import { useEffect, useRef, useState } from 'preact/hooks'; import { AlertDialog, AlertDialogDescription, AlertDialogLabel, } from '@reach/alert-dialog'; import { STRING_SIGN_OUT_CONFIRMATION } from '@/strings'; import { WebApplication } from '@/ui_models/application'; import { toDirective } from './utils'; import { AppState } from '@/ui_models/app_state'; import { observer } from 'mobx-react-lite'; type Props = { application: WebApplication; appState: AppState; }; const ConfirmSignoutContainer = observer((props: Props) => { if (!props.appState.accountMenu.signingOut) { return null; } return ; }); const ConfirmSignoutModal = observer(({ application, appState }: Props) => { const [deleteLocalBackups, setDeleteLocalBackups] = useState( application.hasAccount() ); const cancelRef = useRef(); function close() { appState.accountMenu.setSigningOut(false); } const [localBackupsCount, setLocalBackupsCount] = useState(0); useEffect(() => { application.bridge.localBackupsCount().then(setLocalBackupsCount); }, [appState.accountMenu.signingOut, application.bridge]); return ( End your session? {STRING_SIGN_OUT_CONFIRMATION} {localBackupsCount > 0 && ( { setDeleteLocalBackups( (event.target as HTMLInputElement).checked ); }} /> Delete {localBackupsCount} local backup file {localBackupsCount > 1 ? 's' : ''} { application.bridge.viewlocalBackups(); }} > View backup files )} Cancel { if (deleteLocalBackups) { application.signOutAndDeleteLocalBackups(); } else { application.signOut(); } close(); }} > {application.hasAccount() ? 'Sign Out' : 'Clear Session Data'} ); }); export const ConfirmSignoutDirective = toDirective( ConfirmSignoutContainer );
{STRING_SIGN_OUT_CONFIRMATION}