chore: Remove last trace of client in dashboard (#8873)
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { useCustomer } from "../../../hooks/api/customers"
|
import { useCustomer } from "../../../hooks/api/customers"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { getStylizedAmount } from "../../../lib/money-amount-helpers"
|
import { getStylizedAmount } from "../../../lib/money-amount-helpers"
|
||||||
import {
|
import {
|
||||||
getOrderFulfillmentStatus,
|
getOrderFulfillmentStatus,
|
||||||
@@ -74,7 +74,7 @@ export const TransferOwnerShipForm = ({
|
|||||||
const { data, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
|
const { data, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
|
||||||
queryKey: ["customers", debouncedQuery],
|
queryKey: ["customers", debouncedQuery],
|
||||||
queryFn: async ({ pageParam = 0 }) => {
|
queryFn: async ({ pageParam = 0 }) => {
|
||||||
const res = await client.customers.list({
|
const res = await sdk.admin.customer.list({
|
||||||
q: debouncedQuery,
|
q: debouncedQuery,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
offset: pageParam,
|
offset: pageParam,
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
import {
|
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||||
AdminCampaignListResponse,
|
|
||||||
AdminCampaignResponse,
|
|
||||||
AdminCreateCampaign,
|
|
||||||
AdminUpdateCampaign,
|
|
||||||
LinkMethodRequest,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
@@ -12,23 +6,23 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
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 { CampaignDeleteRes } from "../../types/api-responses"
|
|
||||||
import { promotionsQueryKeys } from "./promotions"
|
import { promotionsQueryKeys } from "./promotions"
|
||||||
|
import { FetchError } from "@medusajs/js-sdk"
|
||||||
|
|
||||||
const REGIONS_QUERY_KEY = "campaigns" as const
|
const REGIONS_QUERY_KEY = "campaigns" as const
|
||||||
export const campaignsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
export const campaignsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
||||||
|
|
||||||
export const useCampaign = (
|
export const useCampaign = (
|
||||||
id: string,
|
id: string,
|
||||||
query?: Record<string, any>,
|
query?: HttpTypes.AdminGetCampaignParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCampaignResponse,
|
HttpTypes.AdminCampaignResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminCampaignResponse,
|
HttpTypes.AdminCampaignResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -36,7 +30,7 @@ export const useCampaign = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: campaignsQueryKeys.detail(id),
|
queryKey: campaignsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.campaigns.retrieve(id, query),
|
queryFn: async () => sdk.admin.campaign.retrieve(id, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -44,19 +38,19 @@ export const useCampaign = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useCampaigns = (
|
export const useCampaigns = (
|
||||||
query?: Record<string, any>,
|
query?: HttpTypes.AdminGetCampaignsParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCampaignListResponse,
|
HttpTypes.AdminCampaignListResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminCampaignListResponse,
|
HttpTypes.AdminCampaignListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.campaigns.list(query),
|
queryFn: () => sdk.admin.campaign.list(query),
|
||||||
queryKey: campaignsQueryKeys.list(query),
|
queryKey: campaignsQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -66,13 +60,13 @@ export const useCampaigns = (
|
|||||||
|
|
||||||
export const useCreateCampaign = (
|
export const useCreateCampaign = (
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCampaignResponse,
|
HttpTypes.AdminCampaignResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminCreateCampaign
|
HttpTypes.AdminCreateCampaign
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.campaigns.create(payload),
|
mutationFn: (payload) => sdk.admin.campaign.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
@@ -84,13 +78,13 @@ export const useCreateCampaign = (
|
|||||||
export const useUpdateCampaign = (
|
export const useUpdateCampaign = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCampaignResponse,
|
HttpTypes.AdminCampaignResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminUpdateCampaign
|
HttpTypes.AdminUpdateCampaign
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.campaigns.update(id, payload),
|
mutationFn: (payload) => sdk.admin.campaign.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||||
@@ -103,10 +97,14 @@ export const useUpdateCampaign = (
|
|||||||
|
|
||||||
export const useDeleteCampaign = (
|
export const useDeleteCampaign = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<CampaignDeleteRes, Error, void>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.DeleteResponse<"campaign">,
|
||||||
|
FetchError,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.campaigns.delete(id),
|
mutationFn: () => sdk.admin.campaign.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||||
@@ -119,11 +117,14 @@ export const useDeleteCampaign = (
|
|||||||
|
|
||||||
export const useAddOrRemoveCampaignPromotions = (
|
export const useAddOrRemoveCampaignPromotions = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<AdminCampaignResponse, Error, LinkMethodRequest>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminCampaignResponse,
|
||||||
|
FetchError,
|
||||||
|
LinkMethodRequest
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) =>
|
mutationFn: (payload) => sdk.admin.campaign.batchPromotions(id, payload),
|
||||||
client.campaigns.addOrRemovePromotions(id, payload),
|
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { AdminGetPromotionsParams } from "@medusajs/medusa"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import { FetchError } from "@medusajs/js-sdk"
|
||||||
AdminPromotionRuleListResponse,
|
|
||||||
AdminRuleAttributeOptionsListResponse,
|
|
||||||
AdminRuleValueOptionsListResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
useMutation,
|
useMutation,
|
||||||
@@ -11,21 +7,9 @@ import {
|
|||||||
useQuery,
|
useQuery,
|
||||||
UseQueryOptions,
|
UseQueryOptions,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
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 {
|
|
||||||
BatchAddPromotionRulesReq,
|
|
||||||
BatchRemovePromotionRulesReq,
|
|
||||||
BatchUpdatePromotionRulesReq,
|
|
||||||
CreatePromotionReq,
|
|
||||||
UpdatePromotionReq,
|
|
||||||
} from "../../types/api-payloads"
|
|
||||||
import {
|
|
||||||
PromotionDeleteRes,
|
|
||||||
PromotionListRes,
|
|
||||||
PromotionRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
import { campaignsQueryKeys } from "./campaigns"
|
import { campaignsQueryKeys } from "./campaigns"
|
||||||
|
|
||||||
const PROMOTIONS_QUERY_KEY = "promotions" as const
|
const PROMOTIONS_QUERY_KEY = "promotions" as const
|
||||||
@@ -35,31 +19,35 @@ export const promotionsQueryKeys = {
|
|||||||
listRules: (
|
listRules: (
|
||||||
id: string | null,
|
id: string | null,
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
query?: Record<string, string>
|
query?: HttpTypes.AdminGetPromotionRuleParams
|
||||||
) => [PROMOTIONS_QUERY_KEY, id, ruleType, query],
|
) => [PROMOTIONS_QUERY_KEY, id, ruleType, query],
|
||||||
listRuleAttributes: (ruleType: string, promotionType?: string) => [
|
listRuleAttributes: (ruleType: string, promotionType?: string) => [
|
||||||
PROMOTIONS_QUERY_KEY,
|
PROMOTIONS_QUERY_KEY,
|
||||||
ruleType,
|
ruleType,
|
||||||
promotionType,
|
promotionType,
|
||||||
],
|
],
|
||||||
listRuleValues: (ruleType: string, ruleValue: string, query: object) => [
|
listRuleValues: (
|
||||||
PROMOTIONS_QUERY_KEY,
|
ruleType: string,
|
||||||
ruleType,
|
ruleValue: string,
|
||||||
ruleValue,
|
query: HttpTypes.AdminGetPromotionsRuleValueParams
|
||||||
query,
|
) => [PROMOTIONS_QUERY_KEY, ruleType, ruleValue, query],
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usePromotion = (
|
export const usePromotion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<PromotionRes, Error, PromotionRes, QueryKey>,
|
UseQueryOptions<
|
||||||
|
HttpTypes.AdminPromotionResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminPromotionResponse,
|
||||||
|
QueryKey
|
||||||
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: promotionsQueryKeys.detail(id),
|
queryKey: promotionsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.promotions.retrieve(id),
|
queryFn: async () => sdk.admin.promotion.retrieve(id),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -69,12 +57,12 @@ export const usePromotion = (
|
|||||||
export const usePromotionRules = (
|
export const usePromotionRules = (
|
||||||
id: string | null,
|
id: string | null,
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
query?: Record<string, string>,
|
query?: HttpTypes.AdminGetPromotionRuleParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminPromotionRuleListResponse,
|
HttpTypes.AdminGetPromotionRuleParams,
|
||||||
Error,
|
FetchError,
|
||||||
AdminPromotionRuleListResponse,
|
HttpTypes.AdminPromotionRuleListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -82,7 +70,7 @@ export const usePromotionRules = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: promotionsQueryKeys.listRules(id, ruleType, query),
|
queryKey: promotionsQueryKeys.listRules(id, ruleType, query),
|
||||||
queryFn: async () => client.promotions.listRules(id, ruleType, query),
|
queryFn: async () => sdk.admin.promotion.listRules(id, ruleType, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -90,15 +78,20 @@ export const usePromotionRules = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const usePromotions = (
|
export const usePromotions = (
|
||||||
query?: AdminGetPromotionsParams,
|
query?: HttpTypes.AdminGetPromotionsParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<PromotionListRes, Error, PromotionListRes, QueryKey>,
|
UseQueryOptions<
|
||||||
|
HttpTypes.AdminPromotionListResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminPromotionListResponse,
|
||||||
|
QueryKey
|
||||||
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: promotionsQueryKeys.list(query),
|
queryKey: promotionsQueryKeys.list(query),
|
||||||
queryFn: async () => client.promotions.list(query),
|
queryFn: async () => sdk.admin.promotion.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,9 +103,9 @@ export const usePromotionRuleAttributes = (
|
|||||||
promotionType?: string,
|
promotionType?: string,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminRuleAttributeOptionsListResponse,
|
HttpTypes.AdminRuleAttributeOptionsListResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminRuleAttributeOptionsListResponse,
|
HttpTypes.AdminRuleAttributeOptionsListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -121,7 +114,7 @@ export const usePromotionRuleAttributes = (
|
|||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: promotionsQueryKeys.listRuleAttributes(ruleType, promotionType),
|
queryKey: promotionsQueryKeys.listRuleAttributes(ruleType, promotionType),
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
client.promotions.listRuleAttributes(ruleType, promotionType),
|
sdk.admin.promotion.listRuleAttributes(ruleType, promotionType),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -131,12 +124,12 @@ export const usePromotionRuleAttributes = (
|
|||||||
export const usePromotionRuleValues = (
|
export const usePromotionRuleValues = (
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
ruleValue: string,
|
ruleValue: string,
|
||||||
query?: Record<string, any>,
|
query?: HttpTypes.AdminGetPromotionsRuleValueParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminRuleValueOptionsListResponse,
|
HttpTypes.AdminRuleValueOptionsListResponse,
|
||||||
Error,
|
FetchError,
|
||||||
AdminRuleValueOptionsListResponse,
|
HttpTypes.AdminRuleValueOptionsListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -149,7 +142,7 @@ export const usePromotionRuleValues = (
|
|||||||
query || {}
|
query || {}
|
||||||
),
|
),
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
client.promotions.listRuleValues(ruleType, ruleValue, query),
|
sdk.admin.promotion.listRuleValues(ruleType, ruleValue, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -158,10 +151,14 @@ export const usePromotionRuleValues = (
|
|||||||
|
|
||||||
export const useDeletePromotion = (
|
export const useDeletePromotion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<PromotionDeleteRes, Error, void>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.DeleteResponse<"promotion">,
|
||||||
|
FetchError,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.promotions.delete(id),
|
mutationFn: () => sdk.admin.promotion.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -175,10 +172,14 @@ export const useDeletePromotion = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useCreatePromotion = (
|
export const useCreatePromotion = (
|
||||||
options?: UseMutationOptions<PromotionRes, Error, CreatePromotionReq>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminPromotionResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminCreatePromotion
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.promotions.create(payload),
|
mutationFn: (payload) => sdk.admin.promotion.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||||
@@ -190,10 +191,14 @@ export const useCreatePromotion = (
|
|||||||
|
|
||||||
export const useUpdatePromotion = (
|
export const useUpdatePromotion = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<PromotionRes, Error, UpdatePromotionReq>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminPromotionResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminUpdatePromotion
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.promotions.update(id, payload),
|
mutationFn: (payload) => sdk.admin.promotion.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||||
|
|
||||||
@@ -206,10 +211,15 @@ export const useUpdatePromotion = (
|
|||||||
export const usePromotionAddRules = (
|
export const usePromotionAddRules = (
|
||||||
id: string,
|
id: string,
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
options?: UseMutationOptions<PromotionRes, Error, BatchAddPromotionRulesReq>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminPromotionResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.BatchAddPromotionRulesReq
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.promotions.addRules(id, ruleType, payload),
|
mutationFn: (payload) =>
|
||||||
|
sdk.admin.promotion.addRules(id, ruleType, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||||
|
|
||||||
@@ -223,14 +233,14 @@ export const usePromotionRemoveRules = (
|
|||||||
id: string,
|
id: string,
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
PromotionRes,
|
HttpTypes.AdminPromotionResponse,
|
||||||
Error,
|
FetchError,
|
||||||
BatchRemovePromotionRulesReq
|
HttpTypes.BatchRemovePromotionRulesReq
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) =>
|
mutationFn: (payload) =>
|
||||||
client.promotions.removeRules(id, ruleType, payload),
|
sdk.admin.promotion.removeRules(id, ruleType, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||||
|
|
||||||
@@ -244,14 +254,14 @@ export const usePromotionUpdateRules = (
|
|||||||
id: string,
|
id: string,
|
||||||
ruleType: string,
|
ruleType: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
PromotionRes,
|
HttpTypes.AdminPromotionResponse,
|
||||||
Error,
|
FetchError,
|
||||||
BatchUpdatePromotionRulesReq
|
HttpTypes.BatchUpdatePromotionRulesReq
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) =>
|
mutationFn: (payload) =>
|
||||||
client.promotions.updateRules(id, ruleType, payload),
|
sdk.admin.promotion.updateRules(id, ruleType, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
import {
|
|
||||||
AdminCampaignListResponse,
|
|
||||||
AdminCampaignResponse,
|
|
||||||
AdminCreateCampaign,
|
|
||||||
AdminUpdateCampaign,
|
|
||||||
LinkMethodRequest,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { CampaignDeleteRes } from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrieveCampaign(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminCampaignResponse>(`/admin/campaigns/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listCampaigns(query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminCampaignListResponse>(`/admin/campaigns`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createCampaign(payload: AdminCreateCampaign) {
|
|
||||||
return postRequest<AdminCampaignResponse>(`/admin/campaigns`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateCampaign(id: string, payload: AdminUpdateCampaign) {
|
|
||||||
return postRequest<AdminCampaignResponse>(`/admin/campaigns/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteCampaign(id: string) {
|
|
||||||
return deleteRequest<CampaignDeleteRes>(`/admin/campaigns/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addOrRemoveCampaignPromotions(
|
|
||||||
id: string,
|
|
||||||
payload: LinkMethodRequest
|
|
||||||
) {
|
|
||||||
return postRequest<AdminCampaignResponse>(
|
|
||||||
`/admin/campaigns/${id}/promotions`,
|
|
||||||
payload
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const campaigns = {
|
|
||||||
retrieve: retrieveCampaign,
|
|
||||||
list: listCampaigns,
|
|
||||||
create: createCampaign,
|
|
||||||
update: updateCampaign,
|
|
||||||
delete: deleteCampaign,
|
|
||||||
addOrRemovePromotions: addOrRemoveCampaignPromotions,
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import {
|
|
||||||
AdminProductCategoryListResponse,
|
|
||||||
AdminProductCategoryResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { getRequest } from "./common"
|
|
||||||
|
|
||||||
async function listProductCategories(query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminProductCategoryListResponse>(
|
|
||||||
`/admin/product-categories`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveProductCategory(
|
|
||||||
id: string,
|
|
||||||
query?: Record<string, any>
|
|
||||||
) {
|
|
||||||
return getRequest<AdminProductCategoryResponse>(
|
|
||||||
`/admin/product-categories/${id}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const categories = {
|
|
||||||
list: listProductCategories,
|
|
||||||
retrieve: retrieveProductCategory,
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
import Medusa from "@medusajs/js-sdk"
|
||||||
import { campaigns } from "./campaigns"
|
|
||||||
import { categories } from "./categories"
|
|
||||||
import { promotions } from "./promotions"
|
|
||||||
|
|
||||||
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
||||||
|
|
||||||
export const client = {
|
|
||||||
campaigns: campaigns,
|
|
||||||
categories: categories,
|
|
||||||
promotions: promotions,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const sdk = new Medusa({
|
export const sdk = new Medusa({
|
||||||
baseUrl: backendUrl,
|
baseUrl: backendUrl,
|
||||||
auth: {
|
auth: {
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
import { stringify } from "qs"
|
|
||||||
|
|
||||||
const baseUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
|
||||||
|
|
||||||
const commonHeaders: HeadersInit = {
|
|
||||||
Accept: "application/json",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUrl(path: string, query?: Record<string, any>) {
|
|
||||||
const params = query ? stringify(query) : null
|
|
||||||
|
|
||||||
return `${baseUrl}${path}${params ? `?${params}` : ""}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBody(payload?: Record<string, any>) {
|
|
||||||
return payload ? JSON.stringify(payload) : undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOptions(
|
|
||||||
options?: Omit<RequestInit, "body">,
|
|
||||||
payload?: Record<string, any>
|
|
||||||
): RequestInit {
|
|
||||||
const body = getBody(payload)
|
|
||||||
|
|
||||||
return {
|
|
||||||
...options,
|
|
||||||
headers: {
|
|
||||||
...commonHeaders,
|
|
||||||
...options?.headers,
|
|
||||||
},
|
|
||||||
body,
|
|
||||||
credentials: "include",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function makeRequest<
|
|
||||||
TRes,
|
|
||||||
TPayload extends Record<string, any> | undefined,
|
|
||||||
TQuery extends Record<string, any> | undefined = undefined,
|
|
||||||
>(
|
|
||||||
path: string,
|
|
||||||
payload?: TPayload,
|
|
||||||
query?: TQuery,
|
|
||||||
options?: Omit<RequestInit, "body">
|
|
||||||
): Promise<TRes> {
|
|
||||||
const url = getUrl(path, query)
|
|
||||||
const requestOptions = getOptions(options, payload)
|
|
||||||
|
|
||||||
const response = await fetch(url, requestOptions)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json()
|
|
||||||
|
|
||||||
// Temp: Add a better error type
|
|
||||||
throw new Error(`API error ${response.status}: ${errorData.message}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json()
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getRequest<
|
|
||||||
TRes,
|
|
||||||
TQuery extends Record<string, any> | undefined = {},
|
|
||||||
>(
|
|
||||||
path: string,
|
|
||||||
query?: TQuery,
|
|
||||||
options?: Omit<RequestInit, "body" | "method">
|
|
||||||
): Promise<TRes> {
|
|
||||||
return makeRequest<TRes, undefined, Record<string, any>>(
|
|
||||||
path,
|
|
||||||
undefined,
|
|
||||||
query,
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
method: "GET",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function postRequest<
|
|
||||||
TRes,
|
|
||||||
TPayload extends Record<string, any> | undefined = {},
|
|
||||||
>(
|
|
||||||
path: string,
|
|
||||||
payload?: TPayload,
|
|
||||||
options?: Omit<RequestInit, "body" | "method">
|
|
||||||
): Promise<TRes> {
|
|
||||||
return makeRequest<TRes, Record<string, any>, undefined>(
|
|
||||||
path,
|
|
||||||
payload,
|
|
||||||
undefined,
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
method: "POST",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteRequest<TRes>(
|
|
||||||
path: string,
|
|
||||||
options?: Omit<RequestInit, "body" | "method">
|
|
||||||
): Promise<TRes> {
|
|
||||||
return makeRequest<TRes, undefined, undefined>(path, undefined, undefined, {
|
|
||||||
...options,
|
|
||||||
method: "DELETE",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
import {
|
|
||||||
AdminGetPromotionsParams,
|
|
||||||
AdminGetPromotionsRuleValueParams,
|
|
||||||
} from "@medusajs/medusa"
|
|
||||||
import { AdminRuleValueOptionsListResponse } from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
BatchAddPromotionRulesReq,
|
|
||||||
BatchRemovePromotionRulesReq,
|
|
||||||
BatchUpdatePromotionRulesReq,
|
|
||||||
CreatePromotionReq,
|
|
||||||
UpdatePromotionReq,
|
|
||||||
} from "../../types/api-payloads"
|
|
||||||
import {
|
|
||||||
PromotionDeleteRes,
|
|
||||||
PromotionListRes,
|
|
||||||
PromotionRes,
|
|
||||||
PromotionRuleAttributesListRes,
|
|
||||||
} from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrievePromotion(id: string, query?: AdminGetPromotionsParams) {
|
|
||||||
return getRequest<PromotionRes, AdminGetPromotionsParams>(
|
|
||||||
`/admin/promotions/${id}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listPromotions(query?: AdminGetPromotionsParams) {
|
|
||||||
return getRequest<PromotionListRes>(`/admin/promotions`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deletePromotion(id: string) {
|
|
||||||
return deleteRequest<PromotionDeleteRes>(`/admin/promotions/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updatePromotion(id: string, payload: UpdatePromotionReq) {
|
|
||||||
return postRequest<PromotionRes>(`/admin/promotions/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createPromotion(payload: CreatePromotionReq) {
|
|
||||||
return postRequest<PromotionRes>(`/admin/promotions`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addPromotionRules(
|
|
||||||
id: string,
|
|
||||||
ruleType: string,
|
|
||||||
payload: BatchAddPromotionRulesReq
|
|
||||||
) {
|
|
||||||
return postRequest<PromotionRes>(
|
|
||||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
|
||||||
{
|
|
||||||
create: payload.rules,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updatePromotionRules(
|
|
||||||
id: string,
|
|
||||||
ruleType: string,
|
|
||||||
payload: BatchUpdatePromotionRulesReq
|
|
||||||
) {
|
|
||||||
return postRequest<PromotionRes>(
|
|
||||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
|
||||||
{
|
|
||||||
update: payload.rules,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function removePromotionRules(
|
|
||||||
id: string,
|
|
||||||
ruleType: string,
|
|
||||||
payload: BatchRemovePromotionRulesReq
|
|
||||||
) {
|
|
||||||
return postRequest<PromotionRes>(
|
|
||||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
|
||||||
{
|
|
||||||
delete: payload.rule_ids,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listPromotionRules(
|
|
||||||
id: string | null,
|
|
||||||
ruleType: string,
|
|
||||||
query?: Record<string, string>
|
|
||||||
) {
|
|
||||||
return getRequest<PromotionRuleAttributesListRes>(
|
|
||||||
`/admin/promotions/${id}/${ruleType}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listPromotionRuleAttributes(
|
|
||||||
ruleType: string,
|
|
||||||
promotionType?: string
|
|
||||||
) {
|
|
||||||
return getRequest<PromotionRuleAttributesListRes>(
|
|
||||||
`/admin/promotions/rule-attribute-options/${ruleType}?promotion_type=${promotionType}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listPromotionRuleValues(
|
|
||||||
ruleType: string,
|
|
||||||
ruleValue: string,
|
|
||||||
query?: AdminGetPromotionsRuleValueParams
|
|
||||||
) {
|
|
||||||
return getRequest<AdminRuleValueOptionsListResponse>(
|
|
||||||
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const promotions = {
|
|
||||||
retrieve: retrievePromotion,
|
|
||||||
list: listPromotions,
|
|
||||||
delete: deletePromotion,
|
|
||||||
update: updatePromotion,
|
|
||||||
create: createPromotion,
|
|
||||||
addRules: addPromotionRules,
|
|
||||||
removeRules: removePromotionRules,
|
|
||||||
updateRules: updatePromotionRules,
|
|
||||||
listRules: listPromotionRules,
|
|
||||||
listRuleAttributes: listPromotionRuleAttributes,
|
|
||||||
listRuleValues: listPromotionRuleValues,
|
|
||||||
}
|
|
||||||
@@ -2,13 +2,13 @@ import { AdminCampaignResponse } from "@medusajs/types"
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
|
|
||||||
import { campaignsQueryKeys } from "../../../hooks/api/campaigns"
|
import { campaignsQueryKeys } from "../../../hooks/api/campaigns"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const campaignDetailQuery = (id: string) => ({
|
const campaignDetailQuery = (id: string) => ({
|
||||||
queryKey: campaignsQueryKeys.detail(id),
|
queryKey: campaignsQueryKeys.detail(id),
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
client.campaigns.retrieve(id, {
|
sdk.admin.campaign.retrieve(id, {
|
||||||
fields: "+promotions.id",
|
fields: "+promotions.id",
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import { AdminProductCategoryResponse } from "@medusajs/types"
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
|
|
||||||
import { categoriesQueryKeys } from "../../../hooks/api/categories"
|
import { categoriesQueryKeys } from "../../../hooks/api/categories"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const categoryDetailQuery = (id: string) => ({
|
const categoryDetailQuery = (id: string) => ({
|
||||||
queryKey: categoriesQueryKeys.detail(id),
|
queryKey: categoriesQueryKeys.detail(id),
|
||||||
queryFn: async () => client.categories.retrieve(id),
|
queryFn: async () => sdk.admin.productCategory.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const categoryLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const categoryLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import { useCustomerGroupTableColumns } from "../../../../../hooks/table/columns
|
|||||||
import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters.tsx"
|
import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters.tsx"
|
||||||
import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query.tsx"
|
import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query.tsx"
|
||||||
import { useDataTable } from "../../../../../hooks/use-data-table.tsx"
|
import { useDataTable } from "../../../../../hooks/use-data-table.tsx"
|
||||||
import { client, sdk } from "../../../../../lib/client/index.ts"
|
import { sdk } from "../../../../../lib/client/index.ts"
|
||||||
import { queryClient } from "../../../../../lib/query-client.ts"
|
import { queryClient } from "../../../../../lib/query-client.ts"
|
||||||
|
|
||||||
type CustomerGroupSectionProps = {
|
type CustomerGroupSectionProps = {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
import { PromotionRes } from "../../../types/api-responses"
|
import { PromotionRes } from "../../../types/api-responses"
|
||||||
|
|
||||||
const promotionDetailQuery = (id: string) => ({
|
const promotionDetailQuery = (id: string) => ({
|
||||||
queryKey: promotionsQueryKeys.detail(id),
|
queryKey: promotionsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.promotions.retrieve(id),
|
queryFn: async () => sdk.admin.promotion.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const promotionLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const promotionLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { QueryClient } from "@tanstack/react-query"
|
import { QueryClient } from "@tanstack/react-query"
|
||||||
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
import { PromotionListRes } from "../../../types/api-responses"
|
import { PromotionListRes } from "../../../types/api-responses"
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ const params = {
|
|||||||
|
|
||||||
const promotionsListQuery = () => ({
|
const promotionsListQuery = () => ({
|
||||||
queryKey: promotionsQueryKeys.list(params),
|
queryKey: promotionsQueryKeys.list(params),
|
||||||
queryFn: async () => client.promotions.list(params),
|
queryFn: async () => sdk.admin.promotion.list(params),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const promotionsLoader = (client: QueryClient) => {
|
export const promotionsLoader = (client: QueryClient) => {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
import { Client } from "../client"
|
||||||
|
import { ClientHeaders } from "../types"
|
||||||
|
|
||||||
|
export class Campaign {
|
||||||
|
private client: Client
|
||||||
|
constructor(client: Client) {
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
async retrieve(
|
||||||
|
id: string,
|
||||||
|
query?: HttpTypes.AdminGetCampaignParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||||
|
`/admin/campaigns/${id}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async list(
|
||||||
|
query?: HttpTypes.AdminGetCampaignsParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminCampaignListResponse>(
|
||||||
|
`/admin/campaigns`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
payload: HttpTypes.AdminCreateCampaign,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||||
|
`/admin/campaigns`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
id: string,
|
||||||
|
payload: HttpTypes.AdminUpdateCampaign,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||||
|
`/admin/campaigns/${id}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string, headers?: ClientHeaders) {
|
||||||
|
return await this.client.fetch<HttpTypes.DeleteResponse<"campaign">>(
|
||||||
|
`/admin/campaigns/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchPromotions(
|
||||||
|
id: string,
|
||||||
|
payload: HttpTypes.AdminBatchLink,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||||
|
`/admin/campaigns/${id}/promotions`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Client } from "../client"
|
import { Client } from "../client"
|
||||||
import { ApiKey } from "./api-key"
|
import { ApiKey } from "./api-key"
|
||||||
|
import { Campaign } from "./campaign"
|
||||||
import { Claim } from "./claim"
|
import { Claim } from "./claim"
|
||||||
import { Currency } from "./currency"
|
import { Currency } from "./currency"
|
||||||
import { Customer } from "./customer"
|
import { Customer } from "./customer"
|
||||||
@@ -23,6 +24,7 @@ import { ProductCollection } from "./product-collection"
|
|||||||
import { ProductTag } from "./product-tag"
|
import { ProductTag } from "./product-tag"
|
||||||
import { ProductType } from "./product-type"
|
import { ProductType } from "./product-type"
|
||||||
import { ProductVariant } from "./product-variant"
|
import { ProductVariant } from "./product-variant"
|
||||||
|
import { Promotion } from "./promotion"
|
||||||
import { RefundReason } from "./refund-reasons"
|
import { RefundReason } from "./refund-reasons"
|
||||||
import { Region } from "./region"
|
import { Region } from "./region"
|
||||||
import Reservation from "./reservation"
|
import Reservation from "./reservation"
|
||||||
@@ -79,6 +81,8 @@ export class Admin {
|
|||||||
public workflowExecution: WorkflowExecution
|
public workflowExecution: WorkflowExecution
|
||||||
public reservation: Reservation
|
public reservation: Reservation
|
||||||
public customerGroup: CustomerGroup
|
public customerGroup: CustomerGroup
|
||||||
|
public promotion: Promotion
|
||||||
|
public campaign: Campaign
|
||||||
|
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
this.invite = new Invite(client)
|
this.invite = new Invite(client)
|
||||||
@@ -120,5 +124,7 @@ export class Admin {
|
|||||||
this.workflowExecution = new WorkflowExecution(client)
|
this.workflowExecution = new WorkflowExecution(client)
|
||||||
this.reservation = new Reservation(client)
|
this.reservation = new Reservation(client)
|
||||||
this.customerGroup = new CustomerGroup(client)
|
this.customerGroup = new CustomerGroup(client)
|
||||||
|
this.promotion = new Promotion(client)
|
||||||
|
this.campaign = new Campaign(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
import { Client } from "../client"
|
||||||
|
import { ClientHeaders } from "../types"
|
||||||
|
|
||||||
|
export class Promotion {
|
||||||
|
private client: Client
|
||||||
|
constructor(client: Client) {
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
async retrieve(
|
||||||
|
id: string,
|
||||||
|
query?: HttpTypes.AdminGetPromotionParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions/${id}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async list(
|
||||||
|
query?: HttpTypes.AdminGetPromotionsParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionListResponse>(
|
||||||
|
`/admin/promotions`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
payload: HttpTypes.AdminCreatePromotion,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
id: string,
|
||||||
|
payload: HttpTypes.AdminUpdatePromotion,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions/${id}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string, headers?: ClientHeaders) {
|
||||||
|
return await this.client.fetch<HttpTypes.DeleteResponse<"promotion">>(
|
||||||
|
`/admin/promotions/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async addRules(
|
||||||
|
id: string,
|
||||||
|
ruleType: string,
|
||||||
|
payload: HttpTypes.BatchAddPromotionRulesReq,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: { create: payload.rules },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateRules(
|
||||||
|
id: string,
|
||||||
|
ruleType: string,
|
||||||
|
payload: HttpTypes.BatchUpdatePromotionRulesReq,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: { update: payload.rules },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeRules(
|
||||||
|
id: string,
|
||||||
|
ruleType: string,
|
||||||
|
payload: HttpTypes.BatchRemovePromotionRulesReq,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||||
|
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: { delete: payload.rule_ids },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async listRules(
|
||||||
|
id: string | null,
|
||||||
|
ruleType: string,
|
||||||
|
query?: HttpTypes.AdminGetPromotionRuleParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
|
||||||
|
`/admin/promotions/${id}/${ruleType}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async listRuleAttributes(
|
||||||
|
ruleType: string,
|
||||||
|
promotionType?: string,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
|
||||||
|
`/admin/promotions/rule-attribute-options/${ruleType}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query: { promotion_type: promotionType },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async listRuleValues(
|
||||||
|
ruleType: string,
|
||||||
|
ruleValue: string,
|
||||||
|
query?: HttpTypes.AdminGetPromotionsRuleValueParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminRuleValueOptionsListResponse>(
|
||||||
|
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
export * from "./payloads"
|
export * from "./payloads"
|
||||||
|
export * from "./queries"
|
||||||
export * from "./responses"
|
export * from "./responses"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { BaseFilterable } from "../../../dal"
|
||||||
|
import { FindParams, SelectParams } from "../../common"
|
||||||
|
|
||||||
|
export interface AdminGetCampaignsParams
|
||||||
|
extends FindParams,
|
||||||
|
BaseFilterable<AdminGetCampaignsParams> {
|
||||||
|
q?: string
|
||||||
|
campaign_identifier?: string
|
||||||
|
budget?: {
|
||||||
|
currency_code?: string
|
||||||
|
}
|
||||||
|
$and?: AdminGetCampaignsParams[]
|
||||||
|
$or?: AdminGetCampaignsParams[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminGetCampaignParams extends SelectParams {}
|
||||||
@@ -5,7 +5,8 @@ import {
|
|||||||
} from "../common"
|
} from "../common"
|
||||||
|
|
||||||
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
||||||
groups: CustomerGroupInCustomerFilters | string[] | string
|
groups?: CustomerGroupInCustomerFilters | string[] | string
|
||||||
|
has_account?: boolean
|
||||||
}
|
}
|
||||||
export interface AdminCustomerAddressFilters
|
export interface AdminCustomerAddressFilters
|
||||||
extends BaseCustomerAddressFilters {}
|
extends BaseCustomerAddressFilters {}
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
export * from "./entities"
|
export * from "./entities"
|
||||||
export * from "./responses"
|
export * from "./payloads"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import {
|
||||||
|
ApplicationMethodAllocationValues,
|
||||||
|
ApplicationMethodTargetTypeValues,
|
||||||
|
ApplicationMethodTypeValues,
|
||||||
|
PromotionRuleOperatorValues,
|
||||||
|
PromotionTypeValues,
|
||||||
|
} from "../../../promotion"
|
||||||
|
import { AdminCreateCampaign } from "../../campaign"
|
||||||
|
|
||||||
|
export interface AdminCreatePromotionRule {
|
||||||
|
operator: PromotionRuleOperatorValues
|
||||||
|
description?: string | null
|
||||||
|
attribute: string
|
||||||
|
values: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminUpdatePromotionRule {
|
||||||
|
id: string
|
||||||
|
operator?: PromotionRuleOperatorValues
|
||||||
|
description?: string | null
|
||||||
|
attribute?: string
|
||||||
|
values: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminCreateApplicationMethod {
|
||||||
|
description?: string | null
|
||||||
|
value: number
|
||||||
|
currency_code?: string | null
|
||||||
|
max_quantity?: number | null
|
||||||
|
type: ApplicationMethodTypeValues
|
||||||
|
target_type: ApplicationMethodTargetTypeValues
|
||||||
|
allocation?: ApplicationMethodAllocationValues
|
||||||
|
target_rules?: AdminCreatePromotionRule[]
|
||||||
|
buy_rules?: AdminCreatePromotionRule[]
|
||||||
|
apply_to_quantity?: number | null
|
||||||
|
buy_rules_min_quantity?: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminUpdateApplicationMethod {
|
||||||
|
description?: string | null
|
||||||
|
value?: number
|
||||||
|
max_quantity?: number | null
|
||||||
|
currency_code?: string | null
|
||||||
|
type?: ApplicationMethodTypeValues
|
||||||
|
target_type?: ApplicationMethodTargetTypeValues
|
||||||
|
allocation?: ApplicationMethodAllocationValues
|
||||||
|
target_rules?: AdminCreatePromotionRule[]
|
||||||
|
buy_rules?: AdminCreatePromotionRule[]
|
||||||
|
apply_to_quantity?: number | null
|
||||||
|
buy_rules_min_quantity?: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminCreatePromotion {
|
||||||
|
code: string
|
||||||
|
is_automatic?: boolean
|
||||||
|
type: PromotionTypeValues
|
||||||
|
campaign_id?: string | null
|
||||||
|
campaign?: AdminCreateCampaign
|
||||||
|
application_method: AdminCreateApplicationMethod
|
||||||
|
rules?: AdminCreatePromotionRule[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminUpdatePromotion {
|
||||||
|
code?: string
|
||||||
|
is_automatic?: boolean
|
||||||
|
type?: PromotionTypeValues
|
||||||
|
campaign_id?: string | null
|
||||||
|
campaign?: AdminCreateCampaign
|
||||||
|
application_method?: AdminUpdateApplicationMethod
|
||||||
|
rules?: AdminCreatePromotionRule[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BatchAddPromotionRulesReq {
|
||||||
|
rules: AdminCreatePromotionRule[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BatchRemovePromotionRulesReq {
|
||||||
|
rule_ids: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BatchUpdatePromotionRulesReq {
|
||||||
|
rules: AdminUpdatePromotionRule[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { BaseFilterable, OperatorMap } from "../../../dal"
|
||||||
|
import { FindParams, SelectParams } from "../../common"
|
||||||
|
|
||||||
|
export interface AdminGetPromotionParams extends SelectParams {}
|
||||||
|
|
||||||
|
export interface AdminGetPromotionsParams
|
||||||
|
extends FindParams,
|
||||||
|
BaseFilterable<AdminGetPromotionsParams> {
|
||||||
|
q?: string
|
||||||
|
code?: string | string[]
|
||||||
|
campaign_id?: string | string[]
|
||||||
|
application_method?: {
|
||||||
|
currency_code?: string | string[]
|
||||||
|
}
|
||||||
|
created_at?: OperatorMap<string>
|
||||||
|
updated_at?: OperatorMap<string>
|
||||||
|
deleted_at?: OperatorMap<string>
|
||||||
|
$and?: AdminGetPromotionsParams[]
|
||||||
|
$or?: AdminGetPromotionsParams[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminGetPromotionRuleParams {
|
||||||
|
promotion_type?: string
|
||||||
|
application_method_type?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminGetPromotionRuleTypeParams extends SelectParams {
|
||||||
|
promotion_type?: string
|
||||||
|
application_method_type?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminGetPromotionsRuleValueParams extends FindParams {
|
||||||
|
q?: string
|
||||||
|
value?: string | string[]
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from "./entities"
|
export * from "./entities"
|
||||||
export * from "./queries"
|
export * from "./queries"
|
||||||
export * from "./responses"
|
export * from "./responses"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user