UNPKG

@rtbjs/use-state

Version:

`@rtbjs/use-state` is a state management tool that can act as a local state and be easily turned into a global redux state. It is an innovative approach to state management that combines the advantages of both React's useState and Redux's state management

58 lines 3.07 kB
import { __assign } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect } from 'react'; import { Link } from 'react-router-dom'; import { toast } from 'react-toastify'; import { useForgotPasswordMutation } from '../redux/api/auth-api'; import { useNavigate } from 'react-router-dom'; import { Form, Input, Typography } from 'antd'; import { useIsFormSubmittable } from '../components/ui/form/use-is-form-submittable'; import { Container, SubmitButton } from './login.page/login.page.styles'; import { MailOutlined } from '@ant-design/icons'; var ForgotPasswordPage = function () { var form = Form.useForm()[0]; // 👇 API Login Mutation var _a = useForgotPasswordMutation(), forgotPassword = _a[0], _b = _a[1], isLoading = _b.isLoading, isError = _b.isError, error = _b.error, isSuccess = _b.isSuccess; var navigate = useNavigate(); useEffect(function () { if (isSuccess) { toast.success("We've sent you a token for resetting password."); navigate('/resetpassword'); } if (isError) { if (Array.isArray(error.data.error)) { error.data.error.forEach(function (el) { return toast.error(el.message, { position: 'top-right' }); }); } else { toast.error(error.data.message, { position: 'top-right' }); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoading]); var onSubmitHandler = function (_a) { var email = _a.email; // 👇 Executing the forgotPassword Mutation forgotPassword({ email: email }); }; var isSubmittable = useIsFormSubmittable({ form: form }).isSubmittable; return (_jsxs(Container, { children: [_jsx(Typography.Title, { children: "Reset Password" }), _jsxs(Form, __assign({ name: "login", style: { maxWidth: 300 }, onFinish: onSubmitHandler, autoComplete: "off", form: form }, { children: [_jsx(Form.Item, __assign({ name: "email", messageVariables: { name: 'Email' }, rules: [ { type: 'email', message: 'The input is not valid E-mail!' }, { required: true, message: 'Please input your E-mail!' }, ] }, { children: _jsx(Input, { prefix: _jsx(MailOutlined, {}), placeholder: "Email" }) })), _jsx(Form.Item, { children: _jsx(SubmitButton, __assign({ type: "primary", htmlType: "submit", disabled: !isSubmittable }, { children: "Retrieve password" })) }), "Or", ' ', _jsx(Typography.Link, { children: _jsx(Link, __assign({ to: "/login" }, { children: "Back to login" })) })] }))] })); }; export default ForgotPasswordPage; //# sourceMappingURL=forgot-password.page.js.map