Skip to content

Commit

Permalink
chore: Remove unused clients in admin + clean up js-sdk (#8839)
Browse files Browse the repository at this point in the history
* feat(js-sdk): Add API key

* chore: Remove unused clients in admin + clean up js-sdk

* fix sales channel hooks
  • Loading branch information
olivermrbl authored Aug 28, 2024
1 parent 5294ce8 commit 37b7592
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 300 deletions.
4 changes: 2 additions & 2 deletions packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useCreateFulfillment = (
options?: UseMutationOptions<any, Error, any>
) => {
return useMutation({
mutationFn: (payload: any) => client.fulfillments.create(payload),
mutationFn: (payload: any) => sdk.admin.fulfillment.create(payload),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
queryClient.invalidateQueries({
Expand All @@ -31,7 +31,7 @@ export const useCancelFulfillment = (
options?: UseMutationOptions<any, Error, any>
) => {
return useMutation({
mutationFn: () => client.fulfillments.cancel(id),
mutationFn: () => sdk.admin.fulfillment.cancel(id),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
queryClient.invalidateQueries({
Expand Down
11 changes: 5 additions & 6 deletions packages/admin-next/dashboard/src/hooks/api/payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@ import {
useQuery,
UseQueryOptions,
} from "@tanstack/react-query"
import { client, sdk } from "../../lib/client"
import { sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { PaymentProvidersListRes } from "../../types/api-responses"
import { ordersQueryKeys } from "./orders"

const PAYMENT_QUERY_KEY = "payment" as const
export const paymentQueryKeys = queryKeysFactory(PAYMENT_QUERY_KEY)

export const usePaymentProviders = (
query?: Record<string, any>,
query?: HttpTypes.AdminGetPaymentProvidersParams,
options?: Omit<
UseQueryOptions<
PaymentProvidersListRes,
HttpTypes.AdminGetPaymentProvidersParams,
Error,
PaymentProvidersListRes,
HttpTypes.AdminPaymentProviderListResponse,
QueryKey
>,
"queryKey" | "queryFn"
>
) => {
const { data, ...rest } = useQuery({
queryFn: async () => client.payments.listPaymentProviders(query),
queryFn: async () => sdk.admin.payment.listPaymentProviders(query),
queryKey: [],
...options,
})
Expand Down
45 changes: 22 additions & 23 deletions packages/admin-next/dashboard/src/hooks/api/sales-channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ import {
useMutation,
useQuery,
} from "@tanstack/react-query"

import {
AdminSalesChannelListResponse,
AdminSalesChannelResponse,
HttpTypes,
} from "@medusajs/types"
import { client } from "../../lib/client"
import { sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
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"

const SALES_CHANNELS_QUERY_KEY = "sales-channels" as const
Expand All @@ -39,7 +32,7 @@ export const useSalesChannel = (
) => {
const { data, ...rest } = useQuery({
queryKey: salesChannelsQueryKeys.detail(id),
queryFn: async () => client.salesChannels.retrieve(id),
queryFn: async () => sdk.admin.salesChannel.retrieve(id),
...options,
})

Expand All @@ -59,7 +52,7 @@ export const useSalesChannels = (
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.salesChannels.list(query),
queryFn: () => sdk.admin.salesChannel.list(query),
queryKey: salesChannelsQueryKeys.list(query),
...options,
})
Expand All @@ -71,11 +64,11 @@ export const useCreateSalesChannel = (
options?: UseMutationOptions<
AdminSalesChannelResponse,
Error,
CreateSalesChannelReq
HttpTypes.AdminCreateSalesChannel
>
) => {
return useMutation({
mutationFn: (payload) => client.salesChannels.create(payload),
mutationFn: (payload) => sdk.admin.salesChannel.create(payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.lists(),
Expand All @@ -91,11 +84,11 @@ export const useUpdateSalesChannel = (
options?: UseMutationOptions<
AdminSalesChannelResponse,
Error,
UpdateSalesChannelReq
HttpTypes.AdminUpdateSalesChannel
>
) => {
return useMutation({
mutationFn: (payload) => client.salesChannels.update(id, payload),
mutationFn: (payload) => sdk.admin.salesChannel.update(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.lists(),
Expand All @@ -112,10 +105,14 @@ export const useUpdateSalesChannel = (

export const useDeleteSalesChannel = (
id: string,
options?: UseMutationOptions<SalesChannelDeleteRes, Error, void>
options?: UseMutationOptions<
HttpTypes.AdminSalesChannelDeleteResponse,
Error,
void
>
) => {
return useMutation({
mutationFn: () => client.salesChannels.delete(id),
mutationFn: () => sdk.admin.salesChannel.delete(id),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.lists(),
Expand All @@ -140,11 +137,12 @@ export const useSalesChannelRemoveProducts = (
options?: UseMutationOptions<
AdminSalesChannelResponse,
Error,
RemoveProductsSalesChannelReq
HttpTypes.AdminBatchLink["remove"]
>
) => {
return useMutation({
mutationFn: (payload) => client.salesChannels.removeProducts(id, payload),
mutationFn: (payload) =>
sdk.admin.salesChannel.batchProducts(id, { remove: payload }),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.lists(),
Expand All @@ -154,7 +152,7 @@ export const useSalesChannelRemoveProducts = (
})

// Invalidate the products that were removed
for (const product of variables?.product_ids || []) {
for (const product of variables || []) {
queryClient.invalidateQueries({
queryKey: productsQueryKeys.detail(product),
})
Expand All @@ -176,11 +174,12 @@ export const useSalesChannelAddProducts = (
options?: UseMutationOptions<
AdminSalesChannelResponse,
Error,
AddProductsSalesChannelReq
HttpTypes.AdminBatchLink["add"]
>
) => {
return useMutation({
mutationFn: (payload) => client.salesChannels.addProducts(id, payload),
mutationFn: (payload) =>
sdk.admin.salesChannel.batchProducts(id, { add: payload }),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.lists(),
Expand All @@ -190,7 +189,7 @@ export const useSalesChannelAddProducts = (
})

// Invalidate the products that were removed
for (const product of variables?.product_ids || []) {
for (const product of variables || []) {
queryClient.invalidateQueries({
queryKey: productsQueryKeys.detail(product),
})
Expand Down
24 changes: 0 additions & 24 deletions packages/admin-next/dashboard/src/lib/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import Medusa from "@medusajs/js-sdk"
import { campaigns } from "./campaigns"
import { categories } from "./categories"
import { currencies } from "./currencies"
import { customerGroups } from "./customer-groups"
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 { reservations } from "./reservations"
import { salesChannels } from "./sales-channels"
import { shippingOptions } from "./shipping-options"
import { shippingProfiles } from "./shipping-profiles"
import { stockLocations } from "./stock-locations"
import { stores } from "./stores"
import { tags } from "./tags"
import { users } from "./users"
import { workflowExecutions } from "./workflow-executions"

export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
Expand All @@ -26,21 +14,9 @@ export const client = {
campaigns: campaigns,
categories: categories,
customerGroups: customerGroups,
currencies: currencies,
promotions: promotions,
payments: payments,
stores: stores,
salesChannels: salesChannels,
shippingOptions: shippingOptions,
shippingProfiles: shippingProfiles,
productTags: tags,
users: users,
invites: invites,
reservations: reservations,
fulfillments: fulfillments,
fulfillmentProviders: fulfillmentProviders,
productTypes: productTypes,
priceLists: priceLists,
stockLocations: stockLocations,
workflowExecutions: workflowExecutions,
}
Expand Down
25 changes: 0 additions & 25 deletions packages/admin-next/dashboard/src/lib/client/fulfillments.ts

This file was deleted.

38 changes: 0 additions & 38 deletions packages/admin-next/dashboard/src/lib/client/invites.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/admin-next/dashboard/src/lib/client/payments.ts

This file was deleted.

57 changes: 0 additions & 57 deletions packages/admin-next/dashboard/src/lib/client/price-lists.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/admin-next/dashboard/src/lib/client/product-types.ts

This file was deleted.

Loading

0 comments on commit 37b7592

Please sign in to comment.