diff --git a/example.env.local b/example.env.local index 9330e24..e3db184 100644 --- a/example.env.local +++ b/example.env.local @@ -1,5 +1,5 @@ NEXT_PUBLIC_API_NAME = "Loan Facilities Dashboard" -NEXT_PUBLIC_API_VERSION = "2.0.0" +NEXT_PUBLIC_API_VERSION = "2.0.3" NEXT_PUBLIC_DEFAULT_LANGUAGE = "fa" NEXT_PUBLIC_DEFAULT_DIRECTION = "rtl" diff --git a/package.json b/package.json index c2321ca..f820385 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@mui/lab": "^5.0.0-alpha.152", "@mui/material": "^5.12.0", "@mui/x-date-pickers": "^6.18.5", - "@witel/webapp-builder": "^1.3.4", + "@witel/webapp-builder": "^1.4.0", "axios": "^1.4.0", "colord": "^2.9.3", "date-fns-jalali": "^2.13.0-0", diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 5486303..e03dc76 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -161,6 +161,9 @@ "national_number_number": "شناسه ملی شرکت می بایست شامل اعداد باشد", "national_code_max": "کد ملی می بایست 10 رقم باشد", "national_serial_number_max": "سریال پشت کارت ملی می بایست 10 رقم باشد", + "boss_national_serial_number_max": "سریال پشت کارت ملی مدیر عامل می بایست 10 رقم باشد", + "national_tracking_code_max": "کد رهگیری کارت ملی می بایست 10 رقم باشد", + "national_boss_tracking_code_max": "کد رهگیری کارت ملی مدیر عامل می بایست 10 رقم باشد", "boss_national_code_max": "کد ملی مدیر عامل می بایست 10 رقم باشد", "national_number_max": "شناسه ملی شرکت می بایست 11 رقم باشد", "shenasname_serial_max": "سریال پشت کارت ملی می بایست شامل 10 بخش باشد", @@ -196,6 +199,7 @@ "error_message_national_number": "لطفا شناسه ملی شرکت خود را وارد کنید!", "error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!", "error_message_shenasname_serial": "لطفا سریال پشت کارت ملی خود را وارد کنید!", + "error_message_boss_shenasname_serial": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", "error_message_boss_national_serial_number": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", "error_message_tracking_code": "لطفا کد رهگیری کارت ملی خود را وارد کنید!", "error_message_boss_national_card_tracking_code": "لطفا کد رهگیری کارت ملی مدیر عامل را وارد کنید!", diff --git a/src/components/dashboard/first/index.jsx b/src/components/dashboard/first/index.jsx index 826380e..7b42ef9 100644 --- a/src/components/dashboard/first/index.jsx +++ b/src/components/dashboard/first/index.jsx @@ -18,7 +18,7 @@ const FirstComponent = () => { {t("Dashboard.go_to_add_request_loan")} - ) -} -export default LegalPersonForm \ No newline at end of file + ); +}; +export default LegalPersonForm; diff --git a/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx index 8c64c5f..b0740af 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx @@ -1,4 +1,13 @@ -import {Box, Button, Checkbox, FormControlLabel, Grid, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material"; +import { + Box, + Button, + Checkbox, + FormControlLabel, + Grid, + TextField, + ToggleButton, + ToggleButtonGroup, +} from "@mui/material"; import SelectBox from "@/core/components/SelectBox"; import MuiDatePicker from "@/core/components/MuiDatePicker"; import {useTranslations} from "next-intl"; @@ -16,22 +25,24 @@ import UseEducations from "@/lib/app/hooks/useEducations"; import useOccupations from "@/lib/app/hooks/useOccupations"; import useActivityType from "@/lib/app/hooks/useActivityType"; import usePriorityLists from "@/lib/app/hooks/usePriorityLists"; +import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; const RealPersonForm = ({setFinishLoanRequest}) => { 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 {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 {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle(); + const requestServer = useRequest(); + const {getUser, changeUser} = useUser(); + const router = useRouter(); const initialValues = { - person_type : "real", - vehicle_type : "", + person_type: "real", + vehicle_type: "", telephone_number: "", activity_type: "", project_title: "", @@ -64,7 +75,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => { telephone_number: Yup.mixed() .test("max", `${t("LoanRequest.tel_number_max")}`, (value) => { const stringValue = String(value); - return stringValue.length === 11 + return stringValue.length === 11; }) .required(t("LoanRequest.error_message_tel_number")), father_name: Yup.string().required(t("LoanRequest.error_message_father_name")), @@ -86,105 +97,134 @@ 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) + 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() + 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_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) + 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) .test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10) .required(t("LoanRequest.error_message_national_id")), - national_number: Yup.mixed().when('person_type', ([person_type], schema) => { - return person_type === 'legal' ? schema - .test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value)) - .test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0) - .test("max", `${t("LoanRequest.national_number_max")}`, (value) => value && value.toString().length === 11) - .required(t("LoanRequest.error_message_national_number")) : schema; - }), - national_serial_number: Yup.string().test("max", `${t("LoanRequest.national_serial_number_max")}`, (value) => value && value.toString().length === 10).when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'national_serial_number' ? schema.required(t("LoanRequest.error_message_shenasname_serial")) : schema - }), - national_card_tracking_code: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'national_card_tracking_code' ? schema.required(t("LoanRequest.error_message_tracking_code")) : schema - }), + national_serial_number: Yup.string() + .when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "national_serial_number" + ? schema.test( + "max", + `${t("LoanRequest.national_serial_number_max")}`, + (value) => value && value.toString().length === 10 + ).required(t("LoanRequest.error_message_shenasname_serial")) + : schema; + }), + national_card_tracking_code: Yup.string().when( + "national_serial_number_or_tracking_code", + ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "national_card_tracking_code" + ? schema.test( + "max", + `${t("LoanRequest.national_tracking_code_max")}`, + (value) => value && value.toString().length === 10 + ).required(t("LoanRequest.error_message_tracking_code")) + : schema; + } + ), }); const handleSubmit = async (values, props) => { - props.setSubmitting(true) - let _national_number = values.person_type === "legal" ? { - shenase_meli: values.national_number - } : {} + props.setSubmitting(true); - const _national_card = values.national_serial_number_or_tracking_code === "national_serial_number" ? { - national_serial_number: values.national_serial_number - } : { - national_tracking_code: values.national_card_tracking_code - } + const _national_card = + values.national_serial_number_or_tracking_code === "national_serial_number" + ? { + national_serial_number: values.national_serial_number, + } + : { + national_tracking_code: values.national_card_tracking_code, + }; let _data = { - is_legal_person: 0, + is_legal_person: 0, telephone_number: values.telephone_number, - national_code: values.national_code, + national_id: values.national_code, vehicle_type: values.vehicle_type, province_id: values.province_id, + city_id: values.city_id, father_name: values.father_name, first_name: values.first_name, last_name: values.last_name, - city_id: values.city_id, navgan_id: values.navgan_id, postal_code: values.postal_code, navgan_type: values.navgan_type, gender: values.gender, address: values.address, - birthday: values.birthday.locale('en').format("YYYY-MM-DD"), ..._national_card, ..._national_number - } + education_id: values.education_id, + occupation_id: values.occupation_id, + activity_type_id: values.activity_type, + project_title: values.project_title, + activity_priority_id: values.priority_list, + plate_part1: values.plate_part1, + plate_part2: values.plate_part2, + plate_part3: values.plate_part3, + plate_part4: values.plate_part4, + birthday: values.birthday.locale("en").format("YYYY-MM-DD"), + ..._national_card, + }; await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", { - auth: true, notification: true, data: _data - }).then(() => { - router.replace('/dashboard/navgan/followUp-loan') - getUser((data) => { - changeUser(data); - }); - }).catch(() => { - }).finally(() => { - props.setSubmitting(false) + auth: true, + notification: true, + data: _data, }) + .then(() => { + router.replace("/dashboard/navgan/followUp-loan"); + getUser((data) => { + changeUser(data); + }); + }) + .catch(() => { + }) + .finally(() => { + props.setSubmitting(false); + }); }; const formik = useFormik({ - initialValues, validationSchema, onSubmit: handleSubmit - }) + initialValues, + validationSchema, + onSubmit: handleSubmit, + }); + 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("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")} + /> + { isLoading={isLoadingActivityType} errorEcured={errorActivityType} selectors={activityType} - schema={{value: 'value', name: 'name'}} + schema={{value: "value", name: "name"}} select={formik.values.activity_type} value={formik.values.activity_type} handleChange={(event) => { - formik.setFieldValue('activity_type', event.target.value) + formik.setFieldValue("activity_type", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} @@ -215,11 +255,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingPriorityLists} errorEcured={errorPriorityLists} selectors={priorityLists} - schema={{value: 'value', name: 'name'}} + schema={{value: "value", name: "name"}} select={formik.values.priority_list} value={formik.values.priority_list} handleChange={(event) => { - formik.setFieldValue('priority_list', event.target.value) + formik.setFieldValue("priority_list", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} @@ -233,16 +273,17 @@ const RealPersonForm = ({setFinishLoanRequest}) => { { - if (value === null) return + if (value === null) return; formik.handleChange({ target: { - name: "national_serial_number_or_tracking_code", value: value, + name: "national_serial_number_or_tracking_code", + value: value, }, - }) + }); }} > @@ -253,9 +294,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { - {formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? ( - + {formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? ( + { fullWidth onChange={formik.handleChange} onBlur={formik.handleBlur("national_serial_number")} - error={formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number)} + error={ + formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number) + } helperText={formik.touched.national_serial_number && formik.errors.national_serial_number} /> - ) : ( + + ) : ( { fullWidth onChange={formik.handleChange} onBlur={formik.handleBlur("national_card_tracking_code")} - error={formik.touched.national_card_tracking_code && Boolean(formik.errors.national_card_tracking_code)} - helperText={formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code} + error={ + formik.touched.national_card_tracking_code && + Boolean(formik.errors.national_card_tracking_code) + } + helperText={ + formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code + } /> )} @@ -295,8 +343,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { variant="outlined" size="small" value={formik.values.national_code} - inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}} - type={'tel'} + inputProps={{inputMode: "numeric", pattern: "[0-9]*"}} + type={"tel"} onChange={(event) => { const inputValue = event.target.value; if (isNaN(Number(inputValue))) { @@ -304,7 +352,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "national_code", value: inputValue, + name: "national_code", + value: inputValue, }, }); }} @@ -375,15 +424,22 @@ const RealPersonForm = ({setFinishLoanRequest}) => { size="small" value={formik.values.gender} selectType="gender" - selectors={[{ - id: 1, value: 1, name: "زن" - }, { - id: 2, value: 0, name: "مرد" - }]} - schema={{value: 'value', name: 'name'}} + selectors={[ + { + id: 1, + value: 1, + name: "زن", + }, + { + id: 2, + value: 0, + name: "مرد", + }, + ]} + schema={{value: "value", name: "name"}} select={formik.values.gender} handleChange={(event) => { - formik.setFieldValue('gender', event.target.value) + formik.setFieldValue("gender", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.gender && Boolean(formik.errors.gender)} @@ -407,8 +463,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { name="postal_code" variant="outlined" value={formik.values.postal_code} - inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}} - type={'tel'} + inputProps={{inputMode: "numeric", pattern: "[0-9]*"}} + type={"tel"} onChange={(event) => { const inputValue = event.target.value; if (isNaN(Number(inputValue))) { @@ -416,7 +472,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "postal_code", value: inputValue, + name: "postal_code", + value: inputValue, }, }); }} @@ -435,8 +492,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { name="telephone_number" variant="outlined" value={formik.values.telephone_number} - inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}} - type={'tel'} + inputProps={{inputMode: "numeric", pattern: "[0-9]*"}} + type={"tel"} size="small" onChange={(event) => { const inputValue = event.target.value; @@ -445,7 +502,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "telephone_number", value: inputValue, + name: "telephone_number", + value: inputValue, }, }); }} @@ -466,17 +524,27 @@ const RealPersonForm = ({setFinishLoanRequest}) => { size="small" value={formik.values.navgan_type} selectType="navgan_type" - selectors={[{ - id: 1, value: "روستایی", name: "روستایی" - }, { - id: 2, value: "عمومی", name: "عمومی" - }, { - id: 3, value: "منطقه آزاد", name: "منطقه آزاد" - }]} - schema={{value: 'value', name: 'name'}} + selectors={[ + { + id: 1, + value: "روستایی", + name: "روستایی", + }, + { + id: 2, + value: "عمومی", + name: "عمومی", + }, + { + id: 3, + value: "منطقه آزاد", + name: "منطقه آزاد", + }, + ]} + schema={{value: "value", name: "name"}} select={formik.values.navgan_type} handleChange={(event) => { - formik.setFieldValue('navgan_type', event.target.value) + formik.setFieldValue("navgan_type", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} @@ -489,8 +557,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { sx={{width: "100%"}} name="navgan_id" variant="outlined" - inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}} - type={'tel'} + inputProps={{inputMode: "numeric", pattern: "[0-9]*"}} + type={"tel"} value={formik.values.navgan_id} onChange={formik.handleChange} size="small" @@ -513,14 +581,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingProvinceList} errorEcured={errorProvinceList} selectors={provinceList} - schema={{value: 'value', name: 'name'}} + schema={{value: "value", name: "name"}} select={formik.values.province_id} value={formik.values.province_id} handleChange={(event) => { - formik.setFieldValue('province_id', event.target.value); - setProvinceID(event.target.value) + formik.setFieldValue("province_id", event.target.value); + setProvinceID(event.target.value); formik.setFieldTouched("city_id", false, false); - formik.setFieldValue("city_id", "") + formik.setFieldValue("city_id", ""); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.province_id && Boolean(formik.errors.province_id)} @@ -531,15 +599,21 @@ const RealPersonForm = ({setFinishLoanRequest}) => { formik.setFieldValue('city_id', event.target.value)} + handleChange={(event) => formik.setFieldValue("city_id", event.target.value)} setFieldTouched={formik.setFieldTouched} error={formik.touched.city_id && Boolean(formik.errors.city_id)} helperText={formik.touched.city_id && formik.errors.city_id} @@ -554,15 +628,22 @@ const RealPersonForm = ({setFinishLoanRequest}) => { label={t("LoanRequest.text_field_vehicle_type")} size="small" value={formik.values.vehicle_type} - schema={{value: 'value', name: 'name'}} + schema={{value: "value", name: "name"}} selectType="vehicle_type" - selectors={[{ - id: 0, value: "اتوبوس", name: "اتوبوس" - }, { - id: 1, value: "مینی بوس", name: "مینی بوس" - }]} + selectors={[ + { + id: 0, + value: "اتوبوس", + name: "اتوبوس", + }, + { + id: 1, + value: "مینی بوس", + name: "مینی بوس", + }, + ]} select={formik.values.vehicle_type} - handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)} + handleChange={(event) => 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")} @@ -584,9 +665,9 @@ const RealPersonForm = ({setFinishLoanRequest}) => { selectors={educationsList} select={formik.values.education_id} value={formik.values.education_id} - schema={{value: 'id', name: 'title'}} + schema={{value: "id", name: "title"}} handleChange={(event) => { - formik.setFieldValue('education_id', event.target.value) + formik.setFieldValue("education_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.education_id && Boolean(formik.errors.education_id)} @@ -602,12 +683,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingOccupationsList} errorEcured={errorOccupationsList} selectType="occupation_id" - schema={{value: 'id', name: 'title'}} + schema={{value: "id", name: "title"}} selectors={occupationsList} select={formik.values.occupation_id} value={formik.values.occupation_id} handleChange={(event) => { - formik.setFieldValue('occupation_id', event.target.value) + formik.setFieldValue("occupation_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)} @@ -639,15 +720,17 @@ const RealPersonForm = ({setFinishLoanRequest}) => { { - formik.setFieldValue("checkedBox", event.target.checked) - }} - />} - label={`${t("LoanRequest.checkbox")}`}/> - + color={"error.main"} + control={ + { + formik.setFieldValue("checkedBox", event.target.checked); + }} + /> + } + label={`${t("LoanRequest.checkbox")}`} + /> { size="large" sx={{my: 4}} endIcon={} - disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true} + disabled={formik.values.checkedBox ? formik.isSubmitting || !formik.dirty || !formik.isValid : true} > - {formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")} - ) -} -export default RealPersonForm \ No newline at end of file + ); +}; +export default RealPersonForm; diff --git a/src/lib/app/hooks/useProjectTitle.jsx b/src/lib/app/hooks/useProjectTitle.jsx index 9b07bbb..31cbb35 100644 --- a/src/lib/app/hooks/useProjectTitle.jsx +++ b/src/lib/app/hooks/useProjectTitle.jsx @@ -1,35 +1,36 @@ -import {GET_PROJECT_TITLE} from "@/core/data/apiRoutes"; -import {useRequest} from "@witel/webapp-builder"; -import {useEffect, useState} from "react"; +import { GET_PROJECT_TITLE } 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}) + 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) - }) - }, []) + setIsLoadingProjectTitle(true); + requestServer(GET_PROJECT_TITLE, "get", { auth: true, notification: false }) + .then(({ data }) => { + const formattedData = data.data.map((projectTitle, index) => ({ + id: index, + name: projectTitle.title, + value: projectTitle.id, + })); + setIsLoadingProjectTitle(false); + setProjectTitle(formattedData); + }) + .catch(() => { + setIsLoadingProjectTitle(false); + setErrorProjectTitle(true); + }); + }, []); return { projectTitle, isLoadingProjectTitle, - errorProjectTitle - } + errorProjectTitle, + }; }; -export default useProjectTitle; \ No newline at end of file +export default useProjectTitle;