feat(dashboard): add promotions to campaign UI (#7283)
* feat(core-flows,types,medusa): API to add promotions to campaign * chore: consolidate specs * chore: split workflows step into 2 * chore: fix tests * chore: fix specs * chore: add promotions to campaign UI * chore: fix bug wrt to not refreshing * chore: address review comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
AdminCampaignListResponse,
|
||||
AdminCampaignResponse,
|
||||
LinkMethodRequest,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
@@ -14,6 +15,7 @@ import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { CreateCampaignReq, UpdateCampaignReq } from "../../types/api-payloads"
|
||||
import { CampaignDeleteRes } from "../../types/api-responses"
|
||||
import { promotionsQueryKeys } from "./promotions"
|
||||
|
||||
const REGIONS_QUERY_KEY = "campaigns" as const
|
||||
export const campaignsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
||||
@@ -82,7 +84,7 @@ export const useUpdateCampaign = (
|
||||
mutationFn: (payload) => client.campaigns.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.detail(id) })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
@@ -98,10 +100,26 @@ export const useDeleteCampaign = (
|
||||
mutationFn: () => client.campaigns.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.detail(id) })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useAddOrRemoveCampaignPromotions = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<AdminCampaignResponse, Error, LinkMethodRequest>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.campaigns.addOrRemovePromotions(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user