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 };
20 const actions = useMemo(
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),
29 return { breaches, actions };