List the action's rejected fields above the register form

This commit is contained in:
Aaron Po
2026-10-13 01:32:59 -04:00
parent e6240bc889
commit fffbe68dc2
2 changed files with 25 additions and 2 deletions

View File

@@ -51,6 +51,12 @@ const Register = ({ actionData }: Route.ComponentProps) => {
submit(data, { method: 'post' });
});
// A request that reached the action without passing client validation, so the
// rejected fields may well sit on a step other than the one on screen.
const rejectedFields = Object.values(actionData?.fieldErrors ?? {}).flatMap(
(messages) => messages ?? [],
);
useActionErrorToast(actionData?.error);
return (
@@ -68,6 +74,13 @@ const Register = ({ actionData }: Route.ComponentProps) => {
{actionData?.error && <AuthErrorAlert message={actionData.error} />}
{rejectedFields.length > 0 && (
<AuthErrorAlert
message="Check these details before creating your account."
details={rejectedFields}
/>
)}
<RegisterForm wizard={wizard} submitting={isSubmitting} />
<AuthSwitchPrompt lead="Already have an account?" to="/login" label="Sign in" />