From dc0f7f51c590d3857c84e59d5e94cd804fbac992 Mon Sep 17 00:00:00 2001 From: Hermes Date: Fri, 21 Aug 2026 14:25:16 +0200 Subject: [PATCH] fix(client): allow self-booking in manual-confirmation status confirm-delivery-choice blocked any order_groups with delivery_status other than 'pending_confirmation', so orders in manual handling (manual_confirmation_required) showed the client a form but rejected the save. Allow booking for manual_confirmation_required so clients can pick date+time until the order is assigned/paid. Surface 'paid_storage' and 'driver_assigned' states to the client view instead of a dead form. --- supabase/functions/_shared/delivery-invitations.ts | 6 +++++- supabase/functions/confirm-delivery-choice/index.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/supabase/functions/_shared/delivery-invitations.ts b/supabase/functions/_shared/delivery-invitations.ts index 7372297..1637dc0 100644 --- a/supabase/functions/_shared/delivery-invitations.ts +++ b/supabase/functions/_shared/delivery-invitations.ts @@ -88,7 +88,7 @@ export const getClientInvitationStateFromOrderGroupStatus = ( deliveryStatus: string | null | undefined, invitationState: string | null | undefined, ): DeliveryInvitationPublicState => { - if (deliveryStatus === "agreed") { + if (deliveryStatus === "agreed" || deliveryStatus === "driver_assigned") { return "agreed"; } @@ -96,6 +96,10 @@ export const getClientInvitationStateFromOrderGroupStatus = ( return "delivered"; } + if (deliveryStatus === "paid_storage") { + return "paid_storage"; + } + if (["awaiting_choice", "opened", "reminder_sent"].includes(String(invitationState || ""))) { return invitationState as DeliveryInvitationPublicState; } diff --git a/supabase/functions/confirm-delivery-choice/index.ts b/supabase/functions/confirm-delivery-choice/index.ts index 65a5d78..5ecfcbc 100644 --- a/supabase/functions/confirm-delivery-choice/index.ts +++ b/supabase/functions/confirm-delivery-choice/index.ts @@ -20,6 +20,14 @@ import { const MAX_BODY_BYTES = 8 * 1024; +// Order groups a client may still self-book (choose delivery date+time) on. +// manual_confirmation_required (ручная обработка) stays bookable until the +// order leaves these states (date assigned / paid storage / finished). +const CLIENT_BOOKABLE_STATUSES = new Set([ + "pending_confirmation", + "manual_confirmation_required", +]); + type ConfirmBody = { token?: string; deliveryDate?: string; @@ -191,7 +199,9 @@ Deno.serve(async (request) => { ? "agreed" : "requires_address"; - if (!isActiveInvitationState(invitation.state) || currentGroup.delivery_status !== "pending_confirmation") { + const bookingBlocked = !CLIENT_BOOKABLE_STATUSES.has(currentGroup.delivery_status || ""); + + if (!isActiveInvitationState(invitation.state) || bookingBlocked) { return jsonResponse( { ok: false,