1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/frontend/src/hooks/useLocationSettings.ts
olav 2e367b3a04 feat: add trial expiration warning banner (#985)
* refactor: simplify useApiGetter cache keys

* refactor: simplify basePath helpers

* refactor: add UNLEASH_BASE_PATH frontend env var

* refactor: make sure AnnouncerElement does not affect the layout

* refactor: draw texture image above footer

* refactor: extract domain check helpers

* refactor: fix a few ts-expect-errors

* feat: add trial expiration warning banner

* refactor: fix IInstanceStatus interface prefix

* refactor: use ConditionallyRender in InstanceStatus

* refactor: simplify env helper functions

* refactor: use FC in InstanceStatus

* refactor: warn about expired trials

* refactor: fix eslint warnings

* refactor: disable banner outside of localhost

* refactor: use new instance state field name
2022-05-19 14:06:18 +02:00

30 lines
836 B
TypeScript

import { basePath } from 'utils/formatPath';
import { createPersistentGlobalStateHook } from './usePersistentGlobalState';
import React from 'react';
export interface ILocationSettings {
locale: string;
}
interface IUseLocationSettingsOutput {
locationSettings: ILocationSettings;
setLocationSettings: React.Dispatch<
React.SetStateAction<ILocationSettings>
>;
}
export const useLocationSettings = (): IUseLocationSettingsOutput => {
const [locationSettings, setLocationSettings] = useGlobalState();
return { locationSettings, setLocationSettings };
};
const createInitialValue = (): ILocationSettings => {
return { locale: navigator.language };
};
const useGlobalState = createPersistentGlobalStateHook<ILocationSettings>(
`${basePath}:useLocationSettings:v1`,
createInitialValue()
);