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

62 lines 3.98 kB
import { __assign } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { toast } from 'react-toastify'; import { useResetPasswordMutation } from '../redux/api/auth-api'; import { CodeOutlined, LockOutlined } from '@ant-design/icons'; import { Container, SubmitButton } from './login.page/login.page.styles'; import { Form, Input, Typography } from 'antd'; import { useIsFormSubmittable } from '../components/ui/form/use-is-form-submittable'; var ResetPasswordPage = function () { var form = Form.useForm()[0]; // 👇 API Login Mutation var _a = useResetPasswordMutation(), resetPassword = _a[0], _b = _a[1], isLoading = _b.isLoading, isError = _b.isError, error = _b.error, isSuccess = _b.isSuccess; var navigate = useNavigate(); useEffect(function () { if (isSuccess) { navigate('/login'); toast.success('Password updated successfully, login', { position: 'top-right' }); form.resetFields(); } 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 (values) { resetPassword(values); }; 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: "resetToken", messageVariables: { name: 'Reset token' }, rules: [{ required: true }] }, { children: _jsx(Input, { prefix: _jsx(CodeOutlined, {}), placeholder: "Reset token" }) })), _jsx(Form.Item, __assign({ name: "password", messageVariables: { name: 'Password' }, rules: [{ required: true, min: 8, max: 32 }] }, { children: _jsx(Input, { prefix: _jsx(LockOutlined, { className: "site-form-item-icon" }), type: "password", placeholder: "Password" }) })), _jsx(Form.Item, __assign({ name: "passwordConfirm", rules: [ { required: true, message: 'Please confirm your password!' }, function (_a) { var getFieldValue = _a.getFieldValue; return ({ validator: function (_, value) { if (!value || getFieldValue('password') === value) { return Promise.resolve(); } return Promise.reject(new Error('The new password that you entered do not match!')); } }); }, ], dependencies: ['password'], hasFeedback: true }, { children: _jsx(Input, { prefix: _jsx(LockOutlined, { className: "site-form-item-icon" }), type: "password", placeholder: "Confirm password" }) })), _jsx(Form.Item, { children: _jsx(SubmitButton, __assign({ type: "primary", htmlType: "submit", disabled: !isSubmittable }, { children: "Reset password" })) }), "Or", ' ', _jsx(Typography.Link, { children: _jsx(Link, __assign({ to: "/login" }, { children: "Back to login" })) })] }))] })); }; export default ResetPasswordPage; //# sourceMappingURL=reset-password.page.js.map