fix: code style updates and email wording changes
This commit is contained in:
@@ -5,11 +5,11 @@ import { Button } from "@documenso/ui";
|
|||||||
import Logo from "./logo";
|
import Logo from "./logo";
|
||||||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
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 { toast } from "react-hot-toast";
|
||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
|
|
||||||
const schema = z
|
const ZResetPasswordFormSchema = z
|
||||||
.object({
|
.object({
|
||||||
password: z.string().min(8, { message: "Password must be at least 8 characters" }),
|
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" }),
|
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",
|
message: "Password don't match",
|
||||||
});
|
});
|
||||||
|
|
||||||
type ResetPasswordForm = z.infer<typeof schema>;
|
type TResetPasswordFormSchema = z.infer<typeof ZResetPasswordFormSchema>;
|
||||||
|
|
||||||
export default function ResetPassword() {
|
export default function ResetPassword() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -29,20 +29,20 @@ export default function ResetPassword() {
|
|||||||
register,
|
register,
|
||||||
formState: { errors, isSubmitting },
|
formState: { errors, isSubmitting },
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
} = useForm<ResetPasswordForm>({
|
} = useForm<TResetPasswordFormSchema>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(ZResetPasswordFormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
const [resetSuccessful, setResetSuccessful] = useState(false);
|
const [resetSuccessful, setResetSuccessful] = useState(false);
|
||||||
|
|
||||||
const onSubmit = async (values: ResetPasswordForm) => {
|
const onSubmit = async ({ password }: TResetPasswordFormSchema) => {
|
||||||
const response = await toast.promise(
|
const response = await toast.promise(
|
||||||
fetch(`/api/auth/reset-password`, {
|
fetch(`/api/auth/reset-password`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ password: values.password, token }),
|
body: JSON.stringify({ password, token }),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
loading: "Resetting...",
|
loading: "Resetting...",
|
||||||
@@ -96,6 +96,7 @@ export default function ResetPassword() {
|
|||||||
placeholder="New password"
|
placeholder="New password"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="confirmPassword" className="sr-only">
|
<label htmlFor="confirmPassword" className="sr-only">
|
||||||
Password
|
Password
|
||||||
@@ -126,6 +127,7 @@ export default function ResetPassword() {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Link href="/login">
|
<Link href="/login">
|
||||||
<div className="relative mt-10 flex items-center justify-center gap-2 text-sm text-gray-500 hover:cursor-pointer hover:text-gray-900">
|
<div className="relative mt-10 flex items-center justify-center gap-2 text-sm text-gray-500 hover:cursor-pointer hover:text-gray-900">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const cleanEmail = email.toLowerCase();
|
const cleanEmail = email.toLowerCase();
|
||||||
|
|
||||||
if (!cleanEmail || !/.+@.+/.test(cleanEmail)) {
|
if (!cleanEmail || !/.+@.+/.test(cleanEmail)) {
|
||||||
res.status(422).json({ message: "Invalid email" });
|
res.status(400).json({ message: "Invalid email" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const cleanEmail = email.toLowerCase();
|
const cleanEmail = email.toLowerCase();
|
||||||
|
|
||||||
if (!cleanEmail || !/.+@.+/.test(cleanEmail)) {
|
if (!cleanEmail || !/.+@.+/.test(cleanEmail)) {
|
||||||
res.status(422).json({ message: "Invalid email" });
|
res.status(400).json({ message: "Invalid email" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!password || password.trim().length < 7) {
|
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.",
|
message: "Password should be at least 7 characters long.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const resetPasswordSuccessTemplate = (user: User) => {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p style="margin-top: 15px">
|
<p style="margin-top: 15px">
|
||||||
If you did not ask to change your password we are here to help you secure your account, just <a href="https://documenso.com">contact us</a>.
|
Didn't request a password change? We are here to help you secure your account, just <a href="https://documenso.com">contact us</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p style="margin-top: 15px">
|
<p style="margin-top: 15px">
|
||||||
|
|||||||
Reference in New Issue
Block a user