Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing resend button on login & registration #294

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions packages/elements-react/src/theme/default/components/form/label.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { FlowType, getNodeLabel } from "@ory/client-fetch"
import { FlowType, getNodeLabel, UiNode } from "@ory/client-fetch"
import {
OryNodeLabelProps,
messageTestId,
uiTextToFormattedMessage,
useComponents,
useOryFlow,
} from "@ory/elements-react"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"

function findResendNode(nodes: UiNode[]) {
return nodes.find(
(n) =>

Check warning on line 17 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L15-L17

Added lines #L15 - L17 were not covered by tests
"name" in n.attributes &&
((n.attributes.name === "email" && n.attributes.type === "submit") ||
n.attributes.name === "resend"),
)
}

export function DefaultLabel({
node,
children,
Expand All @@ -21,15 +31,17 @@
const label = getNodeLabel(node)
const { Message } = useComponents()
const { config, flowType, flow } = useOryFlow()
const { setValue } = useFormContext()

Check warning on line 34 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L34

Added line #L34 was not covered by tests

const isPassword = attributes.type === "password"

const hasResendNode = flow.ui.nodes.some(
(n) =>
"name" in n.attributes &&
n.attributes.name === "email" &&
n.attributes.type === "submit",
)
const resendNode = findResendNode(flow.ui.nodes)

Check warning on line 38 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L38

Added line #L38 was not covered by tests

const handleResend = () => {

Check warning on line 40 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L40

Added line #L40 was not covered by tests
if (resendNode?.attributes && "name" in resendNode.attributes) {
setValue(resendNode.attributes.name, resendNode.attributes.value)

Check warning on line 42 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L42

Added line #L42 was not covered by tests
}
}

return (
<div className="flex flex-col antialiased gap-1">
Expand Down Expand Up @@ -57,11 +69,12 @@
})}
</a>
)}
{hasResendNode && (
{resendNode?.attributes.node_type === "input" && (
<button
type="submit"
name="method"
value="code"
name={resendNode.attributes.name}
value={resendNode.attributes.value}
onClick={handleResend}
className="text-links-link-default hover:underline hover:text-link-hover transition-colors text-sm font-medium cursor-pointer"
>
{intl.formatMessage({ id: "identities.messages.1070008" })}
Expand Down
Loading