-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuseFetchRooms.ts
More file actions
29 lines (24 loc) · 851 Bytes
/
useFetchRooms.ts
File metadata and controls
29 lines (24 loc) · 851 Bytes
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
import { Dropdown } from './../types/dropdown.interface';
import React from 'react';
import { Get } from 'shared/utils/request';
export const getRooms = async (spaceId: string, baseUrl: string) => {
const response = await Get({ path: `/v2/spaces/${spaceId}/rooms`, baseUrl });
return response?.data;
};
export const useFetchRooms = (baseUrl: string) => {
const [isError, setIsError] = React.useState(false);
const [rooms, setRooms] = React.useState<Dropdown[]>([]);
const fetchRooms = React.useCallback(
async (spaceId: string) => {
setIsError(false);
try {
const result = await getRooms(spaceId, baseUrl);
setRooms(result?.map((r: any) => ({ label: r.name, value: r.id })));
} catch (error) {
setIsError(true);
}
},
[baseUrl]
);
return { isError, rooms, fetchRooms };
};