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

49 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 "app/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 "app/auth/mutations/forgot-password";
2021-07-31 14:33:18 +00:00
const ForgotPasswordPage: BlitzPage = () => {
const [forgotPasswordMutation, { isSuccess, reset }] = 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 link",
2021-09-25 13:47:30 +00:00
}}
schema={ForgotPassword}
initialValues={{ email: "" }}
onSubmit={async (values) => {
try {
reset();
2021-09-25 13:47:30 +00:00
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 ? (
<p className="text-center">
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();
ForgotPasswordPage.getLayout = (page) => <BaseLayout title="Reset password">{page}</BaseLayout>;
2021-07-31 14:33:18 +00:00
export default ForgotPasswordPage;