feat(dashboard): added details page for promotions + edit sliders (#6882)
* chore: added details page for promotions * chore: add edit rules, edit details and edit campaign pages * chore: change to type button * chore: connection for rules * chore: listing rule labels of multiple modules * chore: add badge summary list * chore: fix campaigns
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
AdminCampaignRes,
|
||||
AdminCampaignsListRes,
|
||||
AdminGetCampaignsCampaignParams,
|
||||
AdminGetCampaignsParams,
|
||||
AdminPostCampaignsCampaignReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { queryKeysFactory, useAdminCustomQuery } from "medusa-react"
|
||||
import { medusa } from "../medusa"
|
||||
|
||||
const QUERY_KEY = "admin_campaigns"
|
||||
export const adminCampaignKeys = queryKeysFactory<
|
||||
typeof QUERY_KEY,
|
||||
AdminGetCampaignsParams
|
||||
>(QUERY_KEY)
|
||||
|
||||
export const adminCampaignQueryFns = {
|
||||
list: (query: AdminGetCampaignsParams) =>
|
||||
medusa.admin.custom.get(`/admin/campaigns`, query),
|
||||
detail: (id: string) => medusa.admin.custom.get(`/admin/campaigns/${id}`),
|
||||
}
|
||||
|
||||
export const useV2Campaigns = (
|
||||
query?: AdminGetCampaignsParams,
|
||||
options?: object
|
||||
) => {
|
||||
const { data, ...rest } = useAdminCustomQuery<
|
||||
AdminGetCampaignsParams,
|
||||
AdminCampaignsListRes
|
||||
>("/admin/campaigns", adminCampaignKeys.list(query), query, options)
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useV2Campaign = (
|
||||
id: string,
|
||||
query?: AdminGetCampaignsParams,
|
||||
options?: object
|
||||
) => {
|
||||
const { data, ...rest } = useAdminCustomQuery<
|
||||
AdminGetCampaignsCampaignParams,
|
||||
AdminCampaignRes
|
||||
>(`/admin/campaigns/${id}`, adminCampaignKeys.detail(id), query, options)
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useV2DeleteCampaign = (id: string) => {
|
||||
return useMutation(() => medusa.admin.custom.delete(`/admin/campaigns/${id}`))
|
||||
}
|
||||
|
||||
export const useV2PostCampaign = (id: string) => {
|
||||
return useMutation((args: AdminPostCampaignsCampaignReq) =>
|
||||
medusa.client.request("POST", `/admin/campaigns/${id}`, args)
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./auth"
|
||||
export * from "./promotion"
|
||||
export * from "./store"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import {
|
||||
AdminGetPromotionsParams,
|
||||
AdminPromotionsListRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
import {
|
||||
UseQueryOptionsWrapper,
|
||||
queryKeysFactory,
|
||||
useAdminCustomQuery,
|
||||
} from "medusa-react"
|
||||
|
||||
const ADMIN_PROMOTIONS_QUERY_KEY = "admin_promotions"
|
||||
|
||||
export const adminPromotionKeys = queryKeysFactory<
|
||||
typeof ADMIN_PROMOTIONS_QUERY_KEY,
|
||||
AdminGetPromotionsParams
|
||||
>(ADMIN_PROMOTIONS_QUERY_KEY)
|
||||
|
||||
type PromotionQueryKey = typeof adminPromotionKeys
|
||||
|
||||
export const useV2Promotions = (
|
||||
query?: AdminGetPromotionsParams,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<AdminPromotionsListRes>,
|
||||
Error,
|
||||
ReturnType<PromotionQueryKey["list"]>
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useAdminCustomQuery<
|
||||
AdminGetPromotionsParams,
|
||||
AdminPromotionsListRes
|
||||
>("/promotions", adminPromotionKeys.list(query), query, options as any)
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { CreateCampaignDTO, UpdateCampaignDTO } from "@medusajs/types"
|
||||
import {
|
||||
CampaignDeleteRes,
|
||||
CampaignListRes,
|
||||
CampaignRes,
|
||||
} from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
async function retrieveCampaign(id: string, query?: Record<string, any>) {
|
||||
return getRequest<CampaignRes>(`/admin/campaigns/${id}`, query)
|
||||
}
|
||||
|
||||
async function listCampaigns(query?: Record<string, any>) {
|
||||
return getRequest<CampaignListRes>(`/admin/campaigns`, query)
|
||||
}
|
||||
|
||||
async function createCampaign(payload: CreateCampaignDTO) {
|
||||
return postRequest<CampaignRes>(`/admin/campaigns`, payload)
|
||||
}
|
||||
|
||||
async function updateCampaign(id: string, payload: UpdateCampaignDTO) {
|
||||
return postRequest<CampaignRes>(`/admin/campaigns/${id}`, payload)
|
||||
}
|
||||
|
||||
async function deleteCampaign(id: string) {
|
||||
return deleteRequest<CampaignDeleteRes>(`/admin/campaigns/${id}`)
|
||||
}
|
||||
|
||||
export const campaigns = {
|
||||
retrieve: retrieveCampaign,
|
||||
list: listCampaigns,
|
||||
create: createCampaign,
|
||||
update: updateCampaign,
|
||||
delete: deleteCampaign,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiKeys } from "./api-keys"
|
||||
import { auth } from "./auth"
|
||||
import { campaigns } from "./campaigns"
|
||||
import { categories } from "./categories"
|
||||
import { collections } from "./collections"
|
||||
import { currencies } from "./currencies"
|
||||
@@ -19,6 +20,7 @@ import { workflowExecutions } from "./workflow-executions"
|
||||
export const client = {
|
||||
auth: auth,
|
||||
apiKeys: apiKeys,
|
||||
campaigns: campaigns,
|
||||
categories: categories,
|
||||
customers: customers,
|
||||
currencies: currencies,
|
||||
|
||||
@@ -1,23 +1,113 @@
|
||||
import { AdminGetPromotionsParams } from "@medusajs/medusa"
|
||||
|
||||
import { PromotionListRes, PromotionRes } from "../../types/api-responses"
|
||||
import { getRequest } from "./common"
|
||||
import {
|
||||
BatchAddPromotionRulesReq,
|
||||
BatchRemovePromotionRulesReq,
|
||||
BatchUpdatePromotionRulesReq,
|
||||
CreatePromotionReq,
|
||||
UpdatePromotionReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
PromotionDeleteRes,
|
||||
PromotionListRes,
|
||||
PromotionRes,
|
||||
PromotionRuleAttributesListRes,
|
||||
PromotionRuleOperatorsListRes,
|
||||
PromotionRuleValuesListRes,
|
||||
} from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
const retrievePromotion = async (
|
||||
id: string,
|
||||
query?: AdminGetPromotionsParams
|
||||
) => {
|
||||
async function retrievePromotion(id: string, query?: AdminGetPromotionsParams) {
|
||||
return getRequest<PromotionRes, AdminGetPromotionsParams>(
|
||||
`/admin/promotions/${id}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
const listPromotions = async (query?: AdminGetPromotionsParams) => {
|
||||
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/add`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function updatePromotionRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: BatchUpdatePromotionRulesReq
|
||||
) {
|
||||
return postRequest<PromotionRes>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch/update`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function removePromotionRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: BatchRemovePromotionRulesReq
|
||||
) {
|
||||
return postRequest<PromotionRes>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch/remove`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRules(id: string, ruleType: string) {
|
||||
return getRequest<PromotionRuleAttributesListRes>(
|
||||
`/admin/promotions/${id}/${ruleType}`
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRuleAttributes(ruleType: string) {
|
||||
return getRequest<PromotionRuleAttributesListRes>(
|
||||
`/admin/promotions/rule-attribute-options/${ruleType}`
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRuleValues(ruleType: string, ruleValue: string) {
|
||||
return getRequest<PromotionRuleValuesListRes>(
|
||||
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRuleOperators() {
|
||||
return getRequest<PromotionRuleOperatorsListRes>(
|
||||
`/admin/promotions/rule-operator-options`
|
||||
)
|
||||
}
|
||||
|
||||
export const promotions = {
|
||||
retrieve: retrievePromotion,
|
||||
list: listPromotions,
|
||||
delete: deletePromotion,
|
||||
update: updatePromotion,
|
||||
create: createPromotion,
|
||||
addRules: addPromotionRules,
|
||||
removeRules: removePromotionRules,
|
||||
updateRules: updatePromotionRules,
|
||||
listRules: listPromotionRules,
|
||||
listRuleAttributes: listPromotionRuleAttributes,
|
||||
listRuleOperators: listPromotionRuleOperators,
|
||||
listRuleValues: listPromotionRuleValues,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user