mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-07-01 04:29:18 +00:00
NORY-47: move identity credentials to client component
This also adds the possibility to delete identity credentials
This commit is contained in:
parent
e83041f8ac
commit
e1ee4bda43
2 changed files with 63 additions and 20 deletions
61
dashboard/src/components/identity/identity-credentials.tsx
Normal file
61
dashboard/src/components/identity/identity-credentials.tsx
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use client';
|
||||
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { ConfirmationDialogWrapper } from '@/components/confirmation-dialog-wrapper';
|
||||
import { deleteIdentityCredential } from '@/app/(inside)/user/action';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Trash } from 'lucide-react';
|
||||
import { DeleteIdentityCredentialsTypeEnum, Identity } from '@ory/client';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
interface IdentityCredentialsProps {
|
||||
identity: Identity;
|
||||
}
|
||||
|
||||
export function IdentityCredentials({ identity }: IdentityCredentialsProps) {
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead>Value</TableHead>
|
||||
<TableHead></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{
|
||||
Object.entries(identity.credentials!).map(([key, value]) => {
|
||||
return (
|
||||
<TableRow key={key}>
|
||||
<TableCell>{key}</TableCell>
|
||||
<TableCell>{value.identifiers![0]}</TableCell>
|
||||
<TableCell>
|
||||
{
|
||||
Object.values(DeleteIdentityCredentialsTypeEnum).includes(key as DeleteIdentityCredentialsTypeEnum) &&
|
||||
key !== 'password' && key !== 'code' &&
|
||||
(
|
||||
<ConfirmationDialogWrapper
|
||||
onSubmit={async () => {
|
||||
deleteIdentityCredential({ id: identity.id, type: key as never })
|
||||
.then(() => toast.success(`Credential ${key} deleted`))
|
||||
.catch(() => toast.error(`Deleting credential ${key} failed`));
|
||||
}}
|
||||
dialogTitle="Delete credential"
|
||||
dialogDescription={`Are you sure you want to remove the credential of type ${key} from this identity?`}
|
||||
dialogButtonSubmit={`Delete ${key}`}
|
||||
dialogButtonSubmitProps={{ variant: 'destructive' }}>
|
||||
<Button size="icon" variant="outline">
|
||||
<Trash className="h-4"/>
|
||||
</Button>
|
||||
</ConfirmationDialogWrapper>
|
||||
)
|
||||
}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue