feat(ui,dashboard): Migrate SC tables to DataTable (#11106)
This commit is contained in:
committed by
GitHub
parent
d588073cea
commit
fcd3e2226e
@@ -41,7 +41,7 @@ export const useSalesChannel = (
|
||||
}
|
||||
|
||||
export const useSalesChannels = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminSalesChannelListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminSalesChannelListResponse,
|
||||
@@ -133,6 +133,34 @@ export const useDeleteSalesChannel = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteSalesChannelLazy = (
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminSalesChannelDeleteResponse,
|
||||
FetchError,
|
||||
string
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => sdk.admin.salesChannel.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: salesChannelsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: salesChannelsQueryKeys.detail(variables),
|
||||
})
|
||||
|
||||
// Invalidate all products to ensure they are updated if they were linked to the sales channel
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: productsQueryKeys.all,
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useSalesChannelRemoveProducts = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
|
||||
@@ -8,6 +8,4 @@ export * from "./use-product-tag-table-columns"
|
||||
export * from "./use-product-type-table-columns"
|
||||
export * from "./use-region-table-columns"
|
||||
export * from "./use-return-reason-table-columns"
|
||||
export * from "./use-sales-channel-table-columns"
|
||||
export * from "./use-tax-rates-table-columns"
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { StatusCell } from "../../../components/table/table-cells/common/status-cell"
|
||||
import { TextHeader } from "../../../components/table/table-cells/common/text-cell"
|
||||
import {
|
||||
DescriptionCell,
|
||||
DescriptionHeader,
|
||||
} from "../../../components/table/table-cells/sales-channel/description-cell"
|
||||
import {
|
||||
NameCell,
|
||||
NameHeader,
|
||||
} from "../../../components/table/table-cells/sales-channel/name-cell"
|
||||
|
||||
const columnHelper = createColumnHelper<HttpTypes.AdminSalesChannel>()
|
||||
|
||||
export const useSalesChannelTableColumns = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMemo(
|
||||
() => [
|
||||
columnHelper.accessor("name", {
|
||||
header: () => <NameHeader />,
|
||||
cell: ({ getValue }) => <NameCell name={getValue()} />,
|
||||
}),
|
||||
columnHelper.accessor("description", {
|
||||
header: () => <DescriptionHeader />,
|
||||
cell: ({ getValue }) => <DescriptionCell description={getValue()} />,
|
||||
}),
|
||||
columnHelper.accessor("is_disabled", {
|
||||
header: () => <TextHeader text={t("fields.status")} />,
|
||||
cell: ({ getValue }) => {
|
||||
const value = getValue()
|
||||
return (
|
||||
<StatusCell color={value ? "grey" : "green"}>
|
||||
{value ? t("general.disabled") : t("general.enabled")}
|
||||
</StatusCell>
|
||||
)
|
||||
},
|
||||
}),
|
||||
],
|
||||
[t]
|
||||
)
|
||||
}
|
||||
@@ -8,6 +8,5 @@ export * from "./use-product-tag-table-filters"
|
||||
export * from "./use-product-type-table-filters"
|
||||
export * from "./use-promotion-table-filters"
|
||||
export * from "./use-region-table-filters"
|
||||
export * from "./use-sales-channel-table-filters"
|
||||
export * from "./use-shipping-option-table-filters"
|
||||
export * from "./use-tax-rate-table-filters"
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Filter } from "../../../components/table/data-table"
|
||||
|
||||
export const useSalesChannelTableFilters = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const dateFilters: Filter[] = [
|
||||
{ label: t("fields.createdAt"), key: "created_at" },
|
||||
{ label: t("fields.updatedAt"), key: "updated_at" },
|
||||
].map((f) => ({
|
||||
key: f.key,
|
||||
label: f.label,
|
||||
type: "date",
|
||||
}))
|
||||
|
||||
return dateFilters
|
||||
}
|
||||
@@ -8,7 +8,6 @@ export * from "./use-product-tag-table-query"
|
||||
export * from "./use-product-type-table-query"
|
||||
export * from "./use-region-table-query"
|
||||
export * from "./use-return-reason-table-query"
|
||||
export * from "./use-sales-channel-table-query"
|
||||
export * from "./use-shipping-option-table-query"
|
||||
export * from "./use-tax-rate-table-query"
|
||||
export * from "./use-tax-region-table-query"
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { useQueryParams } from "../../use-query-params"
|
||||
|
||||
type UseSalesChannelTableQueryProps = {
|
||||
prefix?: string
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export const useSalesChannelTableQuery = ({
|
||||
prefix,
|
||||
pageSize = 20,
|
||||
}: UseSalesChannelTableQueryProps) => {
|
||||
const queryObject = useQueryParams(
|
||||
["offset", "q", "order", "created_at", "updated_at", "is_disabled"],
|
||||
prefix
|
||||
)
|
||||
|
||||
const { offset, created_at, updated_at, is_disabled, ...rest } = queryObject
|
||||
|
||||
const searchParams: HttpTypes.AdminSalesChannelListParams = {
|
||||
limit: pageSize,
|
||||
offset: offset ? Number(offset) : 0,
|
||||
created_at: created_at ? JSON.parse(created_at) : undefined,
|
||||
updated_at: updated_at ? JSON.parse(updated_at) : undefined,
|
||||
is_disabled:
|
||||
is_disabled === "true"
|
||||
? true
|
||||
: is_disabled === "false"
|
||||
? false
|
||||
: undefined,
|
||||
...rest,
|
||||
}
|
||||
|
||||
return {
|
||||
searchParams,
|
||||
raw: queryObject,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user