shellphone.app/app/auth/pages/forgot-password.tsx

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-01 03:05:40 +00:00
import type { BlitzPage } from "blitz";
import { Routes, useMutation } from "blitz";
2021-07-31 14:33:18 +00:00
import BaseLayout from "../../core/layouts/base-layout";
2021-09-25 13:47:30 +00:00
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";
2021-07-31 14:33:18 +00:00
const ForgotPasswordPage: BlitzPage = () => {
const [forgotPasswordMutation, { isSuccess }] = useMutation(forgotPassword);
2021-07-31 14:33:18 +00:00
return (
2021-09-25 13:47:30 +00:00
<Form
texts={{
title: isSuccess ? "Request submitted" : "Forgot your password?",
subtitle: "",
submit: isSuccess ? "" : "Send reset password instructions",
}}
schema={ForgotPassword}
initialValues={{ email: "" }}
onSubmit={async (values) => {
try {
await forgotPasswordMutation(values);
} catch (error: any) {
return {
[FORM_ERROR]: "Sorry, we had an unexpected error. Please try again.",
};
}
}}
>
2021-07-31 14:33:18 +00:00
{isSuccess ? (
2021-09-25 13:47:30 +00:00
<p>If your email is in our system, you will receive instructions to reset your password shortly.</p>
2021-07-31 14:33:18 +00:00
) : (
2021-09-25 13:47:30 +00:00
<LabeledTextField name="email" label="Email" />
2021-07-31 14:33:18 +00:00
)}
2021-09-25 13:47:30 +00:00
</Form>
);
};
2021-07-31 14:33:18 +00:00
2021-08-01 03:05:40 +00:00
ForgotPasswordPage.redirectAuthenticatedTo = Routes.Messages();
2021-08-01 14:03:49 +00:00
ForgotPasswordPage.getLayout = (page) => <BaseLayout title="Forgot Your Password?">{page}</BaseLayout>;
2021-07-31 14:33:18 +00:00
export default ForgotPasswordPage;