useOpenAISuggestionLocalStorage.tsx 801 B

1234567891011121314151617181920212223242526
  1. import {useCallback} from 'react';
  2. import ConfigStore from 'sentry/stores/configStore';
  3. import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
  4. export function useOpenAISuggestionLocalStorage(): [
  5. boolean,
  6. (agreedForwardDataToOpenAI: boolean) => void
  7. ] {
  8. const user = ConfigStore.get('user');
  9. const [localStorageState, setLocalStorageState] = useLocalStorageState<{
  10. agreedForwardDataToOpenAI: boolean;
  11. }>(`open-ai-suggestion:${user.id}`, {
  12. agreedForwardDataToOpenAI: false,
  13. });
  14. const setAgreedForwardDataToOpenAI = useCallback(
  15. (agreedForwardDataToOpenAI: boolean) => {
  16. setLocalStorageState({agreedForwardDataToOpenAI});
  17. },
  18. [setLocalStorageState]
  19. );
  20. return [localStorageState.agreedForwardDataToOpenAI, setAgreedForwardDataToOpenAI];
  21. }