complete new request and hook for limited province and disable update province
This commit is contained in:
@@ -17,7 +17,6 @@ import {useFormik} from "formik";
|
|||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import {CenterLayout, useRequest, useUser} from "@witel/webapp-builder";
|
import {CenterLayout, useRequest, useUser} from "@witel/webapp-builder";
|
||||||
import useProvince from "@/lib/app/hooks/useProvince";
|
|
||||||
import useCities from "@/lib/app/hooks/useCities";
|
import useCities from "@/lib/app/hooks/useCities";
|
||||||
import PlateNumber from "@/core/components/PlateNumber";
|
import PlateNumber from "@/core/components/PlateNumber";
|
||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
@@ -29,6 +28,7 @@ import {NextLinkComposed} from "@witel/webapp-builder/dist/utils/linkRouting";
|
|||||||
import SvgDone from "@/core/components/svgs/SvgDone";
|
import SvgDone from "@/core/components/svgs/SvgDone";
|
||||||
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
|
import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||||
|
|
||||||
const AddFormComponent = () => {
|
const AddFormComponent = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -37,7 +37,7 @@ const AddFormComponent = () => {
|
|||||||
const [finishLoanRequest, setFinishLoanRequest] = useState(false)
|
const [finishLoanRequest, setFinishLoanRequest] = useState(false)
|
||||||
const [checked, setChecked] = useState(false);
|
const [checked, setChecked] = useState(false);
|
||||||
const requestServer = useRequest()
|
const requestServer = useRequest()
|
||||||
const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince()
|
const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince()
|
||||||
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
||||||
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
||||||
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
|||||||
}
|
}
|
||||||
formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD"));
|
formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD"));
|
||||||
formData.append("postal_code", values.postal_code);
|
formData.append("postal_code", values.postal_code);
|
||||||
formData.append("province_id", values.province_id);
|
formData.append("province_id", LoanDetails.province_id);
|
||||||
formData.append("city_id", values.city_id);
|
formData.append("city_id", LoanDetails.city_id);
|
||||||
formData.append("telephone_number", values.telephone_number);
|
formData.append("telephone_number", values.telephone_number);
|
||||||
formData.append("education_id", values.education_id);
|
formData.append("education_id", values.education_id);
|
||||||
formData.append("occupation_id", values.occupation_id);
|
formData.append("occupation_id", values.occupation_id);
|
||||||
@@ -547,7 +547,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
|||||||
name="province_id"
|
name="province_id"
|
||||||
label={t("ShowLoan.text_field_province_id")}
|
label={t("ShowLoan.text_field_province_id")}
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="standard"
|
||||||
|
disabled
|
||||||
selectType="province_id"
|
selectType="province_id"
|
||||||
schema={{value: "value", name: "name"}}
|
schema={{value: "value", name: "name"}}
|
||||||
isLoading={provinceStates.isLoadingProvinceList}
|
isLoading={provinceStates.isLoadingProvinceList}
|
||||||
@@ -568,6 +569,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
|||||||
as={TextField}
|
as={TextField}
|
||||||
sx={{width: "100%"}}
|
sx={{width: "100%"}}
|
||||||
disabled
|
disabled
|
||||||
|
variant="standard"
|
||||||
size="small"
|
size="small"
|
||||||
label={t("ShowLoan.text_field_province_id")}
|
label={t("ShowLoan.text_field_province_id")}
|
||||||
value={t("text_field_loading")}
|
value={t("text_field_loading")}
|
||||||
@@ -588,8 +590,9 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
|||||||
label={citiesStates.cityList.length === 0 ? `${t("ShowLoan.cityList_empty")}` : citiesStates.cityTextField}
|
label={citiesStates.cityList.length === 0 ? `${t("ShowLoan.cityList_empty")}` : citiesStates.cityTextField}
|
||||||
size="small"
|
size="small"
|
||||||
selectType="city_id"
|
selectType="city_id"
|
||||||
disabled={citiesStates.cityList.length === 0}
|
// disabled={citiesStates.cityList.length === 0}
|
||||||
variant="outlined"
|
variant="standard"
|
||||||
|
disabled
|
||||||
selectors={citiesStates.cityList}
|
selectors={citiesStates.cityList}
|
||||||
select={props.values.city_id}
|
select={props.values.city_id}
|
||||||
schema={{value: "value", name: "name"}}
|
schema={{value: "value", name: "name"}}
|
||||||
@@ -602,6 +605,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
|||||||
as={TextField}
|
as={TextField}
|
||||||
sx={{width: "100%"}}
|
sx={{width: "100%"}}
|
||||||
disabled
|
disabled
|
||||||
|
variant="standard"
|
||||||
size="small"
|
size="small"
|
||||||
label={t("ShowLoan.cityList_empty")}
|
label={t("ShowLoan.cityList_empty")}
|
||||||
value={t("text_field_loading")}
|
value={t("text_field_loading")}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const SEND_LOAN_REQUEST_WELFARE = BASE_URL + "/refahi/loan/store";
|
|||||||
export const UPDATE_LOAN_REQUEST_WELFARE = BASE_URL + "/refahi/loan/update/";
|
export const UPDATE_LOAN_REQUEST_WELFARE = BASE_URL + "/refahi/loan/update/";
|
||||||
export const DETAILS_LOAN_REQUEST_WELFARE = BASE_URL + "/refahi/loan/details/";
|
export const DETAILS_LOAN_REQUEST_WELFARE = BASE_URL + "/refahi/loan/details/";
|
||||||
export const GET_PROVINCE_LIST = BASE_URL + "/provinces";
|
export const GET_PROVINCE_LIST = BASE_URL + "/provinces";
|
||||||
|
export const GET_LIMITED_PROVINCE_LIST = BASE_URL + "/provinces/navgan_eligible";
|
||||||
export const GET_CITIES_LIST = BASE_URL + "/cities";
|
export const GET_CITIES_LIST = BASE_URL + "/cities";
|
||||||
export const GET_EDUCATIONS_LIST = BASE_URL + "/education";
|
export const GET_EDUCATIONS_LIST = BASE_URL + "/education";
|
||||||
export const GET_OCCUPATIONS_LIST = BASE_URL + "/occupations";
|
export const GET_OCCUPATIONS_LIST = BASE_URL + "/occupations";
|
||||||
|
|||||||
34
src/lib/app/hooks/useLimitedProvince.jsx
Normal file
34
src/lib/app/hooks/useLimitedProvince.jsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import {GET_LIMITED_PROVINCE_LIST} from "@/core/data/apiRoutes";
|
||||||
|
import {useRequest} from "@witel/webapp-builder";
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
|
const useLimitedProvince = () => {
|
||||||
|
const [isLoadingProvinceList, setIsLoadingProvinceList] = useState(false)
|
||||||
|
const [errorProvinceList, setErrorProvinceList] = useState(false)
|
||||||
|
const [provinceList, setProvinceList] = useState([])
|
||||||
|
const requestServer = useRequest({auth: true, notification: false})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsLoadingProvinceList(true)
|
||||||
|
requestServer(GET_LIMITED_PROVINCE_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
|
||||||
|
const formattedData = data.data.map((province, index) => ({
|
||||||
|
id: index,
|
||||||
|
name: province.name,
|
||||||
|
value: province.id,
|
||||||
|
}));
|
||||||
|
setIsLoadingProvinceList(false)
|
||||||
|
setProvinceList(formattedData);
|
||||||
|
}).catch(() => {
|
||||||
|
setIsLoadingProvinceList(false)
|
||||||
|
setErrorProvinceList(true)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return {
|
||||||
|
provinceList,
|
||||||
|
isLoadingProvinceList,
|
||||||
|
errorProvinceList
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLimitedProvince;
|
||||||
@@ -8,10 +8,10 @@ const useProvince = () => {
|
|||||||
const [provinceList, setProvinceList] = useState([])
|
const [provinceList, setProvinceList] = useState([])
|
||||||
const requestServer = useRequest({auth: true, notification: false})
|
const requestServer = useRequest({auth: true, notification: false})
|
||||||
|
|
||||||
useEffect(()=> {
|
useEffect(() => {
|
||||||
setIsLoadingProvinceList(true)
|
setIsLoadingProvinceList(true)
|
||||||
requestServer(GET_PROVINCE_LIST, 'get',{auth : true, notification : false}).then(({data}) => {
|
requestServer(GET_PROVINCE_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
|
||||||
const formattedData = data.map((province, index) => ({
|
const formattedData = data.data.map((province, index) => ({
|
||||||
id: index,
|
id: index,
|
||||||
name: province.name,
|
name: province.name,
|
||||||
value: province.id,
|
value: province.id,
|
||||||
@@ -22,7 +22,7 @@ const useProvince = () => {
|
|||||||
setIsLoadingProvinceList(false)
|
setIsLoadingProvinceList(false)
|
||||||
setErrorProvinceList(true)
|
setErrorProvinceList(true)
|
||||||
})
|
})
|
||||||
},[])
|
}, [])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
provinceList,
|
provinceList,
|
||||||
|
|||||||
Reference in New Issue
Block a user