Skip to content

Commit af41bad

Browse files
jonas-jonasory-bot
authored andcommitted
fix: keep buttons disabled if the user is being redirected after a form submission
GitOrigin-RevId: 74965c90343bb8a2919fcbab1d08567768e7c057
1 parent 845a0cd commit af41bad

10 files changed

Lines changed: 394 additions & 182 deletions

File tree

packages/elements-react/api-report/elements-react.api.json

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -639,38 +639,25 @@
639639
{
640640
"kind": "TypeAlias",
641641
"canonicalReference": "@ory/elements-react!FormState:type",
642-
"docComment": "/**\n * Represents the state of the form based on the flow type and active method. This type is used to determine which part of the form should be displayed.\n *\n * It can be one of the following: - `select_method`: The user is selecting an authentication method. - `provide_identifier`: The user is providing an identifier (e.g., email or username). - `method_active`: An authentication method is active, and the user is interacting with it. - `success_screen`: The flow has successfully completed (only used in the verification flow). - `settings`: The user is in the settings flow.\n */\n",
642+
"docComment": "/**\n * Represents the state of the form based on the flow type and active method. This type is used to determine which part of the form should be displayed.\n *\n * It can be one of the following: - `select_method`: The user is selecting an authentication method. - `provide_identifier`: The user is providing an identifier (e.g., email or username). - `method_active`: An authentication method is active, and the user is interacting with it. - `success_screen`: The flow has successfully completed (only used in the verification flow). - `settings`: The user is in the settings flow.\n *\n * In addition, it includes a common properties: - `isSubmitting`: A boolean indicating whether the form is currently being submitted.\n */\n",
643643
"excerptTokens": [
644644
{
645645
"kind": "Content",
646646
"text": "type FormState = "
647647
},
648648
{
649649
"kind": "Reference",
650-
"text": "FormStateSelectMethod",
651-
"canonicalReference": "@ory/elements-react!FormStateSelectMethod:type"
650+
"text": "FlowFormState",
651+
"canonicalReference": "@ory/elements-react!~FlowFormState:type"
652652
},
653653
{
654654
"kind": "Content",
655-
"text": " | "
656-
},
657-
{
658-
"kind": "Reference",
659-
"text": "FormStateProvideIdentifier",
660-
"canonicalReference": "@ory/elements-react!FormStateProvideIdentifier:type"
661-
},
662-
{
663-
"kind": "Content",
664-
"text": " | "
655+
"text": " & "
665656
},
666657
{
667658
"kind": "Reference",
668-
"text": "FormStateMethodActive",
669-
"canonicalReference": "@ory/elements-react!FormStateMethodActive:type"
670-
},
671-
{
672-
"kind": "Content",
673-
"text": " | {\n current: \"success_screen\";\n} | {\n current: \"settings\";\n}"
659+
"text": "CommonFormStateProperties",
660+
"canonicalReference": "@ory/elements-react!~CommonFormStateProperties:type"
674661
},
675662
{
676663
"kind": "Content",
@@ -682,7 +669,7 @@
682669
"name": "FormState",
683670
"typeTokenRange": {
684671
"startIndex": 1,
685-
"endIndex": 7
672+
"endIndex": 4
686673
}
687674
},
688675
{
@@ -714,7 +701,7 @@
714701
},
715702
{
716703
"kind": "Content",
717-
"text": ";\n} | {\n type: \"action_clear_active_method\";\n}"
704+
"text": ";\n} | {\n type: \"action_clear_active_method\";\n} | {\n type: \"form_submit_start\";\n} | {\n type: \"form_submit_end\";\n} | {\n type: \"page_redirect\";\n}"
718705
},
719706
{
720707
"kind": "Content",

packages/elements-react/api-report/elements-react.api.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ export type FlowContextValue = OryFlowContainer & {
7979
dispatchFormState: Dispatch<FormStateAction>;
8080
};
8181

82+
// Warning: (ae-forgotten-export) The symbol "FlowFormState" needs to be exported by the entry point index.d.ts
83+
// Warning: (ae-forgotten-export) The symbol "CommonFormStateProperties" needs to be exported by the entry point index.d.ts
84+
//
8285
// @public
83-
export type FormState = FormStateSelectMethod | FormStateProvideIdentifier | FormStateMethodActive | {
84-
current: "success_screen";
85-
} | {
86-
current: "settings";
87-
};
86+
export type FormState = FlowFormState & CommonFormStateProperties;
8887

8988
// @public
9089
export type FormStateAction = {
@@ -95,6 +94,12 @@ export type FormStateAction = {
9594
method: UiNodeGroupEnum;
9695
} | {
9796
type: "action_clear_active_method";
97+
} | {
98+
type: "form_submit_start";
99+
} | {
100+
type: "form_submit_end";
101+
} | {
102+
type: "page_redirect";
98103
};
99104

100105
// @public
@@ -668,7 +673,7 @@ export type VerificationFlowContainer = {
668673
// dist/index.d.ts:700:5 - (ae-forgotten-export) The symbol "TextRenderer" needs to be exported by the entry point index.d.ts
669674
// dist/index.d.ts:871:5 - (ae-forgotten-export) The symbol "Locale" needs to be exported by the entry point index.d.ts
670675
// dist/index.d.ts:875:5 - (ae-forgotten-export) The symbol "LocaleMap" needs to be exported by the entry point index.d.ts
671-
// dist/index.d.ts:1182:5 - (ae-forgotten-export) The symbol "OrySDK" needs to be exported by the entry point index.d.ts
676+
// dist/index.d.ts:1212:5 - (ae-forgotten-export) The symbol "OrySDK" needs to be exported by the entry point index.d.ts
672677

673678
// (No @packageDocumentation comment for this package)
674679

packages/elements-react/src/components/form/nodes/hooks/useInputProps.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import { MouseEventHandler } from "react"
66
import { useController } from "react-hook-form"
77
import { triggerToWindowCall } from "../../../../util/ui"
88
import { OryNodeInputInputProps } from "../../../../types"
9+
import { useOryFlow } from "../../../../context"
910

1011
export function useInputProps(
1112
attributes: UiNodeInputAttributes,
1213
placeholder?: string,
1314
): OryNodeInputInputProps {
15+
const {
16+
formState: { isSubmitting },
17+
} = useOryFlow()
1418
const controller = useController({
1519
name: attributes.name,
1620
control: undefined,
@@ -30,6 +34,7 @@ export function useInputProps(
3034
maxLength: attributes.maxlength,
3135
autoComplete: attributes.autocomplete,
3236
placeholder: placeholder || "",
33-
disabled: attributes.disabled || !controller.formState.isReady,
37+
disabled:
38+
attributes.disabled || !controller.formState.isReady || isSubmitting,
3439
}
3540
}

packages/elements-react/src/components/form/nodes/renderer/button-renderer.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, useEffect } from "react"
22
import { useFormContext } from "react-hook-form"
33
import { useDebounceValue } from "usehooks-ts"
4-
import { useComponents } from "../../../../context"
4+
import { useComponents, useOryFlow } from "../../../../context"
55
import { OryNodeButtonButtonProps } from "../../../../types"
66
import { triggerToWindowCall } from "../../../../util/ui"
77
import { UiNodeInput } from "../../../../util/utilFixSDKTypesHelper"
@@ -13,6 +13,9 @@ type ButtonRendererProps = {
1313
export function ButtonRenderer({ node }: ButtonRendererProps) {
1414
const { Node } = useComponents()
1515
const { formState, setValue } = useFormContext()
16+
const {
17+
formState: { isSubmitting },
18+
} = useOryFlow()
1619
const [clicked, setClicked] = useDebounceValue(false, 100)
1720

1821
const handleClick = useCallback(() => {
@@ -28,15 +31,14 @@ export function ButtonRenderer({ node }: ButtonRendererProps) {
2831
name: node.attributes.name,
2932
value: node.attributes.value,
3033
onClick: handleClick,
31-
disabled:
32-
node.attributes.disabled || !formState.isReady || formState.isSubmitting,
34+
disabled: node.attributes.disabled || !formState.isReady || isSubmitting,
3335
} satisfies OryNodeButtonButtonProps
3436

3537
useEffect(() => {
36-
if (!formState.isSubmitting) {
38+
if (!isSubmitting) {
3739
setClicked(false)
3840
}
39-
}, [formState.isSubmitting, setClicked])
41+
}, [isSubmitting, setClicked])
4042

4143
return (
4244
<Node.Button

0 commit comments

Comments
 (0)