about summary refs log tree commit diff
path: root/src/components/PolicyUpdateOverlay/usePreemptivelyCompleteActivePolicyUpdate.ts
blob: f41b3e6d7d4fec4225f6d7cc554f698f14ed2127 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import {useCallback} from 'react'

import {ACTIVE_UPDATE_ID} from '#/components/PolicyUpdateOverlay/config'
import {logger} from '#/components/PolicyUpdateOverlay/logger'
import {device, useStorage} from '#/storage'

/*
 * Marks the active policy update as completed in device storage.
 * `usePolicyUpdateState` will react to this and replicate this status in the
 * server NUX state for this account.
 */
export function usePreemptivelyCompleteActivePolicyUpdate() {
  const [_completedForDevice, setCompletedForDevice] = useStorage(device, [
    ACTIVE_UPDATE_ID,
  ])

  return useCallback(() => {
    logger.debug(`preemptively completing active policy update`)
    setCompletedForDevice(true)
  }, [setCompletedForDevice])
}