generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetchCarouselLayout.ts
More file actions
47 lines (38 loc) · 1.16 KB
/
fetchCarouselLayout.ts
File metadata and controls
47 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useQuery } from '@tanstack/react-query';
import {
ApiClient,
isSuccessResponse,
Endpoints,
} from '@AppServices/apiClient';
import type { CarouselLayoutDto } from './dtos/CarouselLayoutDto';
import { parseCarouselLayoutDtoArray } from './dtos/CarouselLayoutDto';
import staticData from './staticData/carouselLayout.json';
type ResponseDto = CarouselLayoutDto[];
const endpoint = Endpoints.CarouselLayout;
export const fetchCarouselLayoutApiCall = async () => {
const response = await ApiClient.get<ResponseDto>(
endpoint,
{ staticData },
{ isAuthorized: true },
);
if (!isSuccessResponse(response)) {
switch (response.status) {
case 400:
throw new Error(
`fetchCarouselLayoutApiCall(): resources does not exists for endpoint '${endpoint}'`,
);
default:
throw new Error(
`fetchCarouselLayoutApiCall(): failed to fetch data from endpoint '${endpoint}'`,
);
}
}
return parseCarouselLayoutDtoArray(response.data);
};
export const useCarouselLayout = () => {
const query = useQuery({
queryKey: [endpoint],
queryFn: fetchCarouselLayoutApiCall,
});
return query;
};