add plate number postal code navgan type and restyle select component
This commit is contained in:
33
src/lib/app/hooks/useCities.jsx
Normal file
33
src/lib/app/hooks/useCities.jsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {useRequest} from "@witel/webapp-builder";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {GET_CITIES_LIST} from "@/core/data/apiRoutes";
|
||||
const useCities = () => {
|
||||
const t = useTranslations();
|
||||
const [provinceID, setProvinceID] = useState(null)
|
||||
const [cityList, setCityList] = useState([]);
|
||||
const [cityTextField, setCityTextField] = useState(t("LoanRequest.city_id"));
|
||||
const requestServer = useRequest({auth: true, notification: false})
|
||||
|
||||
useEffect(()=>{
|
||||
if(provinceID === null) return
|
||||
setCityTextField(t("LoanRequest.text_field_loading_cities_list"))
|
||||
requestServer(`${GET_CITIES_LIST}?province_id=${provinceID}`, "get", {auth: true, notification: false})
|
||||
.then(({data}) => {
|
||||
const result = data.data;
|
||||
const formattedData = result.map((city, index) => ({
|
||||
id: index,
|
||||
name: city.name,
|
||||
value: city.id,
|
||||
}));
|
||||
setCityList(formattedData);
|
||||
setCityTextField(t("LoanRequest.text_field_city_id"))
|
||||
}).catch(() => {
|
||||
setCityTextField(t("LoanRequest.text_field_error_fetching_cities"))
|
||||
});
|
||||
},[provinceID])
|
||||
|
||||
|
||||
return{cityTextField, cityList, setProvinceID}
|
||||
}
|
||||
export default useCities
|
||||
@@ -1,28 +1,33 @@
|
||||
import {GET_PROVINCE_LIST} from "@/core/data/apiRoutes";
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
import useSWR from "swr";
|
||||
import {useRequest} from "@witel/webapp-builder";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
const useProvince = () => {
|
||||
const [isLoadingProvinceList, setIsLoadingProvinceList] = useState(false)
|
||||
const [errorProvinceList, setErrorProvinceList] = useState(false)
|
||||
const [provinceList, setProvinceList] = useState([])
|
||||
const requestServer = useRequest({auth: true, notification: false})
|
||||
|
||||
//swr config
|
||||
const fetcher = (...args) => {
|
||||
return requestServer(args, 'get').then(({data}) => {
|
||||
return data;
|
||||
useEffect(()=> {
|
||||
setIsLoadingProvinceList(true)
|
||||
requestServer(GET_PROVINCE_LIST, 'get',{auth : true, notification : false}).then(({data}) => {
|
||||
const formattedData = data.map((province, index) => ({
|
||||
id: index,
|
||||
name: province.name,
|
||||
value: province.id,
|
||||
}));
|
||||
setIsLoadingProvinceList(false)
|
||||
setProvinceList(formattedData);
|
||||
}).catch(() => {
|
||||
setIsLoadingProvinceList(false)
|
||||
setErrorProvinceList(true)
|
||||
})
|
||||
};
|
||||
|
||||
const {data, isLoading} = useSWR(GET_PROVINCE_LIST, fetcher, {
|
||||
revalidateIfStale: false,
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false
|
||||
});
|
||||
},[])
|
||||
|
||||
return {
|
||||
provinceList: data,
|
||||
isLoadingProvinceList: isLoading,
|
||||
errorProvinceList: !data
|
||||
provinceList,
|
||||
isLoadingProvinceList,
|
||||
errorProvinceList
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user