feat(dashboard,js-sdk,admin-shared): add customer addresses + layout change (#11871)
what: - changes customer layout from 1 layout to 2 - adds ability to create and delete customer addresses - adds 2 customer widget locations - adds is_giftcard=false by default to products list <img width="1663" alt="Screenshot 2025-03-08 at 21 34 02" src="https://github.com/user-attachments/assets/e66f05da-718c-4c25-81ce-67ba0a814ca3" />
This commit is contained in:
@@ -14,6 +14,9 @@ import { customerGroupsQueryKeys } from "./customer-groups"
|
||||
|
||||
const CUSTOMERS_QUERY_KEY = "customers" as const
|
||||
export const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY)
|
||||
export const customerAddressesQueryKeys = queryKeysFactory(
|
||||
`${CUSTOMERS_QUERY_KEY}-addresses`
|
||||
)
|
||||
|
||||
export const useCustomer = (
|
||||
id: string,
|
||||
@@ -148,3 +151,113 @@ export const useBatchCustomerCustomerGroups = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateCustomerAddress = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateCustomerAddress
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => sdk.admin.customer.createAddress(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: customerAddressesQueryKeys.list(id),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateCustomerAddress = (
|
||||
id: string,
|
||||
addressId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateCustomerAddress
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.customer.updateAddress(id, addressId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: customerAddressesQueryKeys.list(id),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteCustomerAddress = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
FetchError,
|
||||
string
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (addressId: string) =>
|
||||
sdk.admin.customer.deleteAddress(id, addressId),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: customerAddressesQueryKeys.list(id),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useListCustomerAddresses = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
options?: UseQueryOptions<
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
QueryKey
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => sdk.admin.customer.listAddresses(id, query),
|
||||
queryKey: customerAddressesQueryKeys.list(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useCustomerAddress = (
|
||||
id: string,
|
||||
addressId: string,
|
||||
options?: UseQueryOptions<
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCustomerResponse,
|
||||
QueryKey
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => sdk.admin.customer.retrieveAddress(id, addressId),
|
||||
queryKey: customerAddressesQueryKeys.detail(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user