From d7c27cf58265f9f4cd81e9d3d59ba354fd4c771d Mon Sep 17 00:00:00 2001 From: EGOIST Date: Fri, 20 May 2022 17:36:06 +0800 Subject: [PATCH] handle error in login modal --- src/components/common/LoginModal.tsx | 16 ++++++++++++---- src/css/code.css | 4 ++-- src/css/tailwind.css | 2 +- src/router/auth.ts | 2 +- src/router/index.ts | 6 +++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/common/LoginModal.tsx b/src/components/common/LoginModal.tsx index 67ecddcb..aad032d4 100644 --- a/src/components/common/LoginModal.tsx +++ b/src/components/common/LoginModal.tsx @@ -3,13 +3,19 @@ import { useStore } from "~/lib/store" import { Dialog } from "@headlessui/react" import { trpc } from "~/lib/trpc" import { useForm } from "react-hook-form" +import { useEffect } from "react" export const LoginModal: React.FC = () => { const [loginModalOpened, setLoginModalOpened] = useStore((store) => [ store.loginModalOpened, store.setLoginModalOpened, ]) - const requestLoginLink = trpc.useMutation("auth.requestLoginLink") + const { + mutate: requestLoginLink, + status: requestLoginLinkStatus, + data, + error, + } = trpc.useMutation("auth.requestLoginLink") const form = useForm({ defaultValues: { @@ -18,7 +24,7 @@ export const LoginModal: React.FC = () => { }) const handleSubmit = form.handleSubmit((values) => { - requestLoginLink.mutate({ + requestLoginLink({ email: values.email, url: location.href, }) @@ -39,12 +45,13 @@ export const LoginModal: React.FC = () => {
- {requestLoginLink.data && ( + {data && (
We just emailed you with a link to log in, please check your inbox and spam folder in case you can{`'`}t find it.
)} + {error &&
{error.message}
}