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

48 lines 2.71 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 { useVerifyEmailMutation } from '../redux/api/auth-api'; 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'; import { CodeOutlined } from '@ant-design/icons'; var EmailVerificationPage = function () { var form = Form.useForm()[0]; // 👇 API Login Mutation var _a = useVerifyEmailMutation(), verifyEmail = _a[0], _b = _a[1], isLoading = _b.isLoading, isError = _b.isError, error = _b.error, isSuccess = _b.isSuccess, data = _b.data; var navigate = useNavigate(); useEffect(function () { if (isSuccess) { toast.success(data === null || data === void 0 ? void 0 : data.message); navigate('/login'); } 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 verificationCode = _a.verificationCode; // 👇 Executing the verifyEmail Mutation verifyEmail(verificationCode); }; var isSubmittable = useIsFormSubmittable({ form: form }).isSubmittable; return (_jsxs(Container, { children: [_jsx(Typography.Title, { children: "Verify your email" }), _jsxs(Form, __assign({ name: "login", style: { maxWidth: 300 }, onFinish: onSubmitHandler, autoComplete: "off", form: form }, { children: [_jsx(Form.Item, __assign({ name: "verificationCode", messageVariables: { name: 'Token' }, rules: [{ required: true }] }, { children: _jsx(Input, { prefix: _jsx(CodeOutlined, {}), placeholder: "Token" }) })), _jsx(Form.Item, { children: _jsx(SubmitButton, __assign({ type: "primary", htmlType: "submit", disabled: !isSubmittable }, { children: "Login" })) }), "Already have an account?", ' ', _jsx(Typography.Link, { children: _jsx(Link, __assign({ to: "/login" }, { children: "Login" })) })] }))] })); }; export default EmailVerificationPage; //# sourceMappingURL=email-verification.page.js.map