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:
committed by
GitHub
parent
122b3ea76b
commit
7e66dd0dd0
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user