feat(mobile): veckoplan – skapa inköpslista från planen (stänger plan→laga→handla-loopen)
CI / Typecheck, test & build (push) Successful in 1m34s

This commit is contained in:
Sven (AAMOS AI)
2026-08-14 03:12:49 +07:00
parent 4d9c69d0ce
commit e3d50707e8
13 changed files with 36 additions and 0 deletions
+24
View File
@@ -1,5 +1,6 @@
import { useEffect, useMemo, useState } from "react";
import { Alert, Pressable, Text, View } from "react-native";
import { router } from "expo-router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { api } from "@/lib/api";
import { getLanguageTag, t } from "@/lib/i18n";
@@ -89,6 +90,7 @@ export default function PlanScreen() {
const plan = query.data?.plans?.[0] ?? null;
const planId = plan?.id ?? null;
const draftPlanId = plan && plan.status === "draft" ? plan.id : null;
const hasEntries = (plan?.entries?.length ?? 0) > 0;
const entriesByDate = useMemo(() => {
const map: Record<string, WeekPlanEntry[]> = {};
@@ -147,6 +149,16 @@ export default function PlanScreen() {
onError: onMutationError,
});
const createList = useMutation({
mutationFn: (weekPlanId: string) =>
api("/v1/shopping-lists", {
method: "POST",
body: { weekPlanId, generateFromPlan: true },
}),
onSuccess: () => router.push("/shopping"),
onError: onMutationError,
});
const openActions = (entry: WeekPlanEntry) => {
if (!planId) return;
Alert.alert(entry.titleSv, undefined, [
@@ -306,6 +318,18 @@ export default function PlanScreen() {
)}
</>
)}
{hasEntries ? (
<>
<Spacer size={spacing.sm} />
<Button
label={t("plan.createShopping")}
variant="secondary"
onPress={() => planId && createList.mutate(planId)}
loading={createList.isPending}
/>
</>
) : null}
</Screen>
);
}