1 import { useParams } from "react-router-dom"
2
3 import { RouteFocusModal } from "../../../components/modals"
4 import { useStockLocation } from "../../../hooks/api/stock-locations"
5 import { EditServiceZoneAreasForm } from "./components/edit-region-areas-form"
6 import { jsonResponse } from "../../../lib/json-response"
7
8 export const LocationServiceZoneManageAreas = () => {
9 const { location_id, fset_id, zone_id } = useParams()
10
11 const { stock_location, isPending, isFetching, isError, error } =
12 useStockLocation(location_id!, {
13 fields:
14 "*fulfillment_sets.service_zones.geo_zones,fulfillment_sets.service_zones.name",
15 })
16
17 const zone = stock_location?.fulfillment_sets
18 ?.find((f) => f.id === fset_id)
19 ?.service_zones.find((z) => z.id === zone_id)
20
21 if (!isPending && !isFetching && !zone) {
22 throw jsonResponse(
23 { message: `Service zone with ID ${zone_id} was not found` },
24 404
25 )
26 }
27
28 if (isError) {
29 throw error
30 }
31
32 return (
33 <RouteFocusModal prev={`/settings/locations/${location_id}`}>
34 {zone && (
35 <EditServiceZoneAreasForm
36 zone={zone}
37 fulfillmentSetId={fset_id!}
38 locationId={location_id!}
39 />
40 )}
41 </RouteFocusModal>
42 )
43 }