Skip to content

Commit

Permalink
auto submit pin
Browse files Browse the repository at this point in the history
  • Loading branch information
eluce2 committed Nov 14, 2024
1 parent c2b4b06 commit c79bc05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ export default function VerifyEmailForm() {
{...form.register("code")}
onChange={(value) => {
form.setValue("code", value);
if (value.length === 8) {
handleSubmitWithAction();
}
}}
error={!!form.formState.errors.code?.message}
autoFocus
/>
{form.formState.errors.code?.message && (
<Text>{form.formState.errors.code.message}</Text>
)}

{action.result.data?.error ? (
<Text c="red">{action.result.data.error}</Text>
) : action.hasErrored ? (
<Text c="red">An error occured</Text>
) : null}

<Button fullWidth type="submit" loading={action.isPending}>
Continue
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useHookFormAction } from "@next-safe-action/adapter-react-hook-form/hoo
import { emailVerificationSchema } from "./schema";
import { verifyEmailAction } from "./actions";
import { zodResolver } from "@hookform/resolvers/zod";
import { Anchor, Button, Group, Paper, PinInput, Text } from "@mantine/core";
import { Button, Paper, PinInput, Text } from "@mantine/core";
import { Stack } from "@mantine/core";

export default function LoginForm() {
Expand All @@ -22,7 +22,12 @@ export default function LoginForm() {
autoFocus
oneTimeCode
{...form.register("code")}
onChange={(value) => form.setValue("code", value)}
onChange={(value) => {
form.setValue("code", value);
if (value.length === 8) {
handleSubmitWithAction();
}
}}
/>

{action.result.data?.error ? (
Expand Down

0 comments on commit c79bc05

Please sign in to comment.