-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: feature complete settings cards
- Loading branch information
Showing
11 changed files
with
269 additions
and
10 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
88 changes: 88 additions & 0 deletions
88
packages/elements-react/src/components/settings/passkey-settings.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,88 @@ | ||
import { | ||
UiNode, | ||
UiNodeAttributes, | ||
UiNodeInputAttributes, | ||
} from "@ory/client-fetch" | ||
import { useComponents, useOryFlow } from "../../context" | ||
import { useIntl } from "react-intl" | ||
import { triggerToWindowCall, useNodesGroups } from "../../util/ui" | ||
import { Node } from "../form/nodes/node" | ||
|
||
const getTriggerNode = (nodes: UiNode[]): UiNode | undefined => | ||
nodes.find( | ||
(node) => | ||
"name" in node.attributes && | ||
node.attributes.name === "passkey_register_trigger", | ||
) | ||
|
||
const getSettingsNodes = (nodes: UiNode[]): UiNode[] => | ||
nodes.filter( | ||
(node) => | ||
"name" in node.attributes && | ||
(node.attributes.name === "passkey_settings_register" || | ||
node.attributes.name === "passkey_create_data"), | ||
) | ||
|
||
const getRemoveNodes = (nodes: UiNode[]): UiNode[] => | ||
nodes.filter( | ||
(node) => | ||
"name" in node.attributes && node.attributes.name === "passkey_remove", | ||
) | ||
|
||
interface OrySettingsPasskeyProps { | ||
nodes: UiNode[] | ||
} | ||
|
||
export function OrySettingsPasskey({ nodes }: OrySettingsPasskeyProps) { | ||
const Components = useComponents() | ||
const intl = useIntl() | ||
const { flow } = useOryFlow() | ||
const { groups } = useNodesGroups(flow.ui.nodes) | ||
|
||
const triggerButton = getTriggerNode(nodes) | ||
const settingsNodes = getSettingsNodes(nodes) | ||
const removeNodes = getRemoveNodes(nodes) | ||
|
||
if (!triggerButton) { | ||
return null | ||
} | ||
|
||
const { | ||
onclick: _onClick, | ||
onclickTrigger, | ||
...triggerAttributes | ||
} = triggerButton.attributes as UiNodeInputAttributes | ||
|
||
const onTriggerClick = () => { | ||
triggerToWindowCall(onclickTrigger) | ||
} | ||
|
||
return ( | ||
<> | ||
<Components.FormSectionContent | ||
title={intl.formatMessage({ id: "settings.passkey.title" })} | ||
description={intl.formatMessage({ | ||
id: "settings.passkey.description", | ||
})} | ||
> | ||
{groups.default?.map((node, i) => ( | ||
<Node key={`passkey-default-nodes-${i}`} node={node} /> | ||
))} | ||
{settingsNodes.map((node, i) => ( | ||
<Node key={`passkey-settings-nodes-${i}`} node={node} /> | ||
))} | ||
<Components.SettingsPasskey | ||
triggerButton={{ | ||
...triggerButton, | ||
attributes: triggerAttributes as UiNodeAttributes, | ||
onClick: onTriggerClick, | ||
}} | ||
removeButtons={removeNodes} | ||
/> | ||
</Components.FormSectionContent> | ||
<Components.FormSectionFooter> | ||
<span>{intl.formatMessage({ id: "settings.passkey.info" })}</span> | ||
</Components.FormSectionFooter> | ||
</> | ||
) | ||
} |
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
5 changes: 5 additions & 0 deletions
5
packages/elements-react/src/theme/default/assets/icons/key.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
72 changes: 72 additions & 0 deletions
72
packages/elements-react/src/theme/default/components/settings/settings-passkey.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,72 @@ | ||
import { OrySettingsPasskeyProps } from "@ory/elements-react" | ||
import { UiNodeInputAttributes } from "@ory/client-fetch" | ||
import { DefaultButton } from "../form/button" | ||
import { DefaultHorizontalDivider } from "../form/horizontal-divider" | ||
import Passkey from "../../assets/icons/passkey.svg" | ||
import Trash from "../../assets/icons/trash.svg" | ||
|
||
export function DefaultSettingsPasskey({ | ||
triggerButton, | ||
removeButtons, | ||
}: OrySettingsPasskeyProps) { | ||
const hasRemoveButtons = removeButtons.length > 0 | ||
|
||
return ( | ||
<div className="flex flex-col gap-8"> | ||
<div className="flex gap-3 items-end max-w-[60%]"> | ||
{triggerButton ? ( | ||
<DefaultButton | ||
node={triggerButton} | ||
attributes={triggerButton.attributes as UiNodeInputAttributes} | ||
onClick={triggerButton.onClick} | ||
/> | ||
) : null} | ||
</div> | ||
{hasRemoveButtons ? ( | ||
<div className="flex flex-col gap-8"> | ||
<DefaultHorizontalDivider /> | ||
<div className="flex flex-col gap-2"> | ||
{removeButtons.map((node, i) => { | ||
const context = node.meta.label?.context ?? {} | ||
const addedAt = | ||
"added_at" in context ? (context.added_at as string) : null | ||
const diaplyName = | ||
"display_name" in context | ||
? (context.display_name as string) | ||
: null | ||
const keyId = | ||
"value" in node.attributes ? node.attributes.value : null | ||
|
||
return ( | ||
<div | ||
className="flex justify-between gap-6" | ||
key={`webauthn-remove-button-${i}`} | ||
> | ||
<Passkey size={32} className="text-dialog-fg-default" /> | ||
<div className="flex-1 flex-col"> | ||
<p className="text-sm font-medium text-dialog-fg-subtle"> | ||
{diaplyName} | ||
</p> | ||
<span className="text-sm text-dialog-fg-mute">{keyId}</span> | ||
</div> | ||
{addedAt && ( | ||
<p className="text-sm self-center text-dialog-fg-mute"> | ||
{new Date(addedAt).toLocaleDateString()} | ||
</p> | ||
)} | ||
<button | ||
{...(node.attributes as UiNodeInputAttributes)} | ||
type="submit" | ||
className="cursor-pointer text-links-link-mute-default hover:text-links-link-mute-hover" | ||
> | ||
<Trash size={20} /> | ||
</button> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) : null} | ||
</div> | ||
) | ||
} |
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.