feat: add sales channel management (#6761)

Add V2 sales channel management to admin

`@medusajs/medusa`
- Add `POST /admin/sales-channels/:id/products/batch/remove`
- Refactor cross-module filter middleware to comply with the latest convention

`@medusajs/admin-next`
- Add all sales channel routes
- Moves the following sales channel UI to shared components in `modules/sales-channel`:
  - sales-channel-list
  - sales-channel-edit
  - sales-channel-details
    - sales-channel-general-section
  - sales-channel-create

The sales-channel-product-section is not shared because the API in V2 will change.
The sales-channel-add-products component is not shared because the API in V2 will change.

`@medusajs/core-flows`
- Add `detachProductsFromSalesChannelsStep`
- Add `removeProductsFromSalesChannelsWorkflow`
This commit is contained in:
Oli Juhl
2024-04-02 15:38:33 +02:00
committed by GitHub
parent 3dee91426e
commit 7895ff3849
40 changed files with 1184 additions and 58 deletions

View File

@@ -0,0 +1,47 @@
import { Modules } from "@medusajs/modules-sdk"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
interface StepInput {
links: {
sales_channel_id: string
product_ids: string[]
}[]
}
export const detachProductsFromSalesChannelsStepId =
"detach-products-from-sales-channels-step"
export const detachProductsFromSalesChannelsStep = createStep(
detachProductsFromSalesChannelsStepId,
async (input: StepInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const links = input.links
.map((link) => {
return link.product_ids.map((id) => {
return {
[Modules.PRODUCT]: {
product_id: id,
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: link.sales_channel_id,
},
}
})
})
.flat()
await remoteLink.dismiss(links)
return new StepResponse(void 0, links)
},
async (links, { container }) => {
if (!links?.length) {
return
}
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create(links)
}
)

View File

@@ -2,5 +2,6 @@ export * from "./associate-products-with-channels"
export * from "./create-default-sales-channel"
export * from "./create-sales-channels"
export * from "./delete-sales-channels"
export * from "./detach-products-from-sales-channels"
export * from "./update-sales-channels"

View File

@@ -1,5 +1,6 @@
export * from "./add-products-to-sales-channels"
export * from "./create-sales-channels"
export * from "./delete-sales-channels"
export * from "./remove-products-from-sales-channels"
export * from "./update-sales-channels"

View File

@@ -0,0 +1,19 @@
import { SalesChannelDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { detachProductsFromSalesChannelsStep } from "../steps/detach-products-from-sales-channels"
type WorkflowInput = {
data: {
sales_channel_id: string
product_ids: string[]
}[]
}
export const removeProductsFromSalesChannelsWorkflowId =
"remove-products-from-sales-channels"
export const removeProductsFromSalesChannelsWorkflow = createWorkflow(
removeProductsFromSalesChannelsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<SalesChannelDTO[]> => {
return detachProductsFromSalesChannelsStep({ links: input.data })
}
)