feat(dashboard): shipping option tax rate overrides UI (#13260)

* feat(dashboard): shipping option tax rate overrides UI

* feat: add location filter

* feat: show service zone in SO table

* feat: display location in the SO table
This commit is contained in:
Frane Polić
2025-08-21 12:06:36 +02:00
committed by GitHub
parent 37f372ccf7
commit 9b38b750de
14 changed files with 480 additions and 76 deletions
@@ -0,0 +1,89 @@
import { HttpTypes } from "@medusajs/types"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import { DateCell } from "../../../components/table/table-cells/common/date-cell"
import { TextCell } from "../../../components/table/table-cells/common/text-cell"
import { getFormattedShippingOptionLocationName } from "../../../lib/shipping-options"
const columnHelper = createColumnHelper<HttpTypes.AdminShippingOption>()
export const useShippingOptionTableColumns = () => {
const { t } = useTranslation()
return useMemo(
() => [
columnHelper.accessor("name", {
header: () => t("fields.name"),
cell: ({ getValue }) => <TextCell text={getValue()} />,
}),
columnHelper.accessor("shipping_profile", {
header: () => t("fields.shippingProfile"),
cell: ({ row }) => (
<TextCell text={row.original.shipping_profile?.name || "N/A"} />
),
}),
columnHelper.display({
id: "location",
header: () => t("fields.location"),
cell: ({ row }) => {
const locationName = getFormattedShippingOptionLocationName(
row.original
)
return <TextCell text={locationName} />
},
}),
columnHelper.display({
id: "service_zone",
header: () => t("fields.serviceZone"),
cell: ({ row }) => {
const serviceZoneName = row.original.service_zone?.name
return <TextCell text={serviceZoneName || "N/A"} />
},
}),
columnHelper.display({
id: "enabled_in_store",
header: () => t("fields.enabledInStore"),
cell: ({ row }) => {
let text = "N/A"
const val = row.original.rules?.find(
(r) => r.attribute === "enabled_in_store"
)
if (val) {
text = val.value === "true" ? "Yes" : "No"
}
return <TextCell text={text} />
},
}),
columnHelper.display({
id: "is_return",
header: () => t("fields.isReturn"),
cell: ({ row }) => {
let text = "N/A"
const val = row.original.rules?.find(
(r) => r.attribute === "is_return"
)
if (val) {
text = val.value === "true" ? "Yes" : "No"
}
return <TextCell text={text} />
},
}),
columnHelper.accessor("created_at", {
header: () => t("fields.createdAt"),
cell: ({ getValue }) => {
return <DateCell date={getValue()} />
},
}),
],
[t]
)
}
@@ -1,27 +1,18 @@
import { useTranslation } from "react-i18next"
import { HttpTypes } from "@medusajs/types"
import { Filter } from "../../../components/table/data-table"
export const useShippingOptionTableFilters = () => {
export const useShippingOptionTableFilters = (
locations: HttpTypes.AdminStockLocation[]
) => {
const { t } = useTranslation()
const isReturnFilter: Filter = {
key: "is_return",
label: t("fields.type"),
const locationFilter: Filter = {
key: "stock_location_id",
label: t("fields.location"),
type: "select",
options: [
{ label: t("regions.return"), value: "true" },
{ label: t("regions.outbound"), value: "false" },
],
}
const isAdminFilter: Filter = {
key: "admin_only",
label: t("fields.availability"),
type: "select",
options: [
{ label: t("general.admin"), value: "true" },
{ label: t("general.store"), value: "false" },
],
options: locations.map((l) => ({ label: l.name, value: l.id })),
}
const dateFilters: Filter[] = [
@@ -33,7 +24,7 @@ export const useShippingOptionTableFilters = () => {
type: "date",
}))
const filters = [isReturnFilter, isAdminFilter, ...dateFilters]
const filters = [locationFilter, ...dateFilters]
return filters
}
@@ -22,22 +22,34 @@ export const useShippingOptionTableQuery = ({
"is_return",
"created_at",
"updated_at",
"stock_location_id",
],
prefix
)
const { offset, order, q, admin_only, is_return, created_at, updated_at } =
queryObject
const {
offset,
order,
q,
admin_only,
is_return,
created_at,
updated_at,
stock_location_id,
} = queryObject
const searchParams: HttpTypes.AdminShippingOptionListParams = {
limit: pageSize,
offset: offset ? Number(offset) : 0,
// TODO: We don't allow region_id in the API yet
// region_id: regionId,
is_return: is_return ? is_return === "true" : undefined,
admin_only: admin_only ? admin_only === "true" : undefined,
// TODO: not supported
// is_return: is_return ? is_return === "true" : undefined,
// admin_only: admin_only ? admin_only === "true" : undefined,
q,
order,
stock_location_id,
created_at: created_at ? JSON.parse(created_at) : undefined,
updated_at: updated_at ? JSON.parse(updated_at) : undefined,
}