1 | import { useState, useEffect } from 'react';
|
2 | import { avRegionsApi } from '@availity/api-axios';
|
3 |
|
4 | export default () => {
|
5 | const [currentRegion, setCurrentRegion] = useState();
|
6 | const [loading, setLoading] = useState(true);
|
7 | const [error, setError] = useState();
|
8 |
|
9 | useEffect(() => {
|
10 | let ignore = false;
|
11 |
|
12 | const fetchCurrentRegion = async () => {
|
13 | setLoading(true);
|
14 | try {
|
15 | const response = await avRegionsApi.getCurrentRegion();
|
16 |
|
17 | if (!ignore) {
|
18 | setCurrentRegion({
|
19 | code: response.data.regions[0].id,
|
20 | value: response.data.regions[0].value,
|
21 | });
|
22 | }
|
23 | } catch (error_) {
|
24 | if (!ignore) setError(error_);
|
25 | }
|
26 |
|
27 | setLoading(false);
|
28 | };
|
29 |
|
30 | fetchCurrentRegion();
|
31 |
|
32 | return () => {
|
33 | ignore = true;
|
34 | };
|
35 | }, []);
|
36 |
|
37 | return [currentRegion, loading, error];
|
38 | };
|