-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuseBetaSwitch.ts
More file actions
35 lines (29 loc) · 837 Bytes
/
useBetaSwitch.ts
File metadata and controls
35 lines (29 loc) · 837 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
30
31
32
33
34
35
import { odeServices } from '@edifice.io/client';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useToast } from '../../../..';
type UserPrefs = { homePage: { betaEnabled: boolean } | null };
function deactivateHomepage() {
return odeServices.http().put<UserPrefs>('/userbook/api/preferences', {
homePage: { betaEnabled: false },
});
}
export function useBetaSwitch() {
const { t } = useTranslation();
const toast = useToast();
const [isSwitching, setIsSwitching] = useState(false);
const onSwitchClick = async () => {
setIsSwitching(true);
try {
await deactivateHomepage();
window.location.reload();
} catch {
toast.error(t('betaSwitch.error'));
setIsSwitching(false);
}
};
return {
isSwitching,
onSwitchClick,
};
}