From 05c6cf9e0463f223672afccb53377e489889aa32 Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Sun, 16 Aug 2026 22:17:15 +0700 Subject: [PATCH] feat(mobile): refresh entitlements after scan + route QUOTA_EXCEEDED to paywall --- apps/mobile/src/app/(tabs)/scan.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/mobile/src/app/(tabs)/scan.tsx b/apps/mobile/src/app/(tabs)/scan.tsx index 6e1963d..b6a8bf3 100644 --- a/apps/mobile/src/app/(tabs)/scan.tsx +++ b/apps/mobile/src/app/(tabs)/scan.tsx @@ -2,8 +2,8 @@ import { useEffect, useState } from "react"; import { Alert, View } from "react-native"; import { router } from "expo-router"; import * as ImagePicker from "expo-image-picker"; -import { useQuery } from "@tanstack/react-query"; -import { api, uploadImage } from "@/lib/api"; +import { useQuery, useQueryClient } from "@tanstack/react-query"; +import { api, uploadImage, ApiError } from "@/lib/api"; import { t } from "@/lib/i18n"; import { Body, @@ -48,7 +48,8 @@ export default function ScanScreen() { const [busyType, setBusyType] = useState(null); const coach = useFirstScanCoach(); const { track } = useAnalytics(); - const entitlements = useQuery({ + const queryClient = useQueryClient(); + const entitlements = useQuery({ queryKey: ["entitlements"], queryFn: () => api("/v1/me/entitlements"), }); @@ -82,7 +83,9 @@ export default function ScanScreen() { body: { scanType, imageCount: 1, contentType: "image/jpeg" }, }); - // 3. Ladda upp + starta analysen + queryClient.invalidateQueries({ queryKey: ["entitlements"] }); + + // 3. Ladda upp + starta analysen const upload = created.uploads[0]; if (!upload) throw new Error(t("common.error")); await uploadImage(upload, asset.uri); @@ -91,7 +94,11 @@ export default function ScanScreen() { // 4. Vidare till granskningsvyn som pollar tills resultatet kommer router.push(`${scanType === "plate" ? "/meal-review" : "/scan-review"}/${created.scan.id}`); } catch (err) { - Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")); + if (err instanceof ApiError && err.code === "QUOTA_EXCEEDED") { + router.push("/paywall"); + } else { + Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")); + } } finally { setBusyType(null); }