diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/ratelimit-setup.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/ratelimit-setup.tsx index 9c984d4391..78ba5efcb1 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/ratelimit-setup.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/ratelimit-setup.tsx @@ -83,7 +83,7 @@ export const RatelimitSetup = () => { -
+
{fields.map((field, index) => (
diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-create-key.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-create-key.tsx index 3911043161..21973901b9 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-create-key.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-create-key.tsx @@ -11,10 +11,6 @@ export const useCreateKey = ( const trpcUtils = trpc.useUtils(); const key = trpc.key.create.useMutation({ onSuccess(data) { - toast.success("Key Created Successfully", { - description: `Your key ${data.keyId} has been created and is ready to use`, - duration: 5000, - }); trpcUtils.api.keys.list.invalidate(); onSuccess(data); }, diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-fetch-identities/create-identity-options.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-fetch-identities/create-identity-options.tsx index f7cf87cb42..437e0911a6 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-fetch-identities/create-identity-options.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/hooks/use-fetch-identities/create-identity-options.tsx @@ -36,12 +36,14 @@ export function createIdentityOptions({
- - {identity.id} + + {identity.externalId.length > 15 + ? `${identity.externalId.slice(0, 4)}...${identity.externalId.slice(-4)}` + : identity.externalId}
- - {identity.externalId} + + {identity.id}
diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx index 58a0b0c486..54ea58bf4d 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx @@ -151,7 +151,7 @@ export const CreateKeyDialog = ({ void) => { const trpcUtils = trpc.useUtils(); - const deleteKey = trpc.key.delete.useMutation({ - onSuccess() { - toast.success("Key Deleted", { - description: "Your key has been permanently deleted successfully", - duration: 5000, - }); + onSuccess(data, variable) { + const deletedCount = data.totalDeleted; - trpcUtils.api.keys.list.invalidate(); + if (deletedCount === 1) { + toast.success("Key Deleted", { + description: "Your key has been permanently deleted successfully", + duration: 5000, + }); + } else { + toast.success("Keys Deleted", { + description: `${deletedCount} keys have been permanently deleted successfully`, + duration: 5000, + }); + } + // If some keys weren't found. Someone might've already deleted them when this is fired. + if (data.deletedKeyIds.length < variable.keyIds.length) { + const missingCount = variable.keyIds.length - data.deletedKeyIds.length; + toast.warning("Some Keys Not Found", { + description: `${missingCount} ${ + missingCount === 1 ? "key was" : "keys were" + } not found and could not be deleted.`, + duration: 7000, + }); + } + + trpcUtils.api.keys.list.invalidate(); if (onSuccess) { onSuccess(); } }, - onError(err) { + onError(err, variable) { const errorMessage = err.message || ""; + const isPlural = variable.keyIds.length > 1; + const keyText = isPlural ? "keys" : "key"; if (err.data?.code === "NOT_FOUND") { toast.error("Key Deletion Failed", { - description: "Unable to find the key. Please refresh and try again.", + description: `Unable to find the ${keyText}. Please refresh and try again.`, }); } else if (err.data?.code === "INTERNAL_SERVER_ERROR") { toast.error("Server Error", { - description: - "We encountered an issue while deleting your key. Please try again later or contact support at support.unkey.dev", + description: `We encountered an issue while deleting your ${keyText}. Please try again later or contact support at support.unkey.dev`, }); } else if (err.data?.code === "FORBIDDEN") { toast.error("Permission Denied", { - description: "You don't have permission to delete this key.", + description: `You don't have permission to delete ${ + isPlural ? "these keys" : "this key" + }.`, }); } else { - toast.error("Failed to Delete Key", { + toast.error(`Failed to Delete ${isPlural ? "Keys" : "Key"}`, { description: errorMessage || "An unexpected error occurred. Please try again later.", action: { label: "Contact Support", diff --git a/apps/dashboard/components/dialog-container/dialog-container.tsx b/apps/dashboard/components/dialog-container/dialog-container.tsx index 97065dfaa6..13d9c42b21 100644 --- a/apps/dashboard/components/dialog-container/dialog-container.tsx +++ b/apps/dashboard/components/dialog-container/dialog-container.tsx @@ -30,7 +30,7 @@ export const DialogContainer = ({ {