-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdopplerLegacyClient.ts
66 lines (54 loc) · 1.9 KB
/
dopplerLegacyClient.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import axios from "axios";
import { DopplerLegacyClientImpl } from "./DopplerLegacyClientImpl";
import { DopplerLegacyClientDummy } from "./DopplerLegacyClientDummy";
import { MaxSubscribersData } from "../components/ValidateSubscriber/types";
import { useAppConfiguration } from "../AppConfiguration";
import { useMutation, useQuery } from "@tanstack/react-query";
export const useDopplerLegacyClient = () => {
const appConfiguration = useAppConfiguration();
const dopplerLegacyClient: DopplerLegacyClient = appConfiguration.useDummies
? new DopplerLegacyClientDummy()
: new DopplerLegacyClientImpl(
axios.create({
baseURL: appConfiguration.dopplerLegacyBaseUrl,
withCredentials: true,
}),
);
return dopplerLegacyClient;
};
export const useSendMaxSubscribersData = () => {
const client = useDopplerLegacyClient();
return useMutation(
async (maxSubscribersData: MaxSubscribersData): Promise<boolean> => {
return await client.sendMaxSubscribersData(maxSubscribersData);
},
);
};
export const useGetMaxSubscribers = () => {
const client = useDopplerLegacyClient();
const queryFn = async () => await client.getMaxSubscribersData();
const queryOptions = {
refetchOnWindowFocus: false,
refetchOnReconnect: false,
retry: false,
};
return useQuery<MaxSubscribersData>(
["getMaxSubscribersData"],
queryFn,
queryOptions,
);
};
export const useChangeUserSession = () => {
const client = useDopplerLegacyClient();
return useMutation(async (idUser: number): Promise<boolean> => {
return await client.changeUserSession(idUser);
});
};
export interface DopplerLegacyClient {
getMaxSubscribersData(): Promise<MaxSubscribersData>;
sendMaxSubscribersData(
maxSubscribersData: MaxSubscribersData,
): Promise<boolean>;
sendAcceptButtonAction(): Promise<boolean>;
changeUserSession(idUser: number): Promise<boolean>;
}