From cd6a9eb5560e21586bcda4025e0890d08221fabd Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Fri, 14 Aug 2026 21:17:55 +0700 Subject: [PATCH] =?UTF-8?q?feat(mobile):=20redigera=20kost/allergier/relig?= =?UTF-8?q?ion=20i=20profilen=20n=C3=A4r=20som=20helst=20(MIKRO=2063)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mobile/src/app/profile.tsx | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/apps/mobile/src/app/profile.tsx b/apps/mobile/src/app/profile.tsx index 943605e..12eef29 100644 --- a/apps/mobile/src/app/profile.tsx +++ b/apps/mobile/src/app/profile.tsx @@ -37,6 +37,11 @@ interface Consent { kind: string; status: string; } +interface Prefs { + dietPattern?: string | null; + allergens?: string[] | null; + religiousRule?: string | null; +} /** Samtyckesetiketter ur i18n-katalogen: profile.consent. (12 språk). */ const CONSENT_KINDS = [ @@ -48,6 +53,9 @@ const CONSENT_KINDS = [ "push_notifications", "product_analytics", ] as const; +const DIETS = ["omnivore", "flexitarian", "pescatarian", "vegetarian", "vegan"] as const; +const ALLERGENS = ["gluten", "milk", "eggs", "tree_nuts", "peanuts", "fish", "crustaceans", "soy", "sesame"] as const; +const RELIGIOUS = ["none", "halal", "kosher", "hindu_no_beef", "buddhist_vegetarian"] as const; export default function ProfileScreen() { const queryClient = useQueryClient(); @@ -62,6 +70,17 @@ export default function ProfileScreen() { queryKey: ["consents"], queryFn: () => api("/v1/me/consents"), }); + const prefs = useQuery({ + queryKey: ["preferences"], + queryFn: () => api("/v1/me/preferences"), + }); + const savePrefs = useMutation({ + mutationFn: (body: Record) => + api("/v1/me/preferences", { method: "PATCH", body }), + onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["preferences"] }), + onError: (err) => + Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")), + }); const setConsent = useMutation({ mutationFn: ({ kind, granted }: { kind: string; granted: boolean }) => @@ -111,6 +130,9 @@ export default function ProfileScreen() { if (me.isError) return void me.refetch()} />; const consentMap = new Map((consents.data ?? []).map((c) => [c.kind, c.status])); + const curDiet = prefs.data?.dietPattern ?? "omnivore"; + const curAllergens = prefs.data?.allergens ?? []; + const curReligious = prefs.data?.religiousRule ?? "none"; return ( @@ -162,6 +184,50 @@ export default function ProfileScreen() { + + {t("onboarding.diet")} + + {DIETS.map((id) => ( +