change financial and pixel perfect
This commit is contained in:
@@ -7,45 +7,51 @@ import Button from '../../../components/Button'
|
||||
import { InfoCircle, TickCircle } from 'iconsax-react'
|
||||
import { CreateLegalUserType, ProvinesItemType } from '../types/FinancialTypes'
|
||||
import * as Yup from 'yup'
|
||||
import { useCreateLegalUser, useGetCities, useGetFinancialInfo, useGetProvines } from '../hooks/useFinancialData'
|
||||
import { useCreateLegalUser, useGetCities, useGetLegalInfo, useGetProvines } from '../hooks/useFinancialData'
|
||||
import Select from '../../../components/Select'
|
||||
import PageLoading from '../../../components/PageLoading'
|
||||
import { toast } from 'react-toastify'
|
||||
import { ErrorType } from '../../../helpers/types'
|
||||
import { useGetProfile } from '../../profile/hooks/useProfileData'
|
||||
|
||||
const Legal: FC = () => {
|
||||
|
||||
const { t } = useTranslation('global')
|
||||
const [isReadOnly, setIsReadOnly] = useState<boolean>(false)
|
||||
const [provinesId, setProvinesId] = useState<string>('')
|
||||
const getFinancialInfo = useGetFinancialInfo()
|
||||
const getProvines = useGetProvines()
|
||||
const getLegalInfo = useGetLegalInfo()
|
||||
const getCities = useGetCities(provinesId)
|
||||
const createLegalUser = useCreateLegalUser()
|
||||
const getProfile = useGetProfile()
|
||||
|
||||
const formik = useFormik<CreateLegalUserType>({
|
||||
initialValues: {
|
||||
address: '',
|
||||
cityId: '',
|
||||
companyRegisteredName: '',
|
||||
registrationName: '',
|
||||
economicCode: '',
|
||||
nationalId: '',
|
||||
number: '',
|
||||
nationalIdentity: '',
|
||||
phone: '',
|
||||
postalCode: '',
|
||||
registrationId: ''
|
||||
registrationCode: ''
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
address: Yup.string().required(t('errors.required')),
|
||||
cityId: Yup.string().required(t('errors.required')),
|
||||
companyRegisteredName: Yup.string().required(t('errors.required')),
|
||||
registrationName: Yup.string().required(t('errors.required')),
|
||||
economicCode: Yup.string().required(t('errors.required')),
|
||||
nationalId: Yup.string().required(t('errors.required')),
|
||||
number: Yup.string().required(t('errors.required')),
|
||||
nationalIdentity: Yup.string().required(t('errors.required')),
|
||||
phone: Yup.string().required(t('errors.required')),
|
||||
postalCode: Yup.string().required(t('errors.required')),
|
||||
registrationId: Yup.string().required(t('errors.required'))
|
||||
registrationCode: Yup.string().required(t('errors.required'))
|
||||
}),
|
||||
onSubmit: values => {
|
||||
createLegalUser.mutate(values, {
|
||||
const params = {
|
||||
...values,
|
||||
cityId: +values.cityId
|
||||
}
|
||||
createLegalUser.mutate(params, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('success'))
|
||||
window.location.reload()
|
||||
@@ -57,33 +63,63 @@ const Legal: FC = () => {
|
||||
}
|
||||
})
|
||||
|
||||
// useEffect(() => {
|
||||
|
||||
// if (getFinancialInfo.data?.data?.user?.legalUser || getFinancialInfo.data?.data?.user?.realUser) {
|
||||
// setIsReadOnly(true)
|
||||
// }
|
||||
// if (getFinancialInfo.data?.data?.user?.legalUser) {
|
||||
// const data = getFinancialInfo.data.data?.user
|
||||
// formik.setValues({
|
||||
// address: data?.address.address,
|
||||
// cityId: data?.address?.city?.id,
|
||||
// companyRegisteredName: data?.legalUser.companyRegisteredName,
|
||||
// economicCode: data?.legalUser.economicCode,
|
||||
// nationalId: data?.legalUser.nationalId,
|
||||
// number: data?.legalUser.number,
|
||||
// postalCode: data?.address.postalCode,
|
||||
// registrationId: data?.legalUser.registrationId
|
||||
// })
|
||||
// setProvinesId(data?.address?.city?.province?.id)
|
||||
// }
|
||||
|
||||
// }, [getFinancialInfo.data])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (getFinancialInfo.data?.data?.user?.legalUser || getFinancialInfo.data?.data?.user?.realUser) {
|
||||
if (getLegalInfo.data?.data?.legalUser) {
|
||||
setIsReadOnly(true)
|
||||
}
|
||||
if (getFinancialInfo.data?.data?.user?.legalUser) {
|
||||
const data = getFinancialInfo.data.data?.user
|
||||
if (getLegalInfo.data?.data?.legalUser) {
|
||||
const data = getLegalInfo.data?.data?.legalUser
|
||||
formik.setValues({
|
||||
address: data?.address.address,
|
||||
address: data?.address.fullAddress,
|
||||
cityId: data?.address?.city?.id,
|
||||
companyRegisteredName: data?.legalUser.companyRegisteredName,
|
||||
economicCode: data?.legalUser.economicCode,
|
||||
nationalId: data?.legalUser.nationalId,
|
||||
number: data?.legalUser.number,
|
||||
registrationName: data.registrationName,
|
||||
economicCode: data.economicCode,
|
||||
nationalIdentity: data.nationalIdentity,
|
||||
phone: data.phone,
|
||||
postalCode: data?.address.postalCode,
|
||||
registrationId: data?.legalUser.registrationId
|
||||
registrationCode: data.registrationCode
|
||||
})
|
||||
setProvinesId(data?.address?.city?.province?.id)
|
||||
}
|
||||
|
||||
}, [getFinancialInfo.data])
|
||||
}, [getLegalInfo.data])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (getProfile.data && getProfile.data?.data?.user?.financialType) {
|
||||
setIsReadOnly(true)
|
||||
}
|
||||
|
||||
}, [getProfile.data])
|
||||
|
||||
|
||||
return (
|
||||
<div className='bg-white rounded-3xl xl:p-6 p-4 mt-8 text-sm'>
|
||||
{
|
||||
getProvines.isPending || getFinancialInfo.isPending ?
|
||||
getProvines.isPending || getLegalInfo.isPending ?
|
||||
<PageLoading />
|
||||
:
|
||||
<Fragment>
|
||||
@@ -100,8 +136,8 @@ const Legal: FC = () => {
|
||||
<div className='flex items-end xl:gap-6 gap-3'>
|
||||
<Input
|
||||
label={t('financial.company_name')}
|
||||
{...formik.getFieldProps('companyRegisteredName')}
|
||||
error_text={formik.touched.companyRegisteredName && formik.errors.companyRegisteredName ? formik.errors.companyRegisteredName : ''}
|
||||
{...formik.getFieldProps('registrationName')}
|
||||
error_text={formik.touched.registrationName && formik.errors.registrationName ? formik.errors.registrationName : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
</div>
|
||||
@@ -109,8 +145,8 @@ const Legal: FC = () => {
|
||||
<div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<Input
|
||||
label={t('financial.company_code')}
|
||||
{...formik.getFieldProps('registrationId')}
|
||||
error_text={formik.touched.registrationId && formik.errors.registrationId ? formik.errors.registrationId : ''}
|
||||
{...formik.getFieldProps('registrationCode')}
|
||||
error_text={formik.touched.registrationCode && formik.errors.registrationCode ? formik.errors.registrationCode : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
</div>
|
||||
@@ -118,8 +154,8 @@ const Legal: FC = () => {
|
||||
<div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<Input
|
||||
label={t('financial.national_id')}
|
||||
{...formik.getFieldProps('nationalId')}
|
||||
error_text={formik.touched.nationalId && formik.errors.nationalId ? formik.errors.nationalId : ''}
|
||||
{...formik.getFieldProps('nationalIdentity')}
|
||||
error_text={formik.touched.nationalIdentity && formik.errors.nationalIdentity ? formik.errors.nationalIdentity : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
|
||||
@@ -166,8 +202,8 @@ const Legal: FC = () => {
|
||||
<div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<Input
|
||||
label={t('financial.company_phone')}
|
||||
{...formik.getFieldProps('number')}
|
||||
error_text={formik.touched.number && formik.errors.number ? formik.errors.number : ''}
|
||||
{...formik.getFieldProps('phone')}
|
||||
error_text={formik.touched.phone && formik.errors.phone ? formik.errors.phone : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ import Button from '../../../components/Button'
|
||||
import { InfoCircle, TickCircle } from 'iconsax-react'
|
||||
import { CreateRealUserType, ProvinesItemType } from '../types/FinancialTypes'
|
||||
import * as Yup from 'yup'
|
||||
import { useCreateRealUser, useGetCities, useGetFinancialInfo, useGetProvines } from '../hooks/useFinancialData'
|
||||
import { useCreateRealUser, useGetCities, useGetProvines, useGetRealInfo } from '../hooks/useFinancialData'
|
||||
import { toast } from 'react-toastify'
|
||||
import { ErrorType } from '../../../helpers/types'
|
||||
import DatePickerComponent from '../../../components/DatePicker'
|
||||
import { useGetProfile } from '../../profile/hooks/useProfileData'
|
||||
|
||||
const Personal: FC = () => {
|
||||
|
||||
@@ -18,30 +20,45 @@ const Personal: FC = () => {
|
||||
|
||||
const [isReadOnly, setIsReadOnly] = useState<boolean>(false)
|
||||
const [provinesId, setProvinesId] = useState<string>('')
|
||||
const getFinancialInfo = useGetFinancialInfo()
|
||||
const createRealUser = useCreateRealUser()
|
||||
const getProvines = useGetProvines()
|
||||
const getRealInfo = useGetRealInfo()
|
||||
const getCities = useGetCities(provinesId)
|
||||
const getProfile = useGetProfile()
|
||||
|
||||
const formik = useFormik<CreateRealUserType>({
|
||||
initialValues: {
|
||||
address: '',
|
||||
cityId: '',
|
||||
fatherName: '',
|
||||
birthDate: '',
|
||||
firstName: '',
|
||||
gender: '',
|
||||
lastName: '',
|
||||
nationalCode: '',
|
||||
nationality: '',
|
||||
phone: '',
|
||||
postalCode: ''
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
address: Yup.string().required(t('errors.required')),
|
||||
cityId: Yup.string().required(t('errors.required')),
|
||||
fatherName: Yup.string().required(t('errors.required')),
|
||||
fatherName: Yup.string().required(t('rerrors.equired')),
|
||||
gender: Yup.string().required(t('errors.required')),
|
||||
firstName: Yup.string().required(t('errors.required')),
|
||||
lastName: Yup.string().required(t('rerrors.equired')),
|
||||
nationalCode: Yup.string().required(t('errors.required')),
|
||||
nationality: Yup.string().required(t('errors.required')),
|
||||
postalCode: Yup.string().required(t('errors.required'))
|
||||
phone: Yup.string().required(t('errors.required')),
|
||||
postalCode: Yup.string().required(t('errors.required')),
|
||||
birthDate: Yup.string().required(t('errors.required'))
|
||||
}),
|
||||
onSubmit: values => {
|
||||
createRealUser.mutate(values, {
|
||||
const params = {
|
||||
...values,
|
||||
cityId: +values.cityId
|
||||
}
|
||||
createRealUser.mutate(params, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('success'))
|
||||
window.location.reload()
|
||||
@@ -55,25 +72,35 @@ const Personal: FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
|
||||
if (getFinancialInfo.data?.data?.user?.legalUser || getFinancialInfo.data?.data?.user?.realUser) {
|
||||
setIsReadOnly(true)
|
||||
}
|
||||
if (getFinancialInfo.data?.data?.user?.realUser) {
|
||||
const data = getFinancialInfo.data?.data?.user
|
||||
if (getRealInfo.data?.data?.realUser) {
|
||||
const data = getRealInfo.data?.data?.realUser
|
||||
setIsReadOnly(true)
|
||||
formik.setValues({
|
||||
address: data.address.address,
|
||||
cityId: data.address?.city?.cityId,
|
||||
fatherName: data?.realUser?.fatherName,
|
||||
gender: data?.realUser?.gender,
|
||||
nationality: data?.realUser?.nationality,
|
||||
postalCode: data?.address?.postalCode
|
||||
address: data.address.fullAddress,
|
||||
cityId: data.address?.city?.id,
|
||||
fatherName: data?.fatherName,
|
||||
gender: data?.gender,
|
||||
nationality: data?.nationality,
|
||||
postalCode: data?.address?.postalCode,
|
||||
birthDate: data?.birthDate,
|
||||
firstName: data?.firstName,
|
||||
lastName: data?.lastName,
|
||||
nationalCode: data?.nationalCode,
|
||||
phone: data?.phone
|
||||
})
|
||||
setProvinesId(data?.address?.city?.province?.id)
|
||||
}
|
||||
|
||||
}, [getFinancialInfo.data])
|
||||
}, [getRealInfo.data])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (getProfile.data && getProfile.data?.data?.user?.financialType) {
|
||||
setIsReadOnly(true)
|
||||
}
|
||||
|
||||
}, [getProfile.data])
|
||||
|
||||
|
||||
|
||||
return (
|
||||
@@ -88,31 +115,33 @@ const Personal: FC = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex-1'>
|
||||
{/* <div className='flex items-end xl:gap-6 gap-3'>
|
||||
<div className='flex xl:gap-6 gap-3'>
|
||||
<Input
|
||||
label={t('financial.name')}
|
||||
{...formik.getFieldProps('company_name')}
|
||||
error_text={formik.touched.company_name && formik.errors.company_name ? formik.errors.company_name : ''}
|
||||
{...formik.getFieldProps('firstName')}
|
||||
error_text={formik.touched.firstName && formik.errors.firstName ? formik.errors.firstName : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label={t('financial.family')}
|
||||
{...formik.getFieldProps('company_name')}
|
||||
error_text={formik.touched.company_name && formik.errors.company_name ? formik.errors.company_name : ''}
|
||||
{...formik.getFieldProps('lastName')}
|
||||
error_text={formik.touched.lastName && formik.errors.lastName ? formik.errors.lastName : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
</div> */}
|
||||
<div className='flex items-end xl:gap-6 gap-3'>
|
||||
</div>
|
||||
<div className='flex xl:gap-6 gap-3 mt-8'>
|
||||
<Select
|
||||
label={t('financial.sex')}
|
||||
placeholder={t('select')}
|
||||
items={[
|
||||
{
|
||||
label: t('man'),
|
||||
value: 'male'
|
||||
value: 'MALE'
|
||||
},
|
||||
{
|
||||
label: t('woman'),
|
||||
value: 'female'
|
||||
value: 'FEMALE'
|
||||
},
|
||||
]}
|
||||
{...formik.getFieldProps('gender')}
|
||||
@@ -128,37 +157,51 @@ const Personal: FC = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* <div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<div className='flex xl:gap-6 gap-3 mt-8'>
|
||||
<Input
|
||||
label={t('financial.phone_number')}
|
||||
{...formik.getFieldProps('company_name')}
|
||||
error_text={formik.touched. && formik.errors.company_name ? formik.errors.company_name : ''}
|
||||
{...formik.getFieldProps('phone')}
|
||||
error_text={formik.touched.phone && formik.errors.phone ? formik.errors.phone : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label={t('financial.national_code')}
|
||||
{...formik.getFieldProps('company_name')}
|
||||
error_text={formik.touched.na && formik.errors.company_name ? formik.errors.company_name : ''}
|
||||
/>
|
||||
</div> */}
|
||||
|
||||
<div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
{/* <DatePickerComponent
|
||||
label={t('financial.date_of_birth')}
|
||||
onChange={(value) => formik.setFieldValue('dateOfBirth', value)}
|
||||
placeholder={t('financial.date_of_birth')}
|
||||
error_text={formik.touched. && formik.errors.dateOfBirth ? formik.errors.dateOfBirth : ''}
|
||||
/> */}
|
||||
|
||||
<Input
|
||||
label={t('financial.nationality')}
|
||||
{...formik.getFieldProps('nationality')}
|
||||
error_text={formik.touched.nationality && formik.errors.nationality ? formik.errors.nationality : ''}
|
||||
{...formik.getFieldProps('nationalCode')}
|
||||
error_text={formik.touched.nationalCode && formik.errors.nationalCode ? formik.errors.nationalCode : ''}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* <div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<div className='flex xl:gap-6 gap-3 mt-8'>
|
||||
<DatePickerComponent
|
||||
label={t('financial.date_of_birth')}
|
||||
onChange={(value) => formik.setFieldValue('birthDate', value)}
|
||||
placeholder={t('financial.date_of_birth')}
|
||||
error_text={formik.touched.birthDate && formik.errors.birthDate ? formik.errors.birthDate : ''}
|
||||
readOnly={isReadOnly}
|
||||
defaulValue={formik.values.birthDate}
|
||||
/>
|
||||
|
||||
<Select
|
||||
items={[
|
||||
{
|
||||
label: t('financial.iranian'),
|
||||
value: 'IRANIAN'
|
||||
},
|
||||
{
|
||||
label: t('financial.foreign'),
|
||||
value: 'FOREIGN'
|
||||
},
|
||||
]}
|
||||
{...formik.getFieldProps('nationality')}
|
||||
error_text={formik.touched.nationality && formik.errors.nationality ? formik.errors.nationality : ''}
|
||||
readOnly={isReadOnly}
|
||||
label={t('financial.nationality')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* <div className='flex xl:gap-6 gap-3 mt-8'>
|
||||
<Input
|
||||
label={t('financial.company_phone')}
|
||||
{...formik.getFieldProps('number')}
|
||||
@@ -187,7 +230,7 @@ const Personal: FC = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex-1'>
|
||||
<div className='flex items-end xl:gap-6 gap-3'>
|
||||
<div className='flex xl:gap-6 gap-3'>
|
||||
<Select
|
||||
value={provinesId}
|
||||
label={t('financial.state')}
|
||||
@@ -215,7 +258,7 @@ const Personal: FC = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='flex items-end xl:gap-6 gap-3 mt-8'>
|
||||
<div className='flex xl:gap-6 gap-3 mt-8'>
|
||||
<Textarea
|
||||
{...formik.getFieldProps('address')}
|
||||
error_text={formik.touched.address && formik.errors.address ? formik.errors.address : ''}
|
||||
|
||||
@@ -40,3 +40,17 @@ export const useGetFinancialInfo = () => {
|
||||
queryFn: () => api.getFinancialInfo(),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetLegalInfo = () => {
|
||||
return useQuery({
|
||||
queryKey: ["legal-info"],
|
||||
queryFn: () => api.getLegalInfo(),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetRealInfo = () => {
|
||||
return useQuery({
|
||||
queryKey: ["real-info"],
|
||||
queryFn: () => api.getRealInfo(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,12 +5,12 @@ import {
|
||||
} from "../types/FinancialTypes";
|
||||
|
||||
export const createLegalUser = async (params: CreateLegalUserType) => {
|
||||
const { data } = await axios.post(`/users/legal-user`, params);
|
||||
const { data } = await axios.post(`/users/legal`, params);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const createRealUser = async (params: CreateRealUserType) => {
|
||||
const { data } = await axios.post(`/users/real-user`, params);
|
||||
const { data } = await axios.post(`/users/real`, params);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -28,3 +28,13 @@ export const getFinancialInfo = async () => {
|
||||
const { data } = await axios.get(`/users/me/financial-info`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getLegalInfo = async () => {
|
||||
const { data } = await axios.get(`/users/legal`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getRealInfo = async () => {
|
||||
const { data } = await axios.get(`/users/real`);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
export type CreateRealUserType = {
|
||||
phone: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthDate: string;
|
||||
nationalCode: string;
|
||||
gender: string;
|
||||
fatherName: string;
|
||||
nationality: string;
|
||||
address: string;
|
||||
postalCode: string;
|
||||
cityId: string;
|
||||
cityId: string | number;
|
||||
};
|
||||
|
||||
export type CreateLegalUserType = {
|
||||
economicCode: string;
|
||||
companyRegisteredName: string;
|
||||
registrationId: string;
|
||||
nationalId: string;
|
||||
number: string;
|
||||
postalCode: string;
|
||||
registrationCode: string;
|
||||
registrationName: string;
|
||||
nationalIdentity: string;
|
||||
address: string;
|
||||
cityId: string;
|
||||
postalCode: string;
|
||||
cityId: string | number;
|
||||
phone: string;
|
||||
};
|
||||
|
||||
export type ProvinesItemType = {
|
||||
|
||||
Reference in New Issue
Block a user