feat(mobile): veckoplan – skapa inköpslista från planen (stänger plan→laga→handla-loopen)
CI / Typecheck, test & build (push) Successful in 1m34s
CI / Typecheck, test & build (push) Successful in 1m34s
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user