diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 67bbf2e..ebc5008 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -204,6 +204,8 @@ "error_message_checkedBox": "لطفا کد صحت اطلاعات خود را تایید کنید!", "error_message_navgan_type": "لطفا نوع ناوگان خود را وارد کنید!", "error_message_address": "لطفا آدرس خود را وارد کنید!", + "error_message_activity_type": "لطفا نوع فعالیت خود را وارد کنید!", + "error_message_priority_list": "لطفا اولویت فعالیت خود را وارد کنید!", "text_field_tel_number": "شماره ثابت (با پیش شماره استان)", "text_field_company_tel_number": "شماره ثابت شرکت (با پیش شماره استان)", "text_field_education_id": "مدرک تحصیلی", @@ -218,6 +220,8 @@ "text_field_last_name": "نام خانوادگی", "text_field_boss_last_name": "نام خانوادگی مدیر عامل", "text_field_gender": "جنسیت", + "text_field_activity_type": "نوع فعالیت", + "text_field_priority_list": "اولویت فعالیت", "text_field_boss_gender": "جنسیت مدیر عامل", "text_field_register_number": "شماره ثبت شرکت", "text_field_father_name": "نام پدر", diff --git a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx index d45dbe4..1c71b3b 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx @@ -14,6 +14,9 @@ import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes"; import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; import {useFormik} from "formik"; import LegalPersonDatePicker from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker"; +import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; +import useActivityType from "@/lib/app/hooks/useActivityType"; +import usePriorityLists from "@/lib/app/hooks/usePriorityLists"; const LegalPersonForm = ({setFinishLoanRequest}) => { const t = useTranslations(); @@ -24,10 +27,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince() const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations() const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations() + const {activityType, isLoadingActivityType, errorActivityType} = useActivityType() + const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists() const initialValues = { person_type: "legal", company_tel_number: "", + activity_type: "", + priority_list: "", vehicle_type: "", province_id: "", boss_father_name: "", @@ -64,6 +71,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { }) .required(t("LoanRequest.error_message_company_tel_number")), vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")), + activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")), + priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")), register_number: Yup.string().required(t("LoanRequest.error_message_register_number")), boss_father_name: Yup.string().required(t("LoanRequest.error_message_boss_father_name")), company_name: Yup.string().required(t("LoanRequest.error_message_company_name")), @@ -165,6 +174,72 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { }) return ( <> + + {/**/} + {/* {*/} + {/* formik.setFieldValue('project_title', event.target.value)*/} + {/* }}*/} + {/* setFieldTouched={formik.setFieldTouched}*/} + {/* error={formik.touched.project_title && Boolean(formik.errors.project_title)}*/} + {/* helperText={formik.touched.project_title && formik.errors.project_title}*/} + {/* onBlur={formik.handleBlur("project_title")}*/} + {/* />*/} + {/**/} + + + { + formik.setFieldValue('activity_type', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} + helperText={formik.touched.activity_type && formik.errors.activity_type} + onBlur={formik.handleBlur("activity_type")} + /> + + + { + formik.setFieldValue('priority_list', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} + helperText={formik.touched.priority_list && formik.errors.priority_list} + onBlur={formik.handleBlur("priority_list")} + /> + + { const t = useTranslations(); const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince() const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities() + const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations() + const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations() + const {activityType, isLoadingActivityType, errorActivityType} = useActivityType() + const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists() const requestServer = useRequest() const {getUser, changeUser} = useUser() const router = useRouter() const initialValues = { person_type : "real", + vehicle_type : "", telephone_number: "", + activity_type: "", + priority_list: "", father_name: "", gender: "", first_name: "", last_name: "", city_id: "", province_id: "", + education_id: "", + occupation_id: "", navgan_id: "", national_code: "", national_serial_number: "", @@ -37,6 +51,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => { postal_code: "", navgan_type: "", address: "", + plate_part1: "", + plate_part2: "الف", + plate_part3: "", + plate_part4: "", birthday: "", checkedBox: false, }; @@ -49,7 +67,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => { }) .required(t("LoanRequest.error_message_tel_number")), father_name: Yup.string().required(t("LoanRequest.error_message_father_name")), + vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")), + activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")), + priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")), gender: Yup.string().required(t("LoanRequest.error_message_gender")), + occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")), + education_id: Yup.string().required(t("LoanRequest.error_message_education_id")), navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")), address: Yup.string().required(t("LoanRequest.error_message_address")), birthday: Yup.string().required(t("LoanRequest.error_message_date_of_birth")), @@ -61,6 +84,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => { city_id: Yup.string().required(t("LoanRequest.error_message_city_id")), first_name: Yup.string().required(t("LoanRequest.error_message_first_name")), last_name: Yup.string().required(t("LoanRequest.error_message_last_name")), + plate_part1: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) + .required(t("LoanRequest.error_message_plate_number")), + plate_part2: Yup.mixed() + .required(t("LoanRequest.error_message_plate_number")), + plate_part3: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3) + .required(t("LoanRequest.error_message_plate_number")), + plate_part4: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) + .required(t("LoanRequest.error_message_plate_number")), national_code: Yup.mixed() .test("is-number", `${t("LoanRequest.national_code_number")}`, (value) => !isNaN(value)) .test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0) @@ -130,6 +161,72 @@ const RealPersonForm = ({setFinishLoanRequest}) => { return ( <> + + {/**/} + {/* {*/} + {/* formik.setFieldValue('project_title', event.target.value)*/} + {/* }}*/} + {/* setFieldTouched={formik.setFieldTouched}*/} + {/* error={formik.touched.project_title && Boolean(formik.errors.project_title)}*/} + {/* helperText={formik.touched.project_title && formik.errors.project_title}*/} + {/* onBlur={formik.handleBlur("project_title")}*/} + {/* />*/} + {/**/} + + + { + formik.setFieldValue('activity_type', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} + helperText={formik.touched.activity_type && formik.errors.activity_type} + onBlur={formik.handleBlur("activity_type")} + /> + + + { + formik.setFieldValue('priority_list', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} + helperText={formik.touched.priority_list && formik.errors.priority_list} + onBlur={formik.handleBlur("priority_list")} + /> + + { /> + + + formik.setFieldValue('vehicle_type', event.target.value)} + error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)} + helperText={formik.touched.vehicle_type && formik.errors.vehicle_type} + onBlur={formik.handleBlur("vehicle_type")} + /> + + + + + + + + { + formik.setFieldValue('education_id', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.education_id && Boolean(formik.errors.education_id)} + helperText={formik.touched.education_id && formik.errors.education_id} + onBlur={formik.handleBlur("education_id")} + /> + + + { + formik.setFieldValue('occupation_id', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)} + helperText={formik.touched.occupation_id && formik.errors.occupation_id} + onBlur={formik.handleBlur("occupation_id")} + /> + + { disabled={disabled} fullWidth > - {plate_words.find(p => p.value === formik.values.plate_part2).name} + {plate_words.find(p => p.value === formik.values.plate_part2)?.name} { + const [isLoadingActivityType, setIsLoadingActivityType] = useState(false) + const [errorActivityType, setErrorActivityType] = useState(false) + const [activityType, setActivityType] = useState([]) + const requestServer = useRequest({auth: true, notification: false}) + + useEffect(() => { + setIsLoadingActivityType(true) + requestServer(GET_ACTIVITY_LIST, 'get', {auth: true, notification: false}).then(({data}) => { + const formattedData = data.data.map((activityList, index) => ({ + id: index, + name: activityList.name, + value: activityList.id, + })); + setIsLoadingActivityType(false) + setActivityType(formattedData); + }).catch(() => { + setIsLoadingActivityType(false) + setErrorActivityType(true) + }) + }, []) + + return { + activityType, + isLoadingActivityType, + errorActivityType + } +}; + +export default useActivityType; \ No newline at end of file diff --git a/src/lib/app/hooks/usePriorityLists.jsx b/src/lib/app/hooks/usePriorityLists.jsx new file mode 100644 index 0000000..75a294e --- /dev/null +++ b/src/lib/app/hooks/usePriorityLists.jsx @@ -0,0 +1,34 @@ +import {GET_PRIORITY_LIST} from "@/core/data/apiRoutes"; +import {useRequest} from "@witel/webapp-builder"; +import {useEffect, useState} from "react"; + +const usePriorityLists = () => { + const [isLoadingPriorityLists, setIsLoadingPriorityLists] = useState(false) + const [errorPriorityLists, setErrorPriorityLists] = useState(false) + const [priorityLists, setPriorityLists] = useState([]) + const requestServer = useRequest({auth: true, notification: false}) + + useEffect(() => { + setIsLoadingPriorityLists(true) + requestServer(GET_PRIORITY_LIST, 'get', {auth: true, notification: false}).then(({data}) => { + const formattedData = data.data.map((priorityList, index) => ({ + id: index, + name: priorityList.name, + value: priorityList.id, + })); + setIsLoadingPriorityLists(false) + setPriorityLists(formattedData); + }).catch(() => { + setIsLoadingPriorityLists(false) + setErrorPriorityLists(true) + }) + }, []) + + return { + priorityLists, + isLoadingPriorityLists, + errorPriorityLists + } +}; + +export default usePriorityLists; \ No newline at end of file diff --git a/src/lib/app/hooks/useProjectTitle.jsx b/src/lib/app/hooks/useProjectTitle.jsx new file mode 100644 index 0000000..797b5c1 --- /dev/null +++ b/src/lib/app/hooks/useProjectTitle.jsx @@ -0,0 +1,35 @@ +import {GET_PROJECT_TITLE, GET_PROVINCE_LIST} from "@/core/data/apiRoutes"; +import {useRequest} from "@witel/webapp-builder"; +import {useEffect, useState} from "react"; + +const useProjectTitle = () => { + const [isLoadingProjectTitle, setIsLoadingProjectTitle] = useState(false) + const [errorProjectTitle, setErrorProjectTitle] = useState(false) + const [projectTitle, setProjectTitle] = useState([]) + const requestServer = useRequest({auth: true, notification: false}) + + useEffect(() => { + setIsLoadingProjectTitle(true) + requestServer(GET_PROJECT_TITLE, 'get', {auth: true, notification: false}).then(({data}) => { + console.log(data) + // const formattedData = data.data.map((projectTitle, index) => ({ + // id: index, + // name: projectTitle.name, + // value: projectTitle.id, + // })); + setIsLoadingProjectTitle(false) + // setProjectTitle(formattedData); + }).catch(() => { + setIsLoadingProjectTitle(false) + setErrorProjectTitle(true) + }) + }, []) + + return { + projectTitle, + isLoadingProjectTitle, + errorProjectTitle + } +}; + +export default useProjectTitle; \ No newline at end of file