From 7ebdf782f10b35ac1e04f06cb0095e5c3ac5a846 Mon Sep 17 00:00:00 2001 From: ThatXliner Date: Sat, 23 Nov 2024 23:05:52 -0800 Subject: [PATCH] :sparkles: Implemented back button --- foundation/auth-flow.tsx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/foundation/auth-flow.tsx b/foundation/auth-flow.tsx index 6241620..1fb95af 100644 --- a/foundation/auth-flow.tsx +++ b/foundation/auth-flow.tsx @@ -1,9 +1,9 @@ import { Button, TextInput, Title } from "@mantine/core" import { useForm } from "@mantine/form" import { useMutation } from "@tanstack/react-query" -import { Panel } from "../components/panel" import { useEffect, useRef, useState } from "react" import type { UserProfile } from "../components" +import { Panel } from "../components/panel" export enum AuthState { WAITING_FOR_EMAIL = 0, @@ -15,7 +15,10 @@ export function AuthFlow(props: { state?: AuthState startLogin(email: string): Promise - consumeVerificationCode(email: string, code: string): Promise<{ token: string }> + consumeVerificationCode( + email: string, + code: string, + ): Promise<{ token: string }> verifyToken(token: string): Promise<{ email: string }> onLogin(token: string, profile: UserProfile): void @@ -38,7 +41,8 @@ export function AuthFlow(props: { if (!tokenRef.current) { return } - props.verifyToken(tokenRef.current) + props + .verifyToken(tokenRef.current) .then((res) => props.onLogin(tokenRef.current!, res)) .catch(() => { tokenRef.current = undefined @@ -69,6 +73,9 @@ export function AuthFlow(props: { const res = await consumeVerificationCode(emailRef.current, code) props.onLogin(res.token, res.profile) }} + onBack={() => { + setState(AuthState.WAITING_FOR_EMAIL) + }} /> ) : undefined} @@ -120,7 +127,10 @@ function EmailPrompt(props: { onSubmit: (email: string) => Promise }) { ) } -function CodePrompt(props: { onSubmit: (code: string) => Promise }) { +function CodePrompt(props: { + onSubmit: (code: string) => Promise + onBack: () => void +}) { const form = useForm({ initialValues: { code: "", @@ -156,10 +166,14 @@ function CodePrompt(props: { onSubmit: (code: string) => Promise }) { } }} /> - - +
+ + +
{submitMutation.error ? (