diff --git a/src/components/PlansSection.tsx b/src/components/PlansSection.tsx index dd1ad13..0f2147b 100644 --- a/src/components/PlansSection.tsx +++ b/src/components/PlansSection.tsx @@ -24,13 +24,13 @@ const formSchema = z.object({ företag: z.string().trim().min(1, "Fyll i företagsnamn").max(100), epost: z.string().trim().email("Ange en giltig e-postadress").max(255), telefon: z.string().trim().max(30).optional(), - adress: z.string().trim().max(200).optional(), + adress: z.string().trim().min(1, "Fyll i leveransadress").max(200), postnummer: z .string() .trim() .min(1, "Fyll i postnummer") .refine(isStockholmPostalCode, "Vi levererar endast inom Storstockholm (100 00 – 199 99)"), - stad: z.string().trim().max(100).optional(), + stad: z.string().trim().min(1, "Fyll i stad").max(100), kommentarer: z.string().trim().max(1000).optional(), }); @@ -67,7 +67,7 @@ const PlansSection = () => { (async () => { const { data } = await supabase .from("profiles") - .select("company_name, phone, street_address, postal_code") + .select("company_name, phone, street_address, postal_code, city") .eq("user_id", user.id) .maybeSingle(); setForm((prev) => ({ @@ -77,6 +77,7 @@ const PlansSection = () => { telefon: prev.telefon || data?.phone || "", adress: prev.adress || data?.street_address || "", postnummer: prev.postnummer || data?.postal_code || "", + stad: prev.stad || data?.city || "", })); })(); }, [user, showForm]); @@ -118,9 +119,9 @@ const PlansSection = () => { company: result.data.företag, email: result.data.epost, phone: result.data.telefon ?? "", - address: result.data.adress ?? "", + address: result.data.adress, postal_code: result.data.postnummer, - city: "Storstockholm", + city: result.data.stad, comments: result.data.kommentarer ?? "", return_url: `${window.location.origin}/order-confirmation?session_id={CHECKOUT_SESSION_ID}&method=card&kg=${recommendedKg}&email=${encodeURIComponent(result.data.epost)}`, environment: getStripeEnvironment(), @@ -371,16 +372,23 @@ const PlansSection = () => {
- + + {errors.adress && ( +

{errors.adress}

+ )}
-
+
+
+ + + {errors.stad && ( +

{errors.stad}

+ )} +
diff --git a/src/components/admin/OrdersTable.tsx b/src/components/admin/OrdersTable.tsx index d1b0613..e268030 100644 --- a/src/components/admin/OrdersTable.tsx +++ b/src/components/admin/OrdersTable.tsx @@ -93,6 +93,7 @@ export function OrdersTable() { Ordernummer Kund + Leveransadress Datum Status Belopp @@ -101,33 +102,57 @@ export function OrdersTable() { {filteredOrders?.length === 0 ? ( - + Inga ordrar hittades ) : ( - filteredOrders?.map((order) => ( - - {order.order_number} - -
-
{order.customer_name || "—"}
-
{order.customer_email}
-
-
- - {format(new Date(order.created_at), "d MMM yyyy, HH:mm", { locale: sv })} - - - - {statusLabels[order.status] || order.status} - - - - {Number(order.total_amount).toLocaleString("sv-SE")} {order.currency} - -
- )) + filteredOrders?.map((order) => { + const item = Array.isArray(order.items) ? order.items[0] : null; + const lev = item?.leverans; + const phone = item?.telefon; + const comments = item?.kommentarer; + return ( + + {order.order_number} + +
+
{order.customer_name || "—"}
+
{order.customer_email}
+ {phone &&
{phone}
} +
+
+ + {lev ? ( +
+
{lev.adress || "—"}
+
+ {[lev.postnummer, lev.stad].filter(Boolean).join(" ")} +
+ {comments && ( +
+ "{comments}" +
+ )} +
+ ) : ( + + )} +
+ + {format(new Date(order.created_at), "d MMM yyyy, HH:mm", { locale: sv })} + + + + {statusLabels[order.status] || order.status} + + + + {Number(order.total_amount).toLocaleString("sv-SE")} {order.currency} + +
+ ); + }) )}
diff --git a/supabase/functions/create-checkout/index.ts b/supabase/functions/create-checkout/index.ts index 43f7782..11eb29a 100644 --- a/supabase/functions/create-checkout/index.ts +++ b/supabase/functions/create-checkout/index.ts @@ -56,7 +56,7 @@ async function insertOrder(row: { leverans: { adress: b.address, postnummer: cleaned, - stad: "Storstockholm", + stad: b.city, }, telefon: b.phone, kommentarer: b.comments, @@ -100,9 +100,9 @@ const BodySchema = z.object({ company: z.string().trim().min(1).max(200), email: z.string().trim().email().max(255), phone: z.string().trim().max(30).optional().default(""), - address: z.string().trim().max(200).optional().default(""), + address: z.string().trim().min(1).max(200), postal_code: z.string().trim().min(1).max(20), - city: z.string().trim().max(100).optional().default(""), + city: z.string().trim().min(1).max(100), comments: z.string().trim().max(1000).optional().default(""), return_url: z.string().url(), environment: z.enum(["sandbox", "live"]),