From d8acd6c37c391143db90c3ab997e88617e5cd3dc Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 25 Sep 2021 21:47:30 +0800 Subject: [PATCH] style forgot password form --- app/auth/components/auth-form.tsx | 28 +++++++++-------- app/auth/pages/forgot-password.tsx | 49 ++++++++++++++---------------- app/auth/pages/reset-password.tsx | 16 +++++++++- app/auth/pages/sign-in.tsx | 10 ++---- app/auth/pages/sign-up.tsx | 6 ++-- 5 files changed, 58 insertions(+), 51 deletions(-) diff --git a/app/auth/components/auth-form.tsx b/app/auth/components/auth-form.tsx index 571b5d1..5b0e7c3 100644 --- a/app/auth/components/auth-form.tsx +++ b/app/auth/components/auth-form.tsx @@ -79,19 +79,21 @@ export function AuthForm>({ {children} - + {texts.submit ? ( + + ) : null} diff --git a/app/auth/pages/forgot-password.tsx b/app/auth/pages/forgot-password.tsx index 398793e..59f66b7 100644 --- a/app/auth/pages/forgot-password.tsx +++ b/app/auth/pages/forgot-password.tsx @@ -2,8 +2,8 @@ import type { BlitzPage } from "blitz"; import { Routes, useMutation } from "blitz"; import BaseLayout from "../../core/layouts/base-layout"; -import { LabeledTextField } from "../../core/components/labeled-text-field"; -import { Form, FORM_ERROR } from "../../core/components/form"; +import { AuthForm as Form, FORM_ERROR } from "../components/auth-form"; +import { LabeledTextField } from "../components/labeled-text-field"; import { ForgotPassword } from "../validations"; import forgotPassword from "../../auth/mutations/forgot-password"; @@ -11,33 +11,30 @@ const ForgotPasswordPage: BlitzPage = () => { const [forgotPasswordMutation, { isSuccess }] = useMutation(forgotPassword); return ( -
-

Forgot your password?

- +
{ + try { + await forgotPasswordMutation(values); + } catch (error: any) { + return { + [FORM_ERROR]: "Sorry, we had an unexpected error. Please try again.", + }; + } + }} + > {isSuccess ? ( -
-

Request Submitted

-

If your email is in our system, you will receive instructions to reset your password shortly.

-
+

If your email is in our system, you will receive instructions to reset your password shortly.

) : ( - { - try { - await forgotPasswordMutation(values); - } catch (error: any) { - return { - [FORM_ERROR]: "Sorry, we had an unexpected error. Please try again.", - }; - } - }} - > - - + )} -
+ ); }; diff --git a/app/auth/pages/reset-password.tsx b/app/auth/pages/reset-password.tsx index b2c49dc..d5cb9d6 100644 --- a/app/auth/pages/reset-password.tsx +++ b/app/auth/pages/reset-password.tsx @@ -1,4 +1,4 @@ -import type { BlitzPage } from "blitz"; +import type { BlitzPage, GetServerSideProps } from "blitz"; import { useRouterQuery, Link, useMutation, Routes } from "blitz"; import BaseLayout from "../../core/layouts/base-layout"; @@ -9,6 +9,7 @@ import resetPassword from "../../auth/mutations/reset-password"; const ResetPasswordPage: BlitzPage = () => { const query = useRouterQuery(); + console.log("client query", query); const [resetPasswordMutation, { isSuccess }] = useMutation(resetPassword); return ( @@ -59,4 +60,17 @@ ResetPasswordPage.redirectAuthenticatedTo = Routes.Messages(); ResetPasswordPage.getLayout = (page) => {page}; +export const getServerSideProps: GetServerSideProps = async (context) => { + if (!context.query.token) { + return { + redirect: { + destination: Routes.ForgotPasswordPage().pathname, + permanent: false, + }, + }; + } + + return { props: {} }; +}; + export default ResetPasswordPage; diff --git a/app/auth/pages/sign-in.tsx b/app/auth/pages/sign-in.tsx index ed4abcc..ce36a52 100644 --- a/app/auth/pages/sign-in.tsx +++ b/app/auth/pages/sign-in.tsx @@ -47,14 +47,8 @@ const SignIn: BlitzPage = () => { } }} > - - + + ); }; diff --git a/app/auth/pages/sign-up.tsx b/app/auth/pages/sign-up.tsx index 37d51b6..291f01a 100644 --- a/app/auth/pages/sign-up.tsx +++ b/app/auth/pages/sign-up.tsx @@ -40,9 +40,9 @@ const SignUp: BlitzPage = () => { } }} > - - - + + + ); };