The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
import { PencilSquare, Trash } from "@medusajs/icons"
import {
Container,
Heading,
StatusBadge,
Text,
toast,
usePrompt,
} from "@medusajs/ui"
import { useTranslation } from "react-i18next"
import { SalesChannelDTO } from "@medusajs/types"
import { useNavigate } from "react-router-dom"
import { ActionMenu } from "../../../../../components/common/action-menu"
import { useDeleteSalesChannel } from "../../../../../hooks/api/sales-channels"
type SalesChannelGeneralSectionProps = {
salesChannel: SalesChannelDTO
}
export const SalesChannelGeneralSection = ({
salesChannel,
}: SalesChannelGeneralSectionProps) => {
const { t } = useTranslation()
const prompt = usePrompt()
const navigate = useNavigate()
const { mutateAsync } = useDeleteSalesChannel(salesChannel.id)
const handleDelete = async () => {
const confirm = await prompt({
title: t("general.areYouSure"),
description: t("salesChannels.deleteSalesChannelWarning", {
name: salesChannel.name,
}),
verificationInstruction: t("general.typeToConfirm"),
verificationText: salesChannel.name,
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
})
if (!confirm) {
return
}
await mutateAsync(undefined, {
onSuccess: () => {
toast.success(t("salesChannels.toast.delete"))
navigate("/settings/sales-channels", { replace: true })
},
onError: (e) => {
toast.error(e.message)
},
})
}
return (
<Container className="divide-y p-0" data-testid="sales-channel-general-section-container">
<div className="flex items-center justify-between px-6 py-4" data-testid="sales-channel-general-section-header">
<Heading data-testid="sales-channel-general-section-heading">{salesChannel.name}</Heading>
<div className="flex items-center gap-x-2">
<StatusBadge color={salesChannel.is_disabled ? "red" : "green"} data-testid="sales-channel-general-section-status-badge">
{t(`general.${salesChannel.is_disabled ? "disabled" : "enabled"}`)}
</StatusBadge>
<ActionMenu
groups={[
{
actions: [
{
icon: <PencilSquare />,
permission: "sales_channels:edit",
label: t("actions.edit"),
to: `/settings/sales-channels/${salesChannel.id}/edit`,
},
],
},
{
actions: [
{
icon: <Trash />,
permission: "sales_channels:manage",
label: t("actions.delete"),
onClick: handleDelete,
},
],
},
]}
data-testid="sales-channel-general-section-action-menu"
/>
</div>
</div>
<div className="text-ui-fg-subtle grid grid-cols-2 items-start px-6 py-4" data-testid="sales-channel-general-section-description-row">
<Text size="small" leading="compact" weight="plus" data-testid="sales-channel-general-section-description-label">
{t("fields.description")}
</Text>
<Text size="small" leading="compact" data-testid="sales-channel-general-section-description-value">
{salesChannel.description || "-"}
</Text>
</div>
</Container>
)
}