{option.name} - {option.shipping_profile.name} (
{formatProvider(option.provider_id)})
{isStoreOption ? t("general.store") : t("general.admin")}
,
label: t("stockLocations.shippingOptions.edit.action"),
to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${option.service_zone_id}/shipping-option/${option.id}/edit`,
},
{
label: t("stockLocations.shippingOptions.pricing.action"),
icon:
,
disabled:
option.price_type === ShippingOptionPriceType.Calculated,
to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${option.service_zone_id}/shipping-option/${option.id}/pricing`,
},
],
},
{
actions: [
{
label: t("actions.delete"),
icon:
,
onClick: handleDelete,
},
],
},
]}
/>
)
}
type ServiceZoneOptionsProps = {
zone: HttpTypes.AdminServiceZone
locationId: string
fulfillmentSetId: string
type: FulfillmentSetType
}
function ServiceZoneOptions({
zone,
locationId,
fulfillmentSetId,
type,
}: ServiceZoneOptionsProps) {
const { t } = useTranslation()
const shippingOptions = zone.shipping_options.filter(
(o) => !isReturnOption(o)
)
const returnOptions = zone.shipping_options.filter((o) => isReturnOption(o))
return (
{t(`stockLocations.shippingOptions.create.${type}.label`)}
{t("stockLocations.shippingOptions.create.action")}
{!!shippingOptions.length && (
{shippingOptions.map((o) => (
))}
)}
{t("stockLocations.shippingOptions.create.returns.label")}
{t("stockLocations.shippingOptions.create.action")}
{!!returnOptions.length && (
{returnOptions.map((o) => (
))}
)}
)
}
type ServiceZoneProps = {
zone: HttpTypes.AdminServiceZone
locationId: string
fulfillmentSetId: string
type: FulfillmentSetType
}
function ServiceZone({
zone,
locationId,
fulfillmentSetId,
type,
}: ServiceZoneProps) {
const { t } = useTranslation()
const prompt = usePrompt()
const [open, setOpen] = useState(true)
const { mutateAsync: deleteZone } = useDeleteFulfillmentServiceZone(
fulfillmentSetId,
zone.id
)
const handleDelete = async () => {
const res = await prompt({
title: t("general.areYouSure"),
description: t("stockLocations.serviceZones.delete.confirmation", {
name: zone.name,
}),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
})
if (!res) {
return
}
await deleteZone(undefined, {
onError: (e) => {
toast.error(e.message)
},
onSuccess: () => {
toast.success(
t("stockLocations.serviceZones.delete.successToast", {
name: zone.name,
})
)
},
})
}
const countries = useMemo(() => {
const countryGeoZones = zone.geo_zones.filter((g) => g.type === "country")
const countries = countryGeoZones
.map(({ country_code }) =>
staticCountries.find((c) => c.iso_2 === country_code)
)
.filter((c) => !!c) as StaticCountry[]
if (
process.env.NODE_ENV === "development" &&
countryGeoZones.length !== countries.length
) {
console.warn(
"Some countries are missing in the static countries list",
countryGeoZones
.filter((g) => !countries.find((c) => c.iso_2 === g.country_code))
.map((g) => g.country_code)
)
}
return countries.sort((c1, c2) => c1.name.localeCompare(c2.name))
}, [zone.geo_zones])
const [shippingOptionsCount, returnOptionsCount] = useMemo(() => {
const options = zone.shipping_options
const optionsCount = options.filter((o) => !isReturnOption(o)).length
const returnOptionsCount = options.filter(isReturnOption).length
return [optionsCount, returnOptionsCount]
}, [zone.shipping_options])
return (