Files
beenvoice-app/lib/account-actions.ts
soconnor 06bc91ac13 Redesign mobile time clock, add shortcuts, and improve account management.
Add iOS Shortcuts/Siri intents, local send-reminder notifications, stable
client picker with last-client defaults, account refresh/remove, and softer
session handling on unauthorized API responses.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-22 16:06:17 -04:00

44 lines
1.1 KiB
TypeScript

import { router } from "expo-router";
import { Alert } from "react-native";
import type { RemoveAccountResult } from "@/contexts/AccountsContext";
type FinishAccountRemovalInput = {
result: RemoveAccountResult;
clearActiveAccount: () => Promise<void>;
signOut: () => Promise<unknown>;
};
/** Navigate to sign-in when the last saved account was removed. */
export async function finishAccountRemoval({
result,
clearActiveAccount,
signOut,
}: FinishAccountRemovalInput): Promise<void> {
if (result.remainingCount > 0) return;
await signOut();
await clearActiveAccount();
router.replace("/(auth)/sign-in");
}
export function confirmRemoveAccount(
label: string,
onRemove: () => Promise<RemoveAccountResult>,
onFinished: (result: RemoveAccountResult) => Promise<void>,
) {
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);
})();
},
},
]);
}