education and occupation inputs and their validation

This commit is contained in:
2023-12-19 10:59:06 +03:30
parent 62670863a1
commit cd3560083d
8 changed files with 357 additions and 290 deletions

View File

@@ -8,10 +8,12 @@ const useCities = () => {
const [provinceID, setProvinceID] = useState(null)
const [cityList, setCityList] = useState([]);
const [cityTextField, setCityTextField] = useState(t("text_field_city_id"));
const [isLoadingCityList, setIsLoadingCityList] = useState(false)
const requestServer = useRequest({auth: true, notification: false})
useEffect(() => {
if (provinceID === null) return
setIsLoadingCityList(true)
setCityTextField(t("text_field_loading_cities_list"))
requestServer(`${GET_CITIES_LIST}?province_id=${provinceID}`, "get", {auth: true, notification: false})
.then(({data}) => {
@@ -22,13 +24,15 @@ const useCities = () => {
value: city.id,
}));
setCityList(formattedData);
setIsLoadingCityList(false)
setCityTextField(t("text_field_city_id"))
}).catch(() => {
setIsLoadingCityList(false)
setCityTextField(t("text_field_error_fetching_cities"))
});
}, [provinceID])
return {cityTextField, cityList, setProvinceID}
return {cityTextField, cityList, setProvinceID, isLoadingCityList}
}
export default useCities

View File

@@ -11,13 +11,8 @@ const useEducations = () => {
useEffect(() => {
setIsLoadingEducationsList(true)
requestServer(GET_EDUCATIONS_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
const formattedData = data.map((province, index) => ({
id: index,
name: province.name,
value: province.id,
}));
setIsLoadingEducationsList(false)
setEducationsList(formattedData);
setEducationsList(data.data);
}).catch(() => {
setIsLoadingEducationsList(false)
setErrorEducationsList(true)

View File

@@ -11,13 +11,8 @@ const useOccupations = () => {
useEffect(() => {
setIsLoadingOccupationsList(true)
requestServer(GET_OCCUPATIONS_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
const formattedData = data.map((province, index) => ({
id: index,
name: province.name,
value: province.id,
}));
setIsLoadingOccupationsList(false)
setOccupationsList(formattedData);
setOccupationsList(data.data);
}).catch(() => {
setIsLoadingOccupationsList(false)
setErrorOccupationsList(true)