add education and occupation list hook
This commit is contained in:
34
src/lib/app/hooks/useEducations.jsx
Normal file
34
src/lib/app/hooks/useEducations.jsx
Normal 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;
|
||||
34
src/lib/app/hooks/useOccupations.jsx
Normal file
34
src/lib/app/hooks/useOccupations.jsx
Normal 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;
|
||||
Reference in New Issue
Block a user