From fef579b2b794be6f4b8e963fe4ed2c4c8f734aec Mon Sep 17 00:00:00 2001 From: JustZvan Date: Wed, 8 Apr 2026 19:48:30 +0200 Subject: feat: 1.2 --- api/settings.ts | 39 +++++++++++++++++++++++++++++++++++ app/(tabs)/settings.tsx | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/locales.ts | 11 ++++++++++ 3 files changed, 105 insertions(+) diff --git a/api/settings.ts b/api/settings.ts index 2823afa..217be01 100644 --- a/api/settings.ts +++ b/api/settings.ts @@ -5,6 +5,13 @@ interface VerifyEmailResponse { reason?: string; } +interface KidLinkCodeResponse { + success: boolean; + code?: string; + expiresInSeconds?: number; + reason?: string; +} + export async function verifyEmail( code: string, ): Promise<{ success: boolean; error?: string }> { @@ -23,6 +30,38 @@ export async function verifyEmail( } } +export async function requestKidLinkCode(): Promise<{ + success: boolean; + code?: string; + expiresInSeconds?: number; + error?: string; +}> { + try { + const response: KidLinkCodeResponse = await apiClient.post( + "/parent/kid-link-code", + ); + + if (!response.success || !response.code) { + return { + success: false, + error: response.reason || "Failed to generate link code", + }; + } + + return { + success: true, + code: response.code, + expiresInSeconds: response.expiresInSeconds, + }; + } catch (e) { + console.error("Failed to request kid link code", e); + return { + success: false, + error: e instanceof Error ? e.message : "Failed to generate link code", + }; + } +} + export interface UserProfile { email: string; emailVerified: boolean; diff --git a/app/(tabs)/settings.tsx b/app/(tabs)/settings.tsx index b4493b4..c19da37 100644 --- a/app/(tabs)/settings.tsx +++ b/app/(tabs)/settings.tsx @@ -5,6 +5,7 @@ import { Device, getDevices, getUserProfile, + requestKidLinkCode, renameDevice, UserProfile, verifyEmail, @@ -38,6 +39,12 @@ export default function SettingsScreen() { success: boolean; message: string; }>({ visible: false, success: false, message: "" }); + const [kidLinkCodeResult, setKidLinkCodeResult] = useState<{ + visible: boolean; + success: boolean; + title: string; + message: string; + }>({ visible: false, success: false, title: "", message: "" }); const showNotWired = () => setAlertVisible(true); @@ -86,6 +93,32 @@ export default function SettingsScreen() { setVerifyEmailVisible(false); }; + const handleGenerateKidLinkCode = async () => { + const result = await requestKidLinkCode(); + + if (result.success && result.code) { + const expiresMinutes = Math.max( + 1, + Math.ceil((result.expiresInSeconds ?? 300) / 60), + ); + + setKidLinkCodeResult({ + visible: true, + success: true, + title: t("kidLinkCodeTitle"), + message: `${result.code}\n${t("kidLinkCodeExpiresIn")} ${expiresMinutes} min`, + }); + return; + } + + setKidLinkCodeResult({ + visible: true, + success: false, + title: t("error"), + message: result.error || t("failedToGenerateKidLinkCode"), + }); + }; + return ( + + setKidLinkCodeResult({ ...kidLinkCodeResult, visible: false }) + } + /> +

{t("account")}

+ + } + /> + {profile && !profile.emailVerified && ( <>