enh
This commit is contained in:
parent
b967213449
commit
612728761d
5 changed files with 130 additions and 5 deletions
|
|
@ -1011,6 +1011,8 @@ real.
|
|||
| ADDRF-37 | edge | map URL without lat/lng | base URL only |
|
||||
| ADDRF-38 | edge | edit + device fix | submits saved coords; device never auto-attached |
|
||||
| ADDRF-39 | edge | edit region differs from browsing | saved address town kept |
|
||||
| ADDRF-40 | edge | attached location outside the service area | submit button disabled |
|
||||
| ADDRF-41 | edge | picked town does not contain the location | submit button disabled |
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
return browsingRegionId != null ? { regionId: browsingRegionId, boundId: browsingBoundId } : null
|
||||
});
|
||||
const [locationError, setLocationError] = useState<string | null>(null);
|
||||
// True while a location/bound resolution request is in flight.
|
||||
const [isCheckingLocation, setIsCheckingLocation] = useState(false);
|
||||
const [locationSource, setLocationSource] = useState<LocationSource | null>(
|
||||
initialValues?.latitude != null && initialValues?.longitude != null ? 'device' : null
|
||||
);
|
||||
|
|
@ -113,6 +115,7 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
setCurrentLocation(coords);
|
||||
setLocationSource(source);
|
||||
setLocationError(null);
|
||||
setIsCheckingLocation(true);
|
||||
try {
|
||||
const resolved = await utils.common.resolveRegionByLocation.fetch({
|
||||
lat: coords.latitude,
|
||||
|
|
@ -132,6 +135,8 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
} catch {
|
||||
setResolvedRegion(null);
|
||||
setLocationError('Could not verify this location. Please try again.');
|
||||
} finally {
|
||||
setIsCheckingLocation(false);
|
||||
}
|
||||
},
|
||||
[utils, onResolvedRegion]
|
||||
|
|
@ -148,6 +153,7 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
}
|
||||
setResolvedRegion({ regionId, boundId: null });
|
||||
setLocationError(null);
|
||||
setIsCheckingLocation(true);
|
||||
try {
|
||||
const resolved = await utils.common.resolveBound.fetch({
|
||||
regionId,
|
||||
|
|
@ -159,6 +165,8 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
onResolvedRegion?.(info);
|
||||
} catch {
|
||||
setLocationError('Your location is outside this town. Pick a point on the map inside it.');
|
||||
} finally {
|
||||
setIsCheckingLocation(false);
|
||||
}
|
||||
},
|
||||
[utils, currentLocation, onResolvedRegion]
|
||||
|
|
@ -229,6 +237,12 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
isDefault: Yup.boolean(),
|
||||
});
|
||||
|
||||
// Submit is gated on a location that actually resolved inside a serviceable
|
||||
// town: a point outside the delivery area (or one still being checked) must
|
||||
// not be saveable.
|
||||
const isLocationServiceable =
|
||||
currentLocation != null && resolvedRegion != null && !locationError && !isCheckingLocation;
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={tw`flex-1 bg-white`}
|
||||
|
|
@ -269,7 +283,7 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
setSubmitError('Please attach your current location or select it on the map.');
|
||||
return;
|
||||
}
|
||||
if (!resolvedRegion || locationError) {
|
||||
if (!resolvedRegion || locationError || isCheckingLocation) {
|
||||
setSubmitError(locationError || 'Please choose a town and a location inside it.');
|
||||
return;
|
||||
}
|
||||
|
|
@ -436,9 +450,9 @@ const AddressForm: React.FC<AddressFormProps & {
|
|||
|
||||
<MyTouchableOpacity
|
||||
testID="address-submit"
|
||||
style={tw`bg-indigo-600 p-3 rounded ${isSubmitting || !currentLocation ? 'opacity-50' : ''}`}
|
||||
style={tw`bg-indigo-600 p-3 rounded ${isSubmitting || !isLocationServiceable ? 'opacity-50' : ''}`}
|
||||
onPress={() => handleSubmit()}
|
||||
disabled={isSubmitting || !currentLocation}
|
||||
disabled={isSubmitting || !isLocationServiceable}
|
||||
>
|
||||
<MyText style={tw`text-white text-center font-bold`}>
|
||||
{isSubmitting ? (isEdit ? 'Updating...' : 'Adding...') : (isEdit ? 'Update Address' : 'Add Address')}
|
||||
|
|
|
|||
|
|
@ -201,6 +201,45 @@ describe('AddressForm', () => {
|
|||
expect(getByText('Attach a location to add address')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('ADDRF-40: an attached location outside the service area disables submit', async () => {
|
||||
denyLocation()
|
||||
spyResolveRegion(null)
|
||||
const { getByTestId, getByText } = renderForm({ initialValues: withCoords() })
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
getByText('This location is outside our delivery area. Try selecting on the map.')
|
||||
).toBeTruthy()
|
||||
)
|
||||
|
||||
expect(getByTestId('address-submit').props.accessibilityState.disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('ADDRF-41: a town that does not contain the location keeps submit disabled', async () => {
|
||||
denyLocation()
|
||||
spyResolveRegion()
|
||||
setProcedure('common.resolveBound', {
|
||||
impl: jest.fn(() => {
|
||||
throw new Error('nope')
|
||||
}),
|
||||
})
|
||||
const screen = renderForm({ initialValues: withCoords() })
|
||||
|
||||
await waitFor(() => expect(screen.onResolvedRegion).toHaveBeenCalled())
|
||||
expect(screen.getByTestId('address-submit').props.accessibilityState.disabled).toBe(false)
|
||||
|
||||
fireEvent.press(screen.getByTestId('address-city'))
|
||||
fireEvent.press(screen.getByTestId('address-city-option-2'))
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByText('Your location is outside this town. Pick a point on the map inside it.')
|
||||
).toBeTruthy()
|
||||
)
|
||||
|
||||
expect(screen.getByTestId('address-submit').props.accessibilityState.disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('ADDRF-10: opening the city picker lists only the regions', async () => {
|
||||
denyLocation()
|
||||
const { getByTestId, queryByTestId, queryByText } = renderForm()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
const [mapCenter, setMapCenter] = useState<{ lat: number; lng: number } | null>(null)
|
||||
const [locating, setLocating] = useState(false)
|
||||
const [locationError, setLocationError] = useState<string | null>(null)
|
||||
// True while a location/bound resolution request is in flight.
|
||||
const [isCheckingLocation, setIsCheckingLocation] = useState(false)
|
||||
const [locationSource, setLocationSource] = useState<LocationSource | null>(
|
||||
initialValues?.latitude != null && initialValues?.longitude != null ? 'device' : null
|
||||
)
|
||||
|
|
@ -61,6 +63,7 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
}
|
||||
setResolvedRegion({ regionId, boundId: null })
|
||||
setLocationError(null)
|
||||
setIsCheckingLocation(true)
|
||||
try {
|
||||
const resolved = await utils.common.resolveBound.fetch({
|
||||
regionId,
|
||||
|
|
@ -72,6 +75,8 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
onResolvedRegion?.(info)
|
||||
} catch {
|
||||
setLocationError('Your location is outside this town. Pick a point on the map inside it.')
|
||||
} finally {
|
||||
setIsCheckingLocation(false)
|
||||
}
|
||||
},
|
||||
[utils, currentLocation, onResolvedRegion]
|
||||
|
|
@ -95,6 +100,7 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
setCurrentLocation(coords)
|
||||
setLocationSource(source)
|
||||
setLocationError(null)
|
||||
setIsCheckingLocation(true)
|
||||
try {
|
||||
const resolved = await utils.common.resolveRegionByLocation.fetch({
|
||||
lat: coords.latitude,
|
||||
|
|
@ -114,6 +120,8 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
} catch {
|
||||
setResolvedRegion(null)
|
||||
setLocationError('Could not verify this location. Please try again.')
|
||||
} finally {
|
||||
setIsCheckingLocation(false)
|
||||
}
|
||||
},
|
||||
[utils, onResolvedRegion]
|
||||
|
|
@ -208,6 +216,12 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
)
|
||||
}
|
||||
|
||||
// Submit is gated on a location that actually resolved inside a serviceable
|
||||
// town: a point outside the delivery area (or one still being checked) must
|
||||
// not be saveable.
|
||||
const isLocationServiceable =
|
||||
currentLocation != null && resolvedRegion != null && !locationError && !isCheckingLocation
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await validationSchema.validate(values, { abortEarly: false })
|
||||
|
|
@ -215,7 +229,7 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
setSubmitError('Please use your current location or select one on the map.')
|
||||
return
|
||||
}
|
||||
if (!resolvedRegion || locationError) {
|
||||
if (!resolvedRegion || locationError || isCheckingLocation) {
|
||||
setSubmitError(locationError || 'Please choose a town and a location inside it.')
|
||||
return
|
||||
}
|
||||
|
|
@ -386,7 +400,7 @@ export function AddressForm({ onSuccess, initialValues, isEdit = false, onResolv
|
|||
fullWidth
|
||||
textContent={isSubmitting ? (isEdit ? 'Updating...' : 'Adding...') : (isEdit ? 'Update Address' : 'Add Address')}
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting || !currentLocation}
|
||||
disabled={isSubmitting || !isLocationServiceable}
|
||||
className="bg-brand-500 text-white"
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10081,3 +10081,59 @@ record. Deploy target for dev: Worker `superadmin-ui-dev`.
|
|||
CLOUDFLARE_ENV=dev explanation, why prod hostnames stay out of top-level routes).
|
||||
Verified: superadmin.freshyo.in and devsuperadmin.freshyo.in both 307 -> /dashboard (200);
|
||||
CORS preflight from the dev origin now returns access-control-allow-origin.
|
||||
|
||||
[2026-10-25 16:19 IST] Address form: disable submit unless the attached location resolved inside a
|
||||
serviceable town.
|
||||
|
||||
--- apps/user-ui/src/components/AddressForm.tsx
|
||||
@@
|
||||
+ // True while a location/bound resolution request is in flight.
|
||||
+ const [isCheckingLocation, setIsCheckingLocation] = useState(false);
|
||||
@@ resolveLocation
|
||||
setLocationError(null);
|
||||
+ setIsCheckingLocation(true);
|
||||
try {
|
||||
@@
|
||||
} catch {
|
||||
setResolvedRegion(null);
|
||||
setLocationError('Could not verify this location. Please try again.');
|
||||
+ } finally {
|
||||
+ setIsCheckingLocation(false);
|
||||
}
|
||||
@@ handleCityChange
|
||||
setLocationError(null);
|
||||
+ setIsCheckingLocation(true);
|
||||
try {
|
||||
@@
|
||||
} catch {
|
||||
setLocationError('Your location is outside this town. Pick a point on the map inside it.');
|
||||
+ } finally {
|
||||
+ setIsCheckingLocation(false);
|
||||
}
|
||||
@@
|
||||
+ // Submit is gated on a location that actually resolved inside a serviceable
|
||||
+ // town: a point outside the delivery area (or one still being checked) must
|
||||
+ // not be saveable.
|
||||
+ const isLocationServiceable =
|
||||
+ currentLocation != null && resolvedRegion != null && !locationError && !isCheckingLocation;
|
||||
@@ onSubmit
|
||||
- if (!resolvedRegion || locationError) {
|
||||
+ if (!resolvedRegion || locationError || isCheckingLocation) {
|
||||
@@ submit button
|
||||
- style={tw`bg-indigo-600 p-3 rounded ${isSubmitting || !currentLocation ? 'opacity-50' : ''}`}
|
||||
+ style={tw`bg-indigo-600 p-3 rounded ${isSubmitting || !isLocationServiceable ? 'opacity-50' : ''}`}
|
||||
onPress={() => handleSubmit()}
|
||||
- disabled={isSubmitting || !currentLocation}
|
||||
+ disabled={isSubmitting || !isLocationServiceable}
|
||||
|
||||
--- apps/user-ui/tests/components/address-form.test.tsx
|
||||
Added ADDRF-40 (out-of-area attach disables submit) and ADDRF-41 (town mismatch keeps it
|
||||
disabled).
|
||||
|
||||
--- apps/web-ui/src/components/AddressForm.tsx
|
||||
Same change as the user-ui form (web counterpart per the mirror rule): isCheckingLocation
|
||||
state, try/finally around resolveLocation/handleCityChange, isLocationServiceable gate on
|
||||
handleSubmit and MyButton disabled.
|
||||
|
||||
--- apps/user-ui/JEST-TEST-CASES.md
|
||||
Catalogue rows ADDRF-40/41 added.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue