Some checks failed
CI / Lint, Unit & Integration Tests (push) Has been cancelled
Audited the implementation against DS_Delivery_Date_Time_App_Study.docx and closed the actionable gaps (see IMPLEMENTATION_REVIEW_2026-09-04.md). Core (code + unit tests, 156 green): - Wire excludeLocationsWithoutStock into resolveAvailabilityRequest; widget now sends variantIds so inventory-based location exclusion actually runs. - Live slot re-validation at checkout: new checkout-snapshot.server.ts writes a shop-metafield capacity snapshot; validation-slot's evaluateCheckout rejects a complete selection that has since filled / blacked out / closed / hit the daily cap / left the schedule. Refreshed on order webhooks and slot/blackout/location/enforcement edits. - Scopable checkout enforcement: Shop.enforcementMode (all|tagged|off) + enforcementTag, new app.settings.tsx admin page, honoured via the snapshot. - Per-day order cap: Location.dailyOrderCap threaded through getAvailability (dailyCap + consumedPerDate); admin field on the location screen. - Product-rule slot blocking: ProductRule.blockedStartMins, unioned in resolveProductRuleConstraints, enforced in the engine and resolveHoldRequest; admin field on the product rules screen. - Product-page placement: product-availability.liquid block + widget data-mode="preview" (read-only earliest-date line). - Second locale: datetime-widget fr.json / fr.schema.json. - Migration 20260904120000_review_gaps (apply with prisma migrate deploy). New Functions (source + unit tests; need `shopify app deploy` to ship): - extensions/payment-customization: cart.payment-methods.transform.run — hides cash-on-delivery / pay-in-store gateways on SHIPPING orders. - extensions/checkout-datetime/src: restored from a gitignored dist-only state — Plus native picker + Thank you / Order status confirmation blocks, all calling the existing checkout.scheduling.* routes (one capacity pool). tsconfig ships checkJs:false pending reconciliation with live checkout types. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
210 lines
7.3 KiB
TypeScript
210 lines
7.3 KiB
TypeScript
import { useState } from "react";
|
|
import { redirect, type ActionFunctionArgs, type LoaderFunctionArgs } from "@remix-run/node";
|
|
import { Form, useActionData, useLoaderData, useNavigation } from "@remix-run/react";
|
|
import {
|
|
Page,
|
|
Card,
|
|
BlockStack,
|
|
FormLayout,
|
|
TextField,
|
|
Button,
|
|
InlineStack,
|
|
Checkbox,
|
|
} from "@shopify/polaris";
|
|
import { TitleBar } from "@shopify/app-bridge-react";
|
|
import { authenticate } from "../shopify.server";
|
|
import db from "../db.server";
|
|
import { geocodeAddress } from "../services/zones.server";
|
|
import { writeCheckoutSnapshot } from "../services/checkout-snapshot.server";
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const { session } = await authenticate.admin(request);
|
|
|
|
const location = await db.location.findFirst({
|
|
where: { id: params.id, shopDomain: session.shop },
|
|
});
|
|
|
|
if (!location) {
|
|
throw new Response("Not found", { status: 404 });
|
|
}
|
|
|
|
return { location };
|
|
};
|
|
|
|
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|
const { session, admin } = await authenticate.admin(request);
|
|
const formData = await request.formData();
|
|
const intent = formData.get("intent");
|
|
|
|
if (intent === "delete") {
|
|
await db.location.deleteMany({ where: { id: params.id, shopDomain: session.shop } });
|
|
await writeCheckoutSnapshot(admin, session.shop);
|
|
return redirect("/app/locations");
|
|
}
|
|
|
|
const name = String(formData.get("name") || "").trim();
|
|
const address = String(formData.get("address") || "").trim();
|
|
const timezone = String(formData.get("timezone") || "").trim();
|
|
const active = formData.get("active") === "true";
|
|
const shopifyLocationId = String(formData.get("shopifyLocationId") || "").trim() || null;
|
|
const dailyOrderCapRaw = String(formData.get("dailyOrderCap") || "").trim();
|
|
const dailyOrderCap = dailyOrderCapRaw ? Number(dailyOrderCapRaw) : null;
|
|
|
|
const errors: Record<string, string> = {};
|
|
if (!name) errors.name = "Name is required";
|
|
if (!timezone) errors.timezone = "Timezone is required";
|
|
if (dailyOrderCap != null && (!Number.isFinite(dailyOrderCap) || dailyOrderCap < 1)) {
|
|
errors.dailyOrderCap = "Leave blank for no cap, or enter a whole number ≥ 1";
|
|
}
|
|
if (Object.keys(errors).length > 0) {
|
|
return { errors };
|
|
}
|
|
|
|
// Auto-geocode on save so radius zones and the widget's pickup map have
|
|
// coordinates without a separate manual step — no-ops silently if
|
|
// GOOGLE_MAPS_API_KEY isn't configured (see zones.server.ts).
|
|
const coordinates = address ? await geocodeAddress(address) : null;
|
|
|
|
await db.location.updateMany({
|
|
where: { id: params.id, shopDomain: session.shop },
|
|
data: {
|
|
name,
|
|
address,
|
|
timezone,
|
|
active,
|
|
shopifyLocationId,
|
|
dailyOrderCap,
|
|
...(coordinates ? { lat: coordinates.lat, lng: coordinates.lng } : {}),
|
|
},
|
|
});
|
|
|
|
await writeCheckoutSnapshot(admin, session.shop);
|
|
return { errors };
|
|
};
|
|
|
|
export default function EditLocation() {
|
|
const { location } = useLoaderData<typeof loader>();
|
|
const actionData = useActionData<typeof action>();
|
|
const navigation = useNavigation();
|
|
const isSubmitting = navigation.state === "submitting";
|
|
|
|
return (
|
|
<Page backAction={{ url: "/app/locations" }}>
|
|
<TitleBar title={location.name} />
|
|
<LocationForm key={location.id} location={location} errors={actionData?.errors} isSubmitting={isSubmitting} />
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
function LocationForm({
|
|
location,
|
|
errors,
|
|
isSubmitting,
|
|
}: {
|
|
location: {
|
|
id: string;
|
|
name: string;
|
|
address: string;
|
|
timezone: string;
|
|
active: boolean;
|
|
shopifyLocationId: string | null;
|
|
dailyOrderCap: number | null;
|
|
lat: number | null;
|
|
lng: number | null;
|
|
};
|
|
errors?: Record<string, string>;
|
|
isSubmitting: boolean;
|
|
}) {
|
|
const [name, setName] = useState(location.name);
|
|
const [address, setAddress] = useState(location.address);
|
|
const [timezone, setTimezone] = useState(location.timezone);
|
|
const [active, setActive] = useState(location.active);
|
|
const [shopifyLocationId, setShopifyLocationId] = useState(location.shopifyLocationId ?? "");
|
|
const [dailyOrderCap, setDailyOrderCap] = useState(
|
|
location.dailyOrderCap != null ? String(location.dailyOrderCap) : "",
|
|
);
|
|
|
|
return (
|
|
<BlockStack gap="400">
|
|
<Card>
|
|
<Form method="post">
|
|
<FormLayout>
|
|
<TextField
|
|
label="Location name"
|
|
name="name"
|
|
autoComplete="off"
|
|
value={name}
|
|
onChange={setName}
|
|
error={errors?.name}
|
|
requiredIndicator
|
|
/>
|
|
<TextField
|
|
label="Address"
|
|
name="address"
|
|
autoComplete="off"
|
|
multiline={2}
|
|
value={address}
|
|
onChange={setAddress}
|
|
helpText={
|
|
location.lat != null
|
|
? `Geocoded: ${location.lat.toFixed(4)}, ${location.lng?.toFixed(4)}`
|
|
: "Saved without coordinates — set GOOGLE_MAPS_API_KEY to auto-geocode on save."
|
|
}
|
|
/>
|
|
<TextField
|
|
label="Timezone (IANA)"
|
|
name="timezone"
|
|
autoComplete="off"
|
|
value={timezone}
|
|
onChange={setTimezone}
|
|
error={errors?.timezone}
|
|
requiredIndicator
|
|
/>
|
|
<TextField
|
|
label="Shopify Location ID (advanced)"
|
|
name="shopifyLocationId"
|
|
autoComplete="off"
|
|
value={shopifyLocationId}
|
|
onChange={setShopifyLocationId}
|
|
helpText="gid://shopify/Location/… — only needed for inventory-based location exclusion."
|
|
/>
|
|
<TextField
|
|
label="Daily order cap (optional)"
|
|
name="dailyOrderCap"
|
|
type="number"
|
|
autoComplete="off"
|
|
value={dailyOrderCap}
|
|
onChange={setDailyOrderCap}
|
|
error={errors?.dailyOrderCap}
|
|
helpText="Once this many orders are booked for a calendar day (across every method and slot), that whole day disappears from the picker. Blank = no daily cap."
|
|
/>
|
|
<Checkbox label="Active" name="active" value="true" checked={active} onChange={setActive} />
|
|
<InlineStack gap="200">
|
|
<Button submit variant="primary" loading={isSubmitting}>
|
|
Save
|
|
</Button>
|
|
<Button url={`/app/slots?locationId=${location.id}`}>Manage weekly slots</Button>
|
|
<Button url={`/app/blackouts?locationId=${location.id}`}>Manage blackout dates</Button>
|
|
<Button url={`/app/zones?locationId=${location.id}`}>Manage delivery zones</Button>
|
|
</InlineStack>
|
|
</FormLayout>
|
|
</Form>
|
|
</Card>
|
|
<Card>
|
|
<Form method="post">
|
|
<input type="hidden" name="intent" value="delete" />
|
|
<InlineStack align="space-between" blockAlign="center">
|
|
<BlockStack gap="050">
|
|
<strong>Delete this location</strong>
|
|
<span>Removes all its slot templates and blackout dates.</span>
|
|
</BlockStack>
|
|
<Button submit tone="critical" variant="secondary">
|
|
Delete location
|
|
</Button>
|
|
</InlineStack>
|
|
</Form>
|
|
</Card>
|
|
</BlockStack>
|
|
);
|
|
}
|