Refactor client config (#529)

* Refactor client config

* Fix server tests

* Fix lint
This commit is contained in:
Charles Bochet
2023-07-07 11:10:42 -07:00
committed by GitHub
parent 11d18cc269
commit 26b033abc9
38 changed files with 386 additions and 180 deletions

View File

@ -1,9 +1,9 @@
import { useCallback } from 'react';
import { useRecoilState } from 'recoil';
import { telemetryState } from '@/client-config/states/telemetryState';
import { useCreateEventMutation } from '~/generated/graphql';
import { useIsTelemetryEnabled } from './useIsTelemetryEnabled';
interface EventLocation {
pathname: string;
}
@ -13,12 +13,12 @@ export interface EventData {
}
export function useEventTracker() {
const telemetryEnabled = useIsTelemetryEnabled();
const [telemetry] = useRecoilState(telemetryState);
const [createEventMutation] = useCreateEventMutation();
return useCallback(
(eventType: string, eventData: EventData) => {
if (telemetryEnabled) {
if (telemetry.enabled) {
createEventMutation({
variables: {
type: eventType,
@ -27,6 +27,6 @@ export function useEventTracker() {
});
}
},
[createEventMutation, telemetryEnabled],
[createEventMutation, telemetry],
);
}

View File

@ -1,4 +0,0 @@
export function useIsTelemetryEnabled() {
// TODO: replace by clientConfig
return process.env.IS_TELEMETRY_ENABLED !== 'false';
}