Feature/road safety form
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import { GET_CITY_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useCities = () => {
|
||||
const requestServer = useRequest()
|
||||
const [cities, setCities] = useState([]);
|
||||
const [loadingCities, setLoadingCities] = useState(true);
|
||||
const [errorCities, setErrorCities] = useState(null);
|
||||
@@ -10,7 +12,7 @@ const useCities = () => {
|
||||
useEffect(() => {
|
||||
const fetchCities = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${GET_CITY_LISTS}`);
|
||||
const response = await requestServer(`${GET_CITY_LISTS}`);
|
||||
setCities(response.data.data);
|
||||
setLoadingCities(false);
|
||||
} catch (e) {
|
||||
|
||||
31
src/lib/hooks/usePrevStateopinion.js
Normal file
31
src/lib/hooks/usePrevStateopinion.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import { GET_PREV_STATE_OPINION } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const usePrevStateOpinion = () => {
|
||||
const requestServer = useRequest()
|
||||
const [message, setMessage] = useState([]);
|
||||
const [loadingMessage, setLoadingMessage] = useState(true);
|
||||
const [errorMessage, setErrorMessage] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchCities = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_PREV_STATE_OPINION}`);
|
||||
setMessage(response.data.message);
|
||||
setLoadingMessage(false);
|
||||
} catch (e) {
|
||||
console.error("Error fetching cities:", e);
|
||||
setErrorMessage(e);
|
||||
setLoadingMessage(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchCities();
|
||||
}, []);
|
||||
|
||||
return { message, loadingMessage, errorMessage };
|
||||
};
|
||||
|
||||
export default usePrevStateOpinion;
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import { GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useProvinces = () => {
|
||||
const requestServer = useRequest()
|
||||
const [provinces, setProvinces] = useState([]);
|
||||
const [loadingProvinces, setLoadingProvinces] = useState(true);
|
||||
const [errorProvinces, setErrorProvinces] = useState(null);
|
||||
@@ -10,7 +12,7 @@ const useProvinces = () => {
|
||||
useEffect(() => {
|
||||
const fetchCities = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${GET_PROVINCE_LISTS}`); // Fetch the cities from the API
|
||||
const response = await requestServer(`${GET_PROVINCE_LISTS}`); // Fetch the cities from the API
|
||||
setProvinces(response.data.data); // Set the cities data
|
||||
setLoadingProvinces(false); // Set loading to false after successful fetch
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user