chore: Remove unused clients in admin + clean up js-sdk (#8839)
* feat(js-sdk): Add API key * chore: Remove unused clients in admin + clean up js-sdk * fix sales channel hooks
This commit is contained in:
1 parent
5294ce8654
commit
37b7592fba
20 files changed
+82
-284
No files matched your search
@@ -14,7 +14,7 @@ export const useCreateFulfillment = (
|
|||||||
options?: UseMutationOptions<any, Error, any>
|
options?: UseMutationOptions<any, Error, any>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload: any) => client.fulfillments.create(payload),
|
mutationFn: (payload: any) => sdk.admin.fulfillment.create(payload),
|
||||||
onSuccess: (data: any, variables: any, context: any) => {
|
onSuccess: (data: any, variables: any, context: any) => {
|
||||||
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -31,7 +31,7 @@ export const useCancelFulfillment = (
|
|||||||
options?: UseMutationOptions<any, Error, any>
|
options?: UseMutationOptions<any, Error, any>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.fulfillments.cancel(id),
|
mutationFn: () => sdk.admin.fulfillment.cancel(id),
|
||||||
onSuccess: (data: any, variables: any, context: any) => {
|
onSuccess: (data: any, variables: any, context: any) => {
|
||||||
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -6,29 +6,28 @@ import {
|
|||||||
useQuery,
|
useQuery,
|
||||||
UseQueryOptions,
|
UseQueryOptions,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
import { client, sdk } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/query-client"
|
import { queryClient } from "../../lib/query-client"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import { PaymentProvidersListRes } from "../../types/api-responses"
|
|
||||||
import { ordersQueryKeys } from "./orders"
|
import { ordersQueryKeys } from "./orders"
|
||||||
|
|
||||||
const PAYMENT_QUERY_KEY = "payment" as const
|
const PAYMENT_QUERY_KEY = "payment" as const
|
||||||
export const paymentQueryKeys = queryKeysFactory(PAYMENT_QUERY_KEY)
|
export const paymentQueryKeys = queryKeysFactory(PAYMENT_QUERY_KEY)
|
||||||
|
|
||||||
export const usePaymentProviders = (
|
export const usePaymentProviders = (
|
||||||
query?: Record<string, any>,
|
query?: HttpTypes.AdminGetPaymentProvidersParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
PaymentProvidersListRes,
|
HttpTypes.AdminGetPaymentProvidersParams,
|
||||||
Error,
|
Error,
|
||||||
PaymentProvidersListRes,
|
HttpTypes.AdminPaymentProviderListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryKey" | "queryFn"
|
"queryKey" | "queryFn"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: async () => client.payments.listPaymentProviders(query),
|
queryFn: async () => sdk.admin.payment.listPaymentProviders(query),
|
||||||
queryKey: [],
|
queryKey: [],
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,21 +5,14 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AdminSalesChannelListResponse,
|
AdminSalesChannelListResponse,
|
||||||
AdminSalesChannelResponse,
|
AdminSalesChannelResponse,
|
||||||
|
HttpTypes,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { client } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/query-client"
|
import { queryClient } from "../../lib/query-client"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import {
|
|
||||||
AddProductsSalesChannelReq,
|
|
||||||
CreateSalesChannelReq,
|
|
||||||
RemoveProductsSalesChannelReq,
|
|
||||||
UpdateSalesChannelReq,
|
|
||||||
} from "../../types/api-payloads"
|
|
||||||
import { SalesChannelDeleteRes } from "../../types/api-responses"
|
|
||||||
import { productsQueryKeys } from "./products"
|
import { productsQueryKeys } from "./products"
|
||||||
|
|
||||||
const SALES_CHANNELS_QUERY_KEY = "sales-channels" as const
|
const SALES_CHANNELS_QUERY_KEY = "sales-channels" as const
|
||||||
@@ -39,7 +32,7 @@ export const useSalesChannel = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: salesChannelsQueryKeys.detail(id),
|
queryKey: salesChannelsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.salesChannels.retrieve(id),
|
queryFn: async () => sdk.admin.salesChannel.retrieve(id),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -59,7 +52,7 @@ export const useSalesChannels = (
|
|||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.salesChannels.list(query),
|
queryFn: () => sdk.admin.salesChannel.list(query),
|
||||||
queryKey: salesChannelsQueryKeys.list(query),
|
queryKey: salesChannelsQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -71,11 +64,11 @@ export const useCreateSalesChannel = (
|
|||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminSalesChannelResponse,
|
AdminSalesChannelResponse,
|
||||||
Error,
|
Error,
|
||||||
CreateSalesChannelReq
|
HttpTypes.AdminCreateSalesChannel
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.salesChannels.create(payload),
|
mutationFn: (payload) => sdk.admin.salesChannel.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: salesChannelsQueryKeys.lists(),
|
queryKey: salesChannelsQueryKeys.lists(),
|
||||||
@@ -91,11 +84,11 @@ export const useUpdateSalesChannel = (
|
|||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminSalesChannelResponse,
|
AdminSalesChannelResponse,
|
||||||
Error,
|
Error,
|
||||||
UpdateSalesChannelReq
|
HttpTypes.AdminUpdateSalesChannel
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.salesChannels.update(id, payload),
|
mutationFn: (payload) => sdk.admin.salesChannel.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: salesChannelsQueryKeys.lists(),
|
queryKey: salesChannelsQueryKeys.lists(),
|
||||||
@@ -112,10 +105,14 @@ export const useUpdateSalesChannel = (
|
|||||||
|
|
||||||
export const useDeleteSalesChannel = (
|
export const useDeleteSalesChannel = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<SalesChannelDeleteRes, Error, void>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminSalesChannelDeleteResponse,
|
||||||
|
Error,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.salesChannels.delete(id),
|
mutationFn: () => sdk.admin.salesChannel.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: salesChannelsQueryKeys.lists(),
|
queryKey: salesChannelsQueryKeys.lists(),
|
||||||
@@ -140,11 +137,12 @@ export const useSalesChannelRemoveProducts = (
|
|||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminSalesChannelResponse,
|
AdminSalesChannelResponse,
|
||||||
Error,
|
Error,
|
||||||
RemoveProductsSalesChannelReq
|
HttpTypes.AdminBatchLink["remove"]
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.salesChannels.removeProducts(id, payload),
|
mutationFn: (payload) =>
|
||||||
|
sdk.admin.salesChannel.batchProducts(id, { remove: payload }),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: salesChannelsQueryKeys.lists(),
|
queryKey: salesChannelsQueryKeys.lists(),
|
||||||
@@ -154,7 +152,7 @@ export const useSalesChannelRemoveProducts = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Invalidate the products that were removed
|
// Invalidate the products that were removed
|
||||||
for (const product of variables?.product_ids || []) {
|
for (const product of variables || []) {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: productsQueryKeys.detail(product),
|
queryKey: productsQueryKeys.detail(product),
|
||||||
})
|
})
|
||||||
@@ -176,11 +174,12 @@ export const useSalesChannelAddProducts = (
|
|||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminSalesChannelResponse,
|
AdminSalesChannelResponse,
|
||||||
Error,
|
Error,
|
||||||
AddProductsSalesChannelReq
|
HttpTypes.AdminBatchLink["add"]
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.salesChannels.addProducts(id, payload),
|
mutationFn: (payload) =>
|
||||||
|
sdk.admin.salesChannel.batchProducts(id, { add: payload }),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: salesChannelsQueryKeys.lists(),
|
queryKey: salesChannelsQueryKeys.lists(),
|
||||||
@@ -190,7 +189,7 @@ export const useSalesChannelAddProducts = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Invalidate the products that were removed
|
// Invalidate the products that were removed
|
||||||
for (const product of variables?.product_ids || []) {
|
for (const product of variables || []) {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: productsQueryKeys.detail(product),
|
queryKey: productsQueryKeys.detail(product),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
import Medusa from "@medusajs/js-sdk"
|
||||||
import { campaigns } from "./campaigns"
|
import { campaigns } from "./campaigns"
|
||||||
import { categories } from "./categories"
|
import { categories } from "./categories"
|
||||||
import { currencies } from "./currencies"
|
|
||||||
import { customerGroups } from "./customer-groups"
|
import { customerGroups } from "./customer-groups"
|
||||||
import { fulfillmentProviders } from "./fulfillment-providers"
|
import { fulfillmentProviders } from "./fulfillment-providers"
|
||||||
import { fulfillments } from "./fulfillments"
|
|
||||||
import { invites } from "./invites"
|
|
||||||
import { payments } from "./payments"
|
|
||||||
import { priceLists } from "./price-lists"
|
|
||||||
import { productTypes } from "./product-types"
|
|
||||||
import { promotions } from "./promotions"
|
import { promotions } from "./promotions"
|
||||||
import { reservations } from "./reservations"
|
import { reservations } from "./reservations"
|
||||||
import { salesChannels } from "./sales-channels"
|
|
||||||
import { shippingOptions } from "./shipping-options"
|
|
||||||
import { shippingProfiles } from "./shipping-profiles"
|
|
||||||
import { stockLocations } from "./stock-locations"
|
import { stockLocations } from "./stock-locations"
|
||||||
import { stores } from "./stores"
|
|
||||||
import { tags } from "./tags"
|
|
||||||
import { users } from "./users"
|
|
||||||
import { workflowExecutions } from "./workflow-executions"
|
import { workflowExecutions } from "./workflow-executions"
|
||||||
|
|
||||||
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
||||||
@@ -26,21 +14,9 @@ export const client = {
|
|||||||
campaigns: campaigns,
|
campaigns: campaigns,
|
||||||
categories: categories,
|
categories: categories,
|
||||||
customerGroups: customerGroups,
|
customerGroups: customerGroups,
|
||||||
currencies: currencies,
|
|
||||||
promotions: promotions,
|
promotions: promotions,
|
||||||
payments: payments,
|
|
||||||
stores: stores,
|
|
||||||
salesChannels: salesChannels,
|
|
||||||
shippingOptions: shippingOptions,
|
|
||||||
shippingProfiles: shippingProfiles,
|
|
||||||
productTags: tags,
|
|
||||||
users: users,
|
|
||||||
invites: invites,
|
|
||||||
reservations: reservations,
|
reservations: reservations,
|
||||||
fulfillments: fulfillments,
|
|
||||||
fulfillmentProviders: fulfillmentProviders,
|
fulfillmentProviders: fulfillmentProviders,
|
||||||
productTypes: productTypes,
|
|
||||||
priceLists: priceLists,
|
|
||||||
stockLocations: stockLocations,
|
stockLocations: stockLocations,
|
||||||
workflowExecutions: workflowExecutions,
|
workflowExecutions: workflowExecutions,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import { CreateFulfillmentDTO } from "@medusajs/types"
|
|
||||||
|
|
||||||
import { FulfillmentRes } from "../../types/api-responses"
|
|
||||||
import { postRequest } from "./common"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a fulfillment.
|
|
||||||
* NOTE: to create a fulfillment on an order use orders/:id/fulfillments endpoint
|
|
||||||
*/
|
|
||||||
async function createFulfillment(payload: CreateFulfillmentDTO) {
|
|
||||||
return postRequest<FulfillmentRes>(`/admin/fulfillments`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancel a fulfillment.
|
|
||||||
* NOTE: to cancel a fulfillment on an order use orders/:id/fulfillments/:id/cancel endpoint
|
|
||||||
*/
|
|
||||||
async function cancelFulfillment(id: string) {
|
|
||||||
return postRequest<FulfillmentRes>(`/admin/fulfillments/${id}/cancel`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fulfillments = {
|
|
||||||
create: createFulfillment,
|
|
||||||
cancel: cancelFulfillment,
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { CreateInviteReq } from "../../types/api-payloads"
|
|
||||||
import {
|
|
||||||
InviteDeleteRes,
|
|
||||||
InviteListRes,
|
|
||||||
InviteRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrieveInvite(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<InviteRes, Record<string, any>>(
|
|
||||||
`/admin/invites/${id}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listInvites(query?: Record<string, any>) {
|
|
||||||
return getRequest<InviteListRes, Record<string, any>>(`/admin/invites`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createInvite(payload: CreateInviteReq) {
|
|
||||||
return postRequest<InviteRes>(`/admin/invites`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resendInvite(id: string) {
|
|
||||||
return postRequest<InviteRes>(`/admin/invites/${id}/resend`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteInvite(id: string) {
|
|
||||||
return deleteRequest<InviteDeleteRes>(`/admin/invites/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const invites = {
|
|
||||||
retrieve: retrieveInvite,
|
|
||||||
list: listInvites,
|
|
||||||
create: createInvite,
|
|
||||||
resend: resendInvite,
|
|
||||||
delete: deleteInvite,
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { PaymentProvidersListRes } from "../../types/api-responses"
|
|
||||||
import { getRequest } from "./common"
|
|
||||||
|
|
||||||
async function listPaymentProviders(query?: Record<string, any>) {
|
|
||||||
return getRequest<PaymentProvidersListRes, Record<string, any>>(
|
|
||||||
`/admin/payments/payment-providers`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const payments = {
|
|
||||||
listPaymentProviders,
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import {
|
|
||||||
AddPriceListPricesReq,
|
|
||||||
CreatePriceListReq,
|
|
||||||
DeletePriceListPricesReq,
|
|
||||||
UpdatePriceListReq,
|
|
||||||
} from "../../types/api-payloads"
|
|
||||||
import {
|
|
||||||
PriceListDeleteRes,
|
|
||||||
PriceListListRes,
|
|
||||||
PriceListRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
import { getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrievePriceLists(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<PriceListRes>(`/admin/price-lists/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listPriceLists(query?: Record<string, any>) {
|
|
||||||
return getRequest<PriceListListRes>(`/admin/price-lists`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createPriceList(payload: CreatePriceListReq) {
|
|
||||||
return postRequest<PriceListRes>(`/admin/price-lists`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updatePriceList(id: string, payload: UpdatePriceListReq) {
|
|
||||||
return postRequest<PriceListRes>(`/admin/price-lists/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deletePriceList(id: string) {
|
|
||||||
return postRequest<PriceListDeleteRes>(`/admin/price-lists/${id}/delete`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addPriceListPrices(id: string, payload: AddPriceListPricesReq) {
|
|
||||||
return postRequest<PriceListRes>(`/admin/price-lists/${id}/prices/batch`, {
|
|
||||||
create: payload.prices,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function removePriceListPrices(
|
|
||||||
id: string,
|
|
||||||
payload: DeletePriceListPricesReq
|
|
||||||
) {
|
|
||||||
return postRequest<PriceListRes>(`/admin/price-lists/${id}/prices/batch`, {
|
|
||||||
delete: payload.ids,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const priceLists = {
|
|
||||||
retrieve: retrievePriceLists,
|
|
||||||
list: listPriceLists,
|
|
||||||
create: createPriceList,
|
|
||||||
update: updatePriceList,
|
|
||||||
delete: deletePriceList,
|
|
||||||
addPrices: addPriceListPrices,
|
|
||||||
removePrices: removePriceListPrices,
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import { HttpTypes } from "@medusajs/types"
|
|
||||||
import { getRequest } from "./common"
|
|
||||||
|
|
||||||
async function listProductTypes(query?: Record<string, any>) {
|
|
||||||
return getRequest<{ product_types: HttpTypes.AdminProductType[] }>(
|
|
||||||
`/admin/product-types`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveProductType(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<{ product_type: HttpTypes.AdminProductType }>(
|
|
||||||
`/admin/product-types/${id}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const productTypes = {
|
|
||||||
list: listProductTypes,
|
|
||||||
retrieve: retrieveProductType,
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { getRequest } from "./common"
|
|
||||||
|
|
||||||
async function listProductTags(query?: Record<string, any>) {
|
|
||||||
return getRequest<any>(`/admin/product-tags`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveProductTag(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<any>(`/admin/product-tags/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const tags = {
|
|
||||||
list: listProductTags,
|
|
||||||
retrieve: retrieveProductTag,
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { UpdateUserReq } from "../../types/api-payloads"
|
|
||||||
import { UserDeleteRes, UserListRes, UserRes } from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function me() {
|
|
||||||
return getRequest<UserRes>("/admin/users/me")
|
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveUser(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<UserRes>(`/admin/users/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listUsers(query?: Record<string, any>) {
|
|
||||||
return getRequest<UserListRes>(`/admin/users`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateUser(id: string, payload: UpdateUserReq) {
|
|
||||||
return postRequest<UserRes>(`/admin/users/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteUser(id: string) {
|
|
||||||
return deleteRequest<UserDeleteRes>(`/admin/users/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const users = {
|
|
||||||
me,
|
|
||||||
retrieve: retrieveUser,
|
|
||||||
list: listUsers,
|
|
||||||
update: updateUser,
|
|
||||||
delete: deleteUser,
|
|
||||||
}
|
|
||||||
+3
-3
@@ -7,7 +7,7 @@ import { Form } from "../../../../../../../components/common/form"
|
|||||||
import { SwitchBox } from "../../../../../../../components/common/switch-box"
|
import { SwitchBox } from "../../../../../../../components/common/switch-box"
|
||||||
import { Combobox } from "../../../../../../../components/inputs/combobox"
|
import { Combobox } from "../../../../../../../components/inputs/combobox"
|
||||||
import { useComboboxData } from "../../../../../../../hooks/use-combobox-data"
|
import { useComboboxData } from "../../../../../../../hooks/use-combobox-data"
|
||||||
import { client, sdk } from "../../../../../../../lib/client"
|
import { sdk } from "../../../../../../../lib/client"
|
||||||
import { CategoryCombobox } from "../../../../../common/components/category-combobox"
|
import { CategoryCombobox } from "../../../../../common/components/category-combobox"
|
||||||
import { ProductCreateSchemaType } from "../../../../types"
|
import { ProductCreateSchemaType } from "../../../../types"
|
||||||
import { useProductCreateDetailsContext } from "../product-create-organize-context"
|
import { useProductCreateDetailsContext } from "../product-create-organize-context"
|
||||||
@@ -34,7 +34,7 @@ export const ProductCreateOrganizationSection = ({
|
|||||||
|
|
||||||
const types = useComboboxData({
|
const types = useComboboxData({
|
||||||
queryKey: ["product_types"],
|
queryKey: ["product_types"],
|
||||||
queryFn: client.productTypes.list,
|
queryFn: sdk.admin.productType.list,
|
||||||
getOptions: (data) =>
|
getOptions: (data) =>
|
||||||
data.product_types.map((type) => ({
|
data.product_types.map((type) => ({
|
||||||
label: type.value,
|
label: type.value,
|
||||||
@@ -44,7 +44,7 @@ export const ProductCreateOrganizationSection = ({
|
|||||||
|
|
||||||
const tags = useComboboxData({
|
const tags = useComboboxData({
|
||||||
queryKey: ["product_tags"],
|
queryKey: ["product_tags"],
|
||||||
queryFn: client.productTags.list,
|
queryFn: sdk.admin.productTag.list,
|
||||||
getOptions: (data) =>
|
getOptions: (data) =>
|
||||||
data.product_tags.map((tag) => ({
|
data.product_tags.map((tag) => ({
|
||||||
label: tag.value,
|
label: tag.value,
|
||||||
|
|||||||
+2
-2
@@ -41,7 +41,7 @@ export const ProductOrganizationForm = ({
|
|||||||
|
|
||||||
const types = useComboboxData({
|
const types = useComboboxData({
|
||||||
queryKey: ["product_types"],
|
queryKey: ["product_types"],
|
||||||
queryFn: client.productTypes.list,
|
queryFn: sdk.admin.productType.list,
|
||||||
getOptions: (data) =>
|
getOptions: (data) =>
|
||||||
data.product_types.map((type) => ({
|
data.product_types.map((type) => ({
|
||||||
label: type.value,
|
label: type.value,
|
||||||
@@ -51,7 +51,7 @@ export const ProductOrganizationForm = ({
|
|||||||
|
|
||||||
const tags = useComboboxData({
|
const tags = useComboboxData({
|
||||||
queryKey: ["product_tags"],
|
queryKey: ["product_tags"],
|
||||||
queryFn: client.productTags.list,
|
queryFn: sdk.admin.productTag.list,
|
||||||
getOptions: (data) =>
|
getOptions: (data) =>
|
||||||
data.product_tags.map((tag) => ({
|
data.product_tags.map((tag) => ({
|
||||||
label: tag.value,
|
label: tag.value,
|
||||||
|
|||||||
+2
-7
@@ -104,18 +104,13 @@ export const AddProductsToSalesChannelForm = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleSubmit = form.handleSubmit(async (values) => {
|
const handleSubmit = form.handleSubmit(async (values) => {
|
||||||
await mutateAsync(
|
await mutateAsync(values.product_ids, {
|
||||||
{
|
|
||||||
product_ids: values.product_ids,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t("salesChannels.toast.update"))
|
toast.success(t("salesChannels.toast.update"))
|
||||||
handleSuccess()
|
handleSuccess()
|
||||||
},
|
},
|
||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
|
|||||||
+4
-14
@@ -93,11 +93,7 @@ export const SalesChannelProductSection = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await mutateAsync(
|
await mutateAsync(ids, {
|
||||||
{
|
|
||||||
product_ids: ids,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t("salesChannels.toast.update"))
|
toast.success(t("salesChannels.toast.update"))
|
||||||
setRowSelection({})
|
setRowSelection({})
|
||||||
@@ -105,8 +101,7 @@ export const SalesChannelProductSection = ({
|
|||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
@@ -218,19 +213,14 @@ const ProductListCellActions = ({
|
|||||||
const { mutateAsync } = useSalesChannelRemoveProducts(salesChannelId)
|
const { mutateAsync } = useSalesChannelRemoveProducts(salesChannelId)
|
||||||
|
|
||||||
const onRemove = async () => {
|
const onRemove = async () => {
|
||||||
await mutateAsync(
|
await mutateAsync([productId], {
|
||||||
{
|
|
||||||
product_ids: [productId],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t("salesChannels.toast.update"))
|
toast.success(t("salesChannels.toast.update"))
|
||||||
},
|
},
|
||||||
onError: (e) => {
|
onError: (e) => {
|
||||||
toast.error(e.message)
|
toast.error(e.message)
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+2
-2
@@ -2,12 +2,12 @@ import { LoaderFunctionArgs } from "react-router-dom"
|
|||||||
|
|
||||||
import { AdminSalesChannelResponse } from "@medusajs/types"
|
import { AdminSalesChannelResponse } from "@medusajs/types"
|
||||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const salesChannelDetailQuery = (id: string) => ({
|
const salesChannelDetailQuery = (id: string) => ({
|
||||||
queryKey: productsQueryKeys.detail(id),
|
queryKey: productsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.salesChannels.retrieve(id),
|
queryFn: async () => sdk.admin.salesChannel.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const salesChannelLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const salesChannelLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
|
|
||||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
import { UserRes } from "../../../types/api-responses"
|
import { UserRes } from "../../../types/api-responses"
|
||||||
|
|
||||||
const userDetailQuery = (id: string) => ({
|
const userDetailQuery = (id: string) => ({
|
||||||
queryKey: productsQueryKeys.detail(id),
|
queryKey: productsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.users.retrieve(id),
|
queryFn: async () => sdk.admin.user.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const userLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const userLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
@@ -18,6 +18,19 @@ export class Payment {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async listPaymentProviders(
|
||||||
|
query?: HttpTypes.AdminGetPaymentProvidersParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPaymentProviderListResponse>(
|
||||||
|
`/admin/payments/payment-providers`,
|
||||||
|
{
|
||||||
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async retrieve(
|
async retrieve(
|
||||||
id: string,
|
id: string,
|
||||||
query?: HttpTypes.AdminPaymentFilters,
|
query?: HttpTypes.AdminPaymentFilters,
|
||||||
|
|||||||
@@ -94,4 +94,19 @@ export class SalesChannel {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async batchProducts(
|
||||||
|
id: string,
|
||||||
|
body: HttpTypes.AdminBatchLink,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminSalesChannelResponse>(
|
||||||
|
`/admin/sales-channels/${id}/products`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { BaseFilterable } from "../../../dal"
|
import { BaseFilterable } from "../../../dal"
|
||||||
|
import { FindParams } from "../../common"
|
||||||
import {
|
import {
|
||||||
BasePaymentCollectionFilters,
|
BasePaymentCollectionFilters,
|
||||||
BasePaymentFilters,
|
BasePaymentFilters,
|
||||||
@@ -23,3 +24,12 @@ export interface RefundFilters extends BaseFilterable<AdminRefund> {
|
|||||||
export interface RefundReasonFilters extends BaseFilterable<AdminRefundReason> {
|
export interface RefundReasonFilters extends BaseFilterable<AdminRefundReason> {
|
||||||
id?: string | string[]
|
id?: string | string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AdminGetPaymentProvidersParams
|
||||||
|
extends FindParams,
|
||||||
|
BaseFilterable<AdminGetPaymentProvidersParams> {
|
||||||
|
id?: string | string[]
|
||||||
|
is_enabled?: boolean
|
||||||
|
$and?: AdminGetPaymentProvidersParams[]
|
||||||
|
$or?: AdminGetPaymentProvidersParams[]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user