add education and occupation list hook

This commit is contained in:
2023-12-18 16:51:18 +03:30
parent c69aa4be89
commit 62670863a1
7 changed files with 202 additions and 63 deletions

View File

@@ -0,0 +1,34 @@
import {GET_EDUCATIONS_LIST} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useEffect, useState} from "react";
const useEducations = () => {
const [isLoadingEducationsList, setIsLoadingEducationsList] = useState(false)
const [errorEducationsList, setErrorEducationsList] = useState(false)
const [educationsList, setEducationsList] = useState([])
const requestServer = useRequest({auth: true, notification: false})
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);
}).catch(() => {
setIsLoadingEducationsList(false)
setErrorEducationsList(true)
})
}, [])
return {
educationsList,
isLoadingEducationsList,
errorEducationsList
}
};
export default useEducations;

View File

@@ -0,0 +1,34 @@
import {GET_OCCUPATIONS_LIST} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useEffect, useState} from "react";
const useOccupations = () => {
const [isLoadingOccupationsList, setIsLoadingOccupationsList] = useState(false)
const [errorOccupationsList, setErrorOccupationsList] = useState(false)
const [occupationsList, setOccupationsList] = useState([])
const requestServer = useRequest({auth: true, notification: false})
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);
}).catch(() => {
setIsLoadingOccupationsList(false)
setErrorOccupationsList(true)
})
}, [])
return {
occupationsList,
isLoadingOccupationsList,
errorOccupationsList
}
};
export default useOccupations;