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:
Riqwan Thamir
2024-04-06 13:20:31 +02:00
committed by GitHub
parent 07fb058d96
commit 5e30b8cce6
60 changed files with 2803 additions and 153 deletions
@@ -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,
}