Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / onboarding / useOnboarding.ts
blob94e651908eccacbaa97778e28fe4f7684dd93af7
1 import { useEffect, useState } from 'react';
3 import useLoading from '@proton/hooks/useLoading';
4 import { queryListPendingExternalInvitations } from '@proton/shared/lib/api/drive/invitation';
5 import type { ListDrivePendingExternalInvitationsPayload } from '@proton/shared/lib/interfaces/drive/sharing';
7 import { useDebouncedRequest } from '../../store/_api';
8 import useChecklist from './useChecklist';
10 export const useOnboarding = () => {
11     const checklist = useChecklist();
12     const debouncedRequest = useDebouncedRequest();
13     const [isLoading, withIsLoading] = useLoading(false);
14     const [hasPendingExternalInvitations, setHasPendingExternalInvitations] = useState(false);
16     const getHasPendingExternalInvitations = () =>
17         withIsLoading(async () => {
18             const { ExternalInvitations } = await debouncedRequest<ListDrivePendingExternalInvitationsPayload>(
19                 queryListPendingExternalInvitations()
20             );
21             setHasPendingExternalInvitations(!!ExternalInvitations.length);
22         });
24     useEffect(() => {
25         void getHasPendingExternalInvitations();
26     }, []);
28     return { isLoading: checklist.isLoading || isLoading, checklist, hasPendingExternalInvitations };