From d3f82e1eb0d7c858a59dcb76eea57384ff7d6f31 Mon Sep 17 00:00:00 2001 From: Mythie Date: Sat, 17 Jun 2023 11:44:34 +1000 Subject: [PATCH] fix: code style updates and email wording changes --- apps/web/components/reset-password.tsx | 16 +++++++++------- apps/web/pages/api/auth/forgot-password.ts | 2 +- apps/web/pages/api/auth/signup.ts | 4 ++-- .../lib/mail/resetPasswordSuccessTemplate.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/web/components/reset-password.tsx b/apps/web/components/reset-password.tsx index 954a6b0da..9f5f1d466 100644 --- a/apps/web/components/reset-password.tsx +++ b/apps/web/components/reset-password.tsx @@ -5,11 +5,11 @@ import { Button } from "@documenso/ui"; import Logo from "./logo"; import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { zodResolver } from "@hookform/resolvers/zod"; -import { FormProvider, useForm } from "react-hook-form"; +import { useForm } from "react-hook-form"; import { toast } from "react-hot-toast"; import * as z from "zod"; -const schema = z +const ZResetPasswordFormSchema = z .object({ password: z.string().min(8, { message: "Password must be at least 8 characters" }), confirmPassword: z.string().min(8, { message: "Password must be at least 8 characters" }), @@ -19,7 +19,7 @@ const schema = z message: "Password don't match", }); -type ResetPasswordForm = z.infer; +type TResetPasswordFormSchema = z.infer; export default function ResetPassword() { const router = useRouter(); @@ -29,20 +29,20 @@ export default function ResetPassword() { register, formState: { errors, isSubmitting }, handleSubmit, - } = useForm({ - resolver: zodResolver(schema), + } = useForm({ + resolver: zodResolver(ZResetPasswordFormSchema), }); const [resetSuccessful, setResetSuccessful] = useState(false); - const onSubmit = async (values: ResetPasswordForm) => { + const onSubmit = async ({ password }: TResetPasswordFormSchema) => { const response = await toast.promise( fetch(`/api/auth/reset-password`, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ password: values.password, token }), + body: JSON.stringify({ password, token }), }), { loading: "Resetting...", @@ -96,6 +96,7 @@ export default function ResetPassword() { placeholder="New password" /> +
)} +
diff --git a/apps/web/pages/api/auth/forgot-password.ts b/apps/web/pages/api/auth/forgot-password.ts index 9a17edd9f..98e4a6676 100644 --- a/apps/web/pages/api/auth/forgot-password.ts +++ b/apps/web/pages/api/auth/forgot-password.ts @@ -9,7 +9,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { const cleanEmail = email.toLowerCase(); if (!cleanEmail || !/.+@.+/.test(cleanEmail)) { - res.status(422).json({ message: "Invalid email" }); + res.status(400).json({ message: "Invalid email" }); return; } diff --git a/apps/web/pages/api/auth/signup.ts b/apps/web/pages/api/auth/signup.ts index d8032ed95..b67f1b50f 100644 --- a/apps/web/pages/api/auth/signup.ts +++ b/apps/web/pages/api/auth/signup.ts @@ -9,12 +9,12 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { const cleanEmail = email.toLowerCase(); if (!cleanEmail || !/.+@.+/.test(cleanEmail)) { - res.status(422).json({ message: "Invalid email" }); + res.status(400).json({ message: "Invalid email" }); return; } if (!password || password.trim().length < 7) { - return res.status(422).json({ + return res.status(400).json({ message: "Password should be at least 7 characters long.", }); } diff --git a/packages/lib/mail/resetPasswordSuccessTemplate.ts b/packages/lib/mail/resetPasswordSuccessTemplate.ts index 44afcc119..25a0a9ff5 100644 --- a/packages/lib/mail/resetPasswordSuccessTemplate.ts +++ b/packages/lib/mail/resetPasswordSuccessTemplate.ts @@ -20,7 +20,7 @@ export const resetPasswordSuccessTemplate = (user: User) => {

- If you did not ask to change your password we are here to help you secure your account, just contact us. + Didn't request a password change? We are here to help you secure your account, just contact us.