fix(dashboard,medusa): Fixes to Customer and Customer Groups domains (#7081)
**What** - Cleanup of domains - Adds toasts - Adds delete customer hook - Fixes validation of create and update customer endpoints.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
AdminCustomerListResponse,
|
||||
AdminCustomerResponse,
|
||||
DeleteResponse,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
@@ -9,10 +14,6 @@ import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { CreateCustomerReq, UpdateCustomerReq } from "../../types/api-payloads"
|
||||
import {
|
||||
AdminCustomerResponse,
|
||||
AdminCustomerListResponse,
|
||||
} from "@medusajs/types"
|
||||
|
||||
const CUSTOMERS_QUERY_KEY = "customers" as const
|
||||
export const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY)
|
||||
@@ -88,3 +89,21 @@ export const useUpdateCustomer = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteCustomer = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<DeleteResponse, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.customers.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: customersQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
+16
-17
@@ -1,35 +1,34 @@
|
||||
import { Text } from "@medusajs/ui"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import {
|
||||
CreatedAtCell,
|
||||
CreatedAtHeader,
|
||||
} from "../../../components/table/table-cells/common/created-at-cell"
|
||||
import { NameHeader } from "../../../components/table/table-cells/common/name-cell"
|
||||
TextCell,
|
||||
TextHeader,
|
||||
} from "../../../components/table/table-cells/common/text-cell"
|
||||
|
||||
const columnHelper =
|
||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
||||
|
||||
export const useCustomerGroupTableColumns = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMemo(
|
||||
() => [
|
||||
columnHelper.display({
|
||||
id: "name",
|
||||
header: () => <NameHeader />,
|
||||
cell: ({
|
||||
row: {
|
||||
original: { name },
|
||||
},
|
||||
}) => <Text size="small">{name}</Text>,
|
||||
columnHelper.accessor("name", {
|
||||
header: () => <TextHeader text={t("fields.name")} />,
|
||||
cell: ({ getValue }) => <TextCell text={getValue() || "-"} />,
|
||||
}),
|
||||
columnHelper.accessor("customers", {
|
||||
header: () => <TextHeader text={t("customers.domain")} />,
|
||||
cell: ({ getValue }) => {
|
||||
const count = getValue()?.length ?? 0
|
||||
|
||||
columnHelper.accessor("created_at", {
|
||||
header: () => <CreatedAtHeader />,
|
||||
cell: ({ getValue }) => <CreatedAtCell date={getValue()} />,
|
||||
return <TextCell text={count} />
|
||||
},
|
||||
}),
|
||||
],
|
||||
[]
|
||||
[t]
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { Customer } from "@medusajs/medusa"
|
||||
import { createColumnHelper } from "@tanstack/react-table"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { AdminCustomerResponse } from "@medusajs/types"
|
||||
import {
|
||||
EmailCell,
|
||||
EmailHeader,
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
FirstSeenHeader,
|
||||
} from "../../../components/table/table-cells/customer/first-seen-cell"
|
||||
|
||||
const columnHelper = createColumnHelper<Customer>()
|
||||
const columnHelper = createColumnHelper<AdminCustomerResponse["customer"]>()
|
||||
|
||||
export const useCustomerTableColumns = () => {
|
||||
return useMemo(
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Filter } from "../../../components/table/data-table"
|
||||
|
||||
export const useCustomerGroupTableFilters = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
let filters: Filter[] = []
|
||||
|
||||
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",
|
||||
}))
|
||||
|
||||
filters = [...filters, ...dateFilters]
|
||||
|
||||
return filters
|
||||
}
|
||||
Reference in New Issue
Block a user