Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions components/ordercontainer/OrderSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,34 @@ export default function OrderSteps({
// ── Pickup step ────────────────────────────────────────────────

if (step === OrderStep.PICKUP) {
const hasExistingTimeslot = !!orderDetails?.pickupTimeslot;

return (
<Box {...containerProps}>
<StepIndicator />
<Heading size="lg" mb={2}>
📍 Select Pickup Time
{hasExistingTimeslot
? "📍 Change Pickup Time"
: "📍 Select Pickup Time"}
</Heading>
<Text color="gray.600" mb={4}>
Order <strong>{orderNumber}</strong> has been paid. Choose when
you&apos;d like to collect it.
{hasExistingTimeslot ? (
<>
Order <strong>{orderNumber}</strong> already has a pickup time.
Select a new timeslot below.
</>
) : (
<>
Order <strong>{orderNumber}</strong> has been paid. Choose when
you&apos;d like to collect it.
</>
)}
</Text>
<OrderSummary />
<Divider mb={6} />
<TimeslotSelector
orderId={orderId}
currentTimeslot={orderDetails?.pickupTimeslot ?? null}
onTimeslotSelected={() => onPickupConfirmed()}
onCancel={() => router.push("/my-orders")}
/>
Expand Down
53 changes: 50 additions & 3 deletions components/pickup/TimeslotSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,21 @@ interface TimeslotResponse {
hasMore: boolean;
}

interface CurrentTimeslot {
date: string;
startTime: string;
endTime: string;
label?: string;
pickupInstructionProfile?:
| { id: string; name: string; shortSummary?: string }
| string
| null;
}

interface TimeslotSelectorProps {
orderId: string;
/** If provided, indicates the user is changing an existing timeslot. */
currentTimeslot?: CurrentTimeslot | null;
onTimeslotSelected: (
timeslotId: string,
pickupInstructions?: unknown[],
Expand Down Expand Up @@ -106,9 +119,11 @@ async function fetchTimeslots(page: number): Promise<TimeslotResponse> {
*/
export function TimeslotSelector({
orderId,
currentTimeslot,
onTimeslotSelected,
onCancel,
}: TimeslotSelectorProps) {
const isChanging = !!currentTimeslot;
const [selectedId, setSelectedId] = useState<string | null>(null);
const [submitting, setSubmitting] = useState(false);
const [submitError, setSubmitError] = useState<string | null>(null);
Expand Down Expand Up @@ -204,9 +219,41 @@ export function TimeslotSelector({
transition="opacity 0.15s ease"
>
<Heading size="md" mb={4}>
Select a Pickup Timeslot
{isChanging ? "Change Pickup Timeslot" : "Select a Pickup Timeslot"}
</Heading>

{/* Show current timeslot when changing */}
{isChanging && currentTimeslot && (
<Box
p={4}
mb={5}
bg="orange.50"
borderRadius="lg"
borderLeft="4px solid"
borderLeftColor="orange.400"
>
<Text fontSize="xs" fontWeight={700} color="orange.700" mb={1}>
CURRENT TIMESLOT
</Text>
<Text fontWeight={600} fontSize="sm">
{currentTimeslot.startTime} – {currentTimeslot.endTime}
{currentTimeslot.label ? ` · ${currentTimeslot.label}` : ""}
</Text>
{typeof currentTimeslot.pickupInstructionProfile === "object" &&
currentTimeslot.pickupInstructionProfile && (
<Text fontSize="sm" color="blue.600" mt={1}>
📍 {currentTimeslot.pickupInstructionProfile.name}
{currentTimeslot.pickupInstructionProfile.shortSummary && (
<Text as="span" color="gray.500">
{" "}
— {currentTimeslot.pickupInstructionProfile.shortSummary}
</Text>
)}
</Text>
)}
</Box>
)}

{submitError && (
<Alert status="error" mb={3} borderRadius="md">
<AlertIcon />
Expand Down Expand Up @@ -328,9 +375,9 @@ export function TimeslotSelector({
onClick={handleSubmit}
isDisabled={!selectedId || submitting}
isLoading={submitting}
loadingText="Confirming..."
loadingText={isChanging ? "Updating..." : "Confirming..."}
>
Confirm Timeslot
{isChanging ? "Update Timeslot" : "Confirm Timeslot"}
</Button>
<Button variant="outline" onClick={onCancel}>
Cancel
Expand Down
Loading