-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Passkey list for react package (#89)
* Added passkey list and delete support * added dialog in react package * fixed build issues * fixed UI issues * added support for custom themes * fixed vercel build issue * added support for translations * updated components structure * fixed pr reviews * fixed local build issue * updated translations
- Loading branch information
Showing
53 changed files
with
902 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
export * from './Button'; | ||
export * from './HorizontalRule'; | ||
export * from './icons'; | ||
export * from './Input'; | ||
export * from './FormInput'; | ||
export * from './IconLink'; | ||
export * from './OtpInputGroup'; | ||
export * from './PasskeyScreensWrapper'; | ||
export * from './Spinner'; | ||
export * from './Header'; | ||
export * from './SubHeader'; | ||
export * from './Body'; | ||
export * from './AuthFormScreenWrapper'; | ||
export * from './EmailOtpScreenWrapper'; | ||
export * from './ui'; | ||
export * from './wrappers'; |
35 changes: 35 additions & 0 deletions
35
packages/react/src/components/passkeyList/PasskeyAgentIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { aaguidMappings, hasDarkMode } from '@corbado/shared-ui'; | ||
import React from 'react'; | ||
|
||
const DefaultIcon = ( | ||
<svg | ||
xmlns='http://www.w3.org/2000/svg' | ||
viewBox='0 -960 960 960' | ||
> | ||
<path d='M120-160v-112q0-34 17.5-62.5T184-378q62-31 126-46.5T440-440q20 0 40 1.5t40 4.5q-4 58 21 109.5t73 84.5v80H120ZM760-40l-60-60v-186q-44-13-72-49.5T600-420q0-58 41-99t99-41q58 0 99 41t41 99q0 45-25.5 80T790-290l50 50-60 60 60 60-80 80ZM440-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47Zm300 80q17 0 28.5-11.5T780-440q0-17-11.5-28.5T740-480q-17 0-28.5 11.5T700-440q0 17 11.5 28.5T740-400Z' /> | ||
</svg> | ||
); | ||
|
||
export interface PasskeyAgentIconProps { | ||
aaguid: string; | ||
} | ||
|
||
const PasskeyAgentIcon = ({ aaguid }: PasskeyAgentIconProps) => { | ||
const iconData = aaguidMappings[aaguid]; | ||
const iconSrc = hasDarkMode() ? iconData?.iconDark ?? iconData?.icon : iconData?.icon; | ||
|
||
return ( | ||
<div className='cb-passkey-list-icon'> | ||
{iconSrc ? ( | ||
<img | ||
src={iconSrc} | ||
alt={iconData?.name ?? 'Passkey'} | ||
/> | ||
) : ( | ||
<>{DefaultIcon}</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PasskeyAgentIcon; |
53 changes: 53 additions & 0 deletions
53
packages/react/src/components/passkeyList/PasskeyDelete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { FC } from 'react'; | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Dialog } from '..'; | ||
|
||
export interface PasskeyDeleteProps { | ||
passkeyId: string; | ||
onPasskeyDelete: (id: string) => Promise<void>; | ||
} | ||
|
||
const PasskeyDelete: FC<PasskeyDeleteProps> = ({ passkeyId, onPasskeyDelete }) => { | ||
const { t } = useTranslation('translation', { keyPrefix: 'passkeysList' }); | ||
const [isDialogOpen, setDialogOpen] = useState(false); | ||
|
||
const openDialog = () => { | ||
setDialogOpen(true); | ||
}; | ||
|
||
const closeDialog = () => { | ||
setDialogOpen(false); | ||
}; | ||
|
||
const confirmDelete = () => { | ||
closeDialog(); | ||
void onPasskeyDelete(passkeyId); | ||
}; | ||
|
||
return ( | ||
<div className='cb-passkey-list-icon'> | ||
<svg | ||
xmlns='http://www.w3.org/2000/svg' | ||
viewBox='0 0 24 24' | ||
className='cb-passkey-list-delete' | ||
onClick={openDialog} | ||
> | ||
<path d='M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z' /> | ||
</svg> | ||
<Dialog | ||
inverseButtonVariants | ||
isOpen={isDialogOpen} | ||
header={t('deleteDialog_header')} | ||
body={t('deleteDialog_body')} | ||
confirmText={t('deleteDialog_deleteButton')} | ||
cancelText={t('deleteDialog_cancelButton')} | ||
onClose={closeDialog} | ||
onConfirm={confirmDelete} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PasskeyDelete; |
49 changes: 49 additions & 0 deletions
49
packages/react/src/components/passkeyList/PasskeyDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { aaguidMappings, getParsedUA } from '@corbado/shared-ui'; | ||
import type { PassKeyItem } from '@corbado/types'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
|
||
export interface PasskeyDetailsProps { | ||
passkey: PassKeyItem; | ||
} | ||
|
||
const PasskeyDetails: FC<PasskeyDetailsProps> = ({ passkey }) => { | ||
const { t } = useTranslation('translation', { keyPrefix: 'passkeysList' }); | ||
const userAgent = getParsedUA(passkey.userAgent); | ||
const title = aaguidMappings[passkey.aaguid]?.name ?? 'Passkey'; | ||
|
||
return ( | ||
<div className='cb-passkey-list-details'> | ||
<div className='cb-passkey-list-header'> | ||
<div className='cb-passkey-list-header-title'>{title}</div> | ||
{passkey.backupState ? <div className='cb-passkey-list-header-badge'>{t('badge_synced')}</div> : null} | ||
</div> | ||
<div> | ||
{t('field_credentialId')} | ||
{passkey.id} | ||
</div> | ||
<div> | ||
<Trans | ||
i18nKey='field_created' | ||
t={t} | ||
values={{ | ||
date: passkey.created, | ||
browser: userAgent.browser.name, | ||
os: userAgent.os.name, | ||
}} | ||
/> | ||
</div> | ||
<div> | ||
{t('field_lastUsed')} | ||
{passkey.lastUsed} | ||
</div> | ||
<div> | ||
{t('field_status')} | ||
{passkey.status} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PasskeyDetails; |
2 changes: 1 addition & 1 deletion
2
packages/react/src/components/Body.tsx → packages/react/src/components/ui/Body.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.