diff --git a/apps/user-ui/src/components/AddressForm.tsx b/apps/user-ui/src/components/AddressForm.tsx index d34fda6..31bc38c 100644 --- a/apps/user-ui/src/components/AddressForm.tsx +++ b/apps/user-ui/src/components/AddressForm.tsx @@ -28,7 +28,6 @@ const AddressForm: React.FC = ({ const [isSubmitting, setIsSubmitting] = useState(false); const [submitError, setSubmitError] = useState(null); const [mapOpen, setMapOpen] = useState(false); - const [mapConfirmOpen, setMapConfirmOpen] = useState(false); const [currentLocation, setCurrentLocation] = useState( initialValues?.latitude != null && initialValues?.longitude != null ? { latitude: initialValues.latitude, longitude: initialValues.longitude } @@ -53,14 +52,48 @@ const AddressForm: React.FC = ({ const cityName = regions.find((region) => region.id === resolvedRegion?.regionId)?.name ?? ''; // The map focuses on the region the address will belong to: the region a picked - // location resolved to, else the browsing region. Confirmed before opening, and - // its stored centre (first-priority bound) becomes the map's centre. + // location resolved to, else the browsing region. Its stored centre + // (first-priority bound) becomes the map's centre. const mapRegion = regions.find((region) => region.id === (resolvedRegion?.regionId ?? browsingRegionId)) ?? null; - const openMap = useCallback(() => { - setMapConfirmOpen(false); + /** Centre the map WebView opens on (null = the page's own default). */ + const [mapCenter, setMapCenter] = useState<{ lat: number; lng: number } | null>(null); + /** + * The pending "which region is this map for?" confirmation. Only the two + * location triggers ask — the City selector's "Select in Map" opens straight + * away. Null means no dialog. + */ + const [mapDialog, setMapDialog] = useState<{ regionName: string | null } | null>(null); + + const requestMapForAddressRegion = useCallback(() => { + Keyboard.dismiss(); + setMapCenter(mapRegion?.center ?? null); + setMapDialog({ regionName: mapRegion?.name ?? null }); + }, [mapRegion]); + + // The City selector's fallback: no town picked, so open the map straight away, + // focused on the first region's bound (the first row of that selector). + const openMapForFirstRegion = useCallback(() => { + const firstRegion = regions[0] ?? null; + setCityOpen(false); + setMapCenter(firstRegion?.center ?? null); setMapOpen(true); + }, [regions]); + + const confirmMapDialog = useCallback(() => { + setMapDialog(null); + setMapOpen(true); + }, []); + + const dismissMapDialog = useCallback(() => { + setMapDialog(null); + setMapCenter(null); + }, []); + + const closeMap = useCallback(() => { + setMapOpen(false); + setMapCenter(null); }, []); // Resolve coordinates -> region + bound. Used for whichever source the user @@ -344,6 +377,16 @@ const AddressForm: React.FC = ({ {regions.length === 0 && ( No towns available )} + + {/* Last option: skip the town list and pick the point on the map. */} + + + Select in Map + )} @@ -376,7 +419,7 @@ const AddressForm: React.FC = ({ setMapConfirmOpen(true)} + onPress={requestMapForAddressRegion} style={tw`flex-row items-center mt-2`} > @@ -388,7 +431,7 @@ const AddressForm: React.FC = ({ ) : ( setMapConfirmOpen(true)} + onPress={requestMapForAddressRegion} style={tw`flex-row items-center`} > @@ -438,35 +481,37 @@ const AddressForm: React.FC = ({ /> {/* Confirm the region before handing over to the map WebView, which opens - focused on that region's centre. */} - setMapConfirmOpen(false)}> + focused on that region's centre. ("Select in Map" skips this.) */} + - {mapRegion ? `Open the map for ${mapRegion.name}?` : 'Open the map?'} + {mapDialog?.regionName + ? `Open the map for ${mapDialog.regionName}?` + : 'Open the map?'} - {mapRegion - ? `The map will open on ${mapRegion.name}. Pick a point inside this region.` + {mapDialog?.regionName + ? `The map will open on ${mapDialog.regionName}. Pick a point inside this region.` : 'Pick a point on the map.'} setMapConfirmOpen(false)} + onPress={dismissMapDialog} style={tw`flex-1 border border-gray-200 py-3.5 rounded-xl items-center`} > Cancel Open map @@ -476,15 +521,15 @@ const AddressForm: React.FC = ({ {/* Full-screen map picker. */} - setMapOpen(false)}> + { - setMapOpen(false); + closeMap(); void resolveLocation(coords, 'map'); }} - onCancel={() => setMapOpen(false)} + onCancel={closeMap} /> diff --git a/change-log.txt b/change-log.txt index e8addea..1f8ccc3 100644 --- a/change-log.txt +++ b/change-log.txt @@ -4768,3 +4768,26 @@ user-ui selected region; on confirm the map opens focused on that region's stored centre. apps/web-ui: unchanged (option A - the page already centres from ?lat=&lng). No tests run. + +2026-10-15 22:03:55 AddressForm City selector: + "Select in Map" as the last option. + + apps/user-ui/src/components/AddressForm.tsx + - the City picker (the selector above the Delivery Location / map block) now ends with a + "Select in Map" row. Picking it opens the map focused on the FIRST region's bound (the + first region in that same name-ordered list; its stored `center` is already its + first-priority bound's centre). + - the pending-map state is now a single `mapRequest { regionName, center }` instead of a + boolean, so the confirm dialog's wording and the WebView's lat/lng both come from the + request: the address's region for the two existing triggers, the first region for + "Select in Map". It is cleared when the map closes. + - the confirmation BottomDialog is kept for this path too. + No other file changed. No tests run. + +2026-10-15 22:09:40 "Select in Map" now opens the map directly (no confirmation). + + apps/user-ui/src/components/AddressForm.tsx + - the single `mapRequest` state is split: `mapCenter` (what the WebView opens on) and + `mapDialog` (the pending confirmation, null = hidden). "Select in Map" sets the centre to + the first region's bound and opens the map in the same step, skipping the dialog; the two + location triggers still ask first. + No other file changed. No tests run.