import React from 'react'; import { View, Text } from 'react-native'; import { AppContainer } from 'common-ui'; import SlotForm from '@/components/SlotForm'; import { useRouter, useLocalSearchParams } from 'expo-router'; import { trpc } from '@/src/trpc-client'; export default function AddSlot() { const router = useRouter(); const { baseslot, dts, fts } = useLocalSearchParams(); const baseSlotId = baseslot ? parseInt(baseslot as string) : null; // e2e hook: SlotForm accepts initial times but nothing passed them, so the // screen always opened with null times and e2e had to fight the native // picker (which cannot set time-of-day). Deep links can carry the exact // delivery/freeze instants as ISO strings: ...?dts=&fts=. // URL-encoding collapses colons in ISO strings to %3A, so normalize. const parseInstant = (raw?: string | string[]): Date | null => { const value = Array.isArray(raw) ? raw[0] : raw if (!value) return null const date = new Date(value.replace(/%3A/gi, ':')) return isNaN(date.getTime()) ? null : date } const initialDeliveryTime = parseInstant(dts) const initialFreezeTime = parseInstant(fts) const { refetch } = trpc.admin.slots.getAll.useQuery(); const { data: baseSlotData, isLoading } = trpc.admin.slots.getSlotById.useQuery( { id: baseSlotId! }, { enabled: !!baseSlotId } ); const handleSlotAdded = () => { refetch(); router.back(); }; if (isLoading && baseSlotId) { return ( Loading base slot... ); } return ( p.id) || []} initialGroupIds={baseSlotData?.slot?.groupIds || []} /> ); }