Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / containers / credentialLeak / useBreaches.ts
blob3406a326d4a7a02dea273af036b7487f3c2c89c7
1 import { useMemo, useState } from 'react';
3 import type { FetchedBreaches } from '@proton/components/containers/credentialLeak/models';
4 import { BREACH_STATE } from '@proton/components/containers/credentialLeak/models';
6 export const useBreaches = () => {
7     const [breaches, setBreaches] = useState<FetchedBreaches[]>([]);
9     const updateBreachState = (breachId: string, state: BREACH_STATE) => {
10         setBreaches((breaches) =>
11             breaches.map((breach) => {
12                 if (breach.id === breachId) {
13                     return { ...breach, resolvedState: state };
14                 }
15                 return breach;
16             })
17         );
18     };
20     const actions = useMemo(
21         () => ({
22             resolve: (breach: FetchedBreaches) => updateBreachState(breach.id, BREACH_STATE.RESOLVED),
23             open: (breach: FetchedBreaches) => updateBreachState(breach.id, BREACH_STATE.READ),
24             load: (breaches: FetchedBreaches[]) => setBreaches(breaches),
25         }),
26         []
27     );
29     return { breaches, actions };