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