From c349d1ce552b11958a2977ecf30e1625e2a1fe0e Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 22 Jan 2025 14:37:48 +0330 Subject: [PATCH] register --- eslint.config.js | 1 + src/components/DatePicker.tsx | 2 +- src/langs/fa.json | 5 +- src/pages/auth/Register.tsx | 66 ++-------- src/pages/auth/components/RegisterStep1.tsx | 77 +++++++++++ src/pages/auth/components/RegisterStep2.tsx | 139 ++++++++++++++++++++ src/pages/auth/hooks/useAuthData.tsx | 14 +- src/pages/auth/service/AuthService.ts | 13 ++ src/pages/auth/types/AuthTypes.ts | 14 ++ 9 files changed, 275 insertions(+), 56 deletions(-) create mode 100644 src/pages/auth/components/RegisterStep1.tsx create mode 100644 src/pages/auth/components/RegisterStep2.tsx diff --git a/eslint.config.js b/eslint.config.js index 092408a..3e70bcc 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -19,6 +19,7 @@ export default tseslint.config( }, rules: { ...reactHooks.configs.recommended.rules, + 'react-hooks/exhaustive-deps': false, 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx index 6e2f994..15fb903 100644 --- a/src/components/DatePicker.tsx +++ b/src/components/DatePicker.tsx @@ -30,7 +30,7 @@ const DatePickerComponent: FC = (props: Props) => { const formattedDate = `${value.year}/${value.month.number}/${value.day}`; props.onChange(formattedDate); } - }, [props, value]); + }, [value]); useEffect(() => { if (props.defaulValue && !value) { diff --git a/src/langs/fa.json b/src/langs/fa.json index 87f4935..2e7c092 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -30,13 +30,16 @@ "verfify_code_text_2": "ارسال شد.", "change_number": "تغییر شماره", "verify_code": "کد تایید ", + "enter_verify_code": "کد تایید ارسالی را وارد کنید ", "counter_otp": "مانده تا دریافت مجدد کد", "login_with_password": "ورود با رمز عبور", "enter_password_step3": "رمز عبور را وارد کنید", "enter_your_password": "رمز عبور خود را وارد کنید.", "forgot_password": "فراموشی رمز عبور", "login_with_otp": "ورود با رمز عبور یکبار مصرف", - "otp_sent": "کد تایید ارسال شد" + "otp_sent": "کد تایید ارسال شد", + "mobile_number": "شماره موبایل", + "enter_mobile_number": "شماره موبایل خود را وارد کنید" }, "errors": { "required": "این فیلد اجباری می باشد" diff --git a/src/pages/auth/Register.tsx b/src/pages/auth/Register.tsx index afda833..4ddf1c8 100644 --- a/src/pages/auth/Register.tsx +++ b/src/pages/auth/Register.tsx @@ -2,20 +2,23 @@ import { FC } from 'react' import LogoImage from '../../assets/images/logo.svg' import LogoSmallImage from '../../assets/images/logo-small.svg' import { useTranslation } from 'react-i18next' -import Input from '../../components/Input' -import DatePickerComponent from '../../components/DatePicker' -import Button from '../../components/Button' import { Link } from 'react-router-dom' import { Pages } from '../../config/Pages' +import RegisterStep1 from './components/RegisterStep1' +import { useAuthStore } from './store/AuthStore' +import RegisterStep2 from './components/RegisterStep2' + const Register: FC = () => { + const { stepLogin } = useAuthStore() const { t } = useTranslation('global') + return (
-
+
@@ -27,55 +30,12 @@ const Register: FC = () => {

- {/*
- {t('auth.user_info')} -
*/} - -
- - - - -
-
- console.log(date)} placeholder={t('auth.select_date')} /> - - - -
- -
- - -
- -
- -
- -
+ ) +} + +export default RegisterStep1 \ No newline at end of file diff --git a/src/pages/auth/components/RegisterStep2.tsx b/src/pages/auth/components/RegisterStep2.tsx new file mode 100644 index 0000000..483bec2 --- /dev/null +++ b/src/pages/auth/components/RegisterStep2.tsx @@ -0,0 +1,139 @@ +import { FC, Fragment } from 'react' +import { useFormik } from 'formik' +import { RegisterType } from '../types/AuthTypes' +import * as Yup from 'yup' +import { useAuthStore } from '../store/AuthStore' +import { useTranslation } from 'react-i18next' +import Input from '../../../components/Input' +import DatePickerComponent from '../../../components/DatePicker' +import Button from '../../../components/Button' +import { useRegister } from '../hooks/useAuthData' +import { ErrorType } from '../../../helpers/types' +import { toast } from 'react-toastify' +import { Pages } from '../../../config/Pages' + +const RegisterStep2: FC = () => { + + const { t } = useTranslation('global') + const { phone } = useAuthStore() + const register = useRegister() + + const formik = useFormik({ + initialValues: { + firstName: '', + lastName: '', + birthDate: '', + code: 0, + nationalCode: '', + password: '', + phone: phone, + }, + validationSchema: Yup.object({ + firstName: Yup.string() + .required(t('errors.required')), + lastName: Yup.string() + .required(t('errors.required')), + birthDate: Yup.string() + .required(t('errors.required')), + code: Yup.number() + .required(t('errors.required')), + nationalCode: Yup.string() + .required(t('errors.required')), + password: Yup.string() + .required(t('errors.required')), + phone: Yup.string() + .required(t('errors.required')), + }), + onSubmit(values) { + register.mutate(values, { + onSuccess(data) { + localStorage.setItem(import.meta.env.VITE_TOKEN_NAME, data?.data?.accessToken?.token) + localStorage.setItem(import.meta.env.VITE_REFRESH_TOKEN_NAME, data?.data?.refreshToken?.token) + window.location.href = Pages.dashboard + }, + onError(error: ErrorType) { + toast.error(error?.response?.data?.error?.message[0]) + }, + }) + }, + }) + + console.log(formik.errors); + + + return ( + +
+ + + + +
+
+ formik.setFieldValue('birthDate', date)} + placeholder={t('auth.select_date')} + error_text={formik.touched.birthDate && formik.errors.birthDate ? formik.errors.birthDate : ''} + /> + + +
+ +
+ + +
+ +
+ +
+ +