2023-06-23 11:58:51 +00:00
|
|
|
import { devlog, makeRequest } from "@frontend/kitui";
|
2023-06-17 16:01:02 +00:00
|
|
|
import { PrivilegeMap } from "@root/model/privilege";
|
2023-06-06 13:13:58 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
export function useCustomTariffs({ onError, onNewUser, url }: {
|
|
|
|
url: string;
|
2023-06-17 16:01:02 +00:00
|
|
|
onNewUser: (response: PrivilegeMap) => void;
|
2023-06-06 13:13:58 +00:00
|
|
|
onError: (error: any) => void;
|
|
|
|
}) {
|
2023-06-23 11:58:51 +00:00
|
|
|
useEffect(() => {
|
2023-06-06 13:13:58 +00:00
|
|
|
const controller = new AbortController();
|
|
|
|
|
2023-06-23 11:58:51 +00:00
|
|
|
makeRequest<never, PrivilegeMap>({
|
2023-06-06 13:13:58 +00:00
|
|
|
url,
|
|
|
|
signal: controller.signal,
|
2023-06-23 11:58:51 +00:00
|
|
|
method: "get",
|
|
|
|
useToken: true,
|
2023-06-06 13:13:58 +00:00
|
|
|
}).then(result => {
|
2023-06-23 11:58:51 +00:00
|
|
|
onNewUser(result);
|
2023-06-06 13:13:58 +00:00
|
|
|
}).catch(error => {
|
|
|
|
devlog("Error fetching custom tariffs", error);
|
|
|
|
onError(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => controller.abort();
|
|
|
|
}, [onError, onNewUser, url]);
|
|
|
|
}
|