import { router } from "expo-router"; import { Alert } from "react-native"; import type { RemoveAccountResult } from "@/contexts/AccountsContext"; type FinishAccountRemovalInput = { result: RemoveAccountResult; clearActiveAccount: () => Promise; signOut: () => Promise; }; /** Navigate to sign-in when the last saved account was removed. */ export async function finishAccountRemoval({ result, clearActiveAccount, signOut, }: FinishAccountRemovalInput): Promise { if (result.remainingCount > 0) return; await signOut(); await clearActiveAccount(); router.replace("/(auth)/sign-in"); } export function confirmRemoveAccount( label: string, onRemove: () => Promise, onFinished: (result: RemoveAccountResult) => Promise, ) { Alert.alert("Remove account", `Remove ${label} from this device?`, [ { text: "Cancel", style: "cancel" }, { text: "Remove", style: "destructive", onPress: () => { void (async () => { const result = await onRemove(); await onFinished(result); })(); }, }, ]); }