Skip to content

Commit

Permalink
fix: oidc linking & unlinking form properties (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas authored Nov 5, 2024
1 parent 6cb5150 commit 2a6999f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/elements-react/src/components/form/form-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function computeDefaultValues(nodes: UiNode[]): FormValues {
// Do not set the default values for this.
return acc
}
if (node.attributes.type === "submit") {
// Submit buttons are not supposed to be part of the form until the user submits it.
return acc
}

acc[node.attributes.name] = node.attributes.value ?? ""
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { getNodeLabel } from "@ory/client-fetch"
import { FlowType, getNodeLabel } from "@ory/client-fetch"
import {
OryNodeInputProps,
uiTextToFormattedMessage,
useOryFlow,
} from "@ory/elements-react"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"
import { cn } from "../../utils/cn"

export const DefaultInput = ({
node,
Expand All @@ -18,6 +20,7 @@ export const DefaultInput = ({
const { register } = useFormContext()
const { value, autocomplete, name, maxlength, ...rest } = attributes
const intl = useIntl()
const { flowType } = useOryFlow()

const formattedLabel = label
? intl.formatMessage(
Expand All @@ -38,7 +41,12 @@ export const DefaultInput = ({
maxLength={maxlength}
autoComplete={autocomplete}
placeholder={formattedLabel}
className="antialiased disabled:text-forms-fg-disabled disabled:bg-forms-bg-disabled bg-forms-bg-default rounded-border-radius-forms border px-3 py-2.5 md:px-4 md:py-4 border-forms-border-default leading-tight hover:border-forms-border-hover transition-colors text-sm"
className={cn(
"antialiased disabled:text-forms-fg-disabled disabled:bg-forms-bg-disabled bg-forms-bg-default rounded-border-radius-forms border border-forms-border-default leading-tight hover:border-forms-border-hover transition-colors text-sm",
"px-3 py-2.5",
// The settings flow input fields are supposed to be dense, so we don't need the extra padding we want on the user flows.
flowType === FlowType.Settings ? "max-w-[488px]" : "md:px-4 md:py-4",
)}
{...register(name, { value })}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { UiNodeInputAttributes } from "@ory/client-fetch"
import { DefaultHorizontalDivider } from "../form/horizontal-divider"
import logos from "../../provider-logos"
import Trash from "../../assets/icons/trash.svg"
import { useFormContext } from "react-hook-form"

export function DefaultSettingsOidc({
linkButtons,
unlinkButtons,
}: OrySettingsOidcProps) {
const hasLinkButtons = linkButtons.length > 0
const hasUnlinkButtons = unlinkButtons.length > 0
const { setValue } = useFormContext()

return (
<div className="flex flex-col gap-8">
Expand All @@ -28,6 +30,10 @@ export function DefaultSettingsOidc({
key={attrs.value}
node={button}
attributes={attrs}
onClick={() => {
setValue("link", attrs.value)
setValue("method", "oidc")
}}
/>
)
})}
Expand All @@ -37,7 +43,7 @@ export function DefaultSettingsOidc({
{unlinkButtons.map((button) => {
const attrs = button.attributes as UiNodeInputAttributes
const provider = extractProvider(button.meta.label?.context) ?? ""
const Logo = logos[attrs.value]
const Logo = attrs.value in logos ? logos[attrs.value] : logos.generic

return (
<div key={attrs.value} className="flex justify-between">
Expand All @@ -47,7 +53,14 @@ export function DefaultSettingsOidc({
{provider}
</p>
</div>
<button {...attrs} type="submit">
<button
{...attrs}
type="submit"
onClick={() => {
setValue("unlink", attrs.value)
setValue("method", "oidc")
}}
>
<Trash className="cursor-pointer text-links-link-mute-default hover:text-links-link-mute-hover" />
</button>
</div>
Expand Down

0 comments on commit 2a6999f

Please sign in to comment.