feat(dashboard,icons,types,js-sdk): add providers to location UI (#8328)

This commit is contained in:
Riqwan Thamir
2024-07-30 08:47:01 +02:00
committed by GitHub
parent b539c6d5bb
commit c976361f22
22 changed files with 616 additions and 103 deletions
@@ -11,6 +11,7 @@ import { HttpTypes } from "@medusajs/types"
import { sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { fulfillmentProvidersQueryKeys } from "./fulfillment-providers"
const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const
export const stockLocationsQueryKeys = queryKeysFactory(
@@ -175,3 +176,28 @@ export const useCreateStockLocationFulfillmentSet = (
...options,
})
}
export const useUpdateStockLocationFulfillmentProviders = (
id: string,
options?: UseMutationOptions<
HttpTypes.AdminStockLocationResponse,
FetchError,
HttpTypes.AdminBatchLink
>
) => {
return useMutation({
mutationFn: (payload) =>
sdk.admin.stockLocation.updateFulfillmentProviders(id, payload),
onSuccess: async (data, variables, context) => {
await queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.details(),
})
await queryClient.invalidateQueries({
queryKey: fulfillmentProvidersQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}
@@ -0,0 +1,25 @@
import { HttpTypes } from "@medusajs/types"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import {
TextCell,
TextHeader,
} from "../../../components/table/table-cells/common/text-cell"
import { formatProvider } from "../../../lib/format-provider"
const columnHelper = createColumnHelper<HttpTypes.AdminFulfillmentProvider>()
export const useFulfillmentProviderTableColumns = () => {
const { t } = useTranslation()
return useMemo(
() => [
columnHelper.accessor("id", {
header: () => <TextHeader text={"Provider"} />,
cell: ({ getValue }) => <TextCell text={formatProvider(getValue())} />,
}),
],
[t]
)
}
@@ -0,0 +1,31 @@
import { HttpTypes } from "@medusajs/types"
import { useQueryParams } from "../../use-query-params"
type UseFulfillmentProviderTableQueryProps = {
prefix?: string
pageSize?: number
}
export const useFulfillmentProvidersTableQuery = ({
prefix,
pageSize = 20,
}: UseFulfillmentProviderTableQueryProps) => {
const queryObject = useQueryParams(
["offset", "q", "stock_location_id"],
prefix
)
const { offset, q, stock_location_id } = queryObject
const searchParams: HttpTypes.AdminFulfillmentProviderListParams = {
limit: pageSize,
offset: offset ? Number(offset) : 0,
stock_location_id,
q,
}
return {
searchParams,
raw: queryObject,
}
}