1 import { PencilSquare, Trash } from "@medusajs/icons"
2 import {
3 Container,
4 Heading,
5 StatusBadge,
6 Text,
7 toast,
8 usePrompt,
9 } from "@medusajs/ui"
10 import { useTranslation } from "react-i18next"
11
12 import { SalesChannelDTO } from "@medusajs/types"
13 import { useNavigate } from "react-router-dom"
14 import { ActionMenu } from "../../../../../components/common/action-menu"
15 import { useDeleteSalesChannel } from "../../../../../hooks/api/sales-channels"
16
17 type SalesChannelGeneralSectionProps = {
18 salesChannel: SalesChannelDTO
19 }
20
21 export const SalesChannelGeneralSection = ({
22 salesChannel,
23 }: SalesChannelGeneralSectionProps) => {
24 const { t } = useTranslation()
25 const prompt = usePrompt()
26 const navigate = useNavigate()
27
28 const { mutateAsync } = useDeleteSalesChannel(salesChannel.id)
29
30 const handleDelete = async () => {
31 const confirm = await prompt({
32 title: t("general.areYouSure"),
33 description: t("salesChannels.deleteSalesChannelWarning", {
34 name: salesChannel.name,
35 }),
36 verificationInstruction: t("general.typeToConfirm"),
37 verificationText: salesChannel.name,
38 confirmText: t("actions.delete"),
39 cancelText: t("actions.cancel"),
40 })
41
42 if (!confirm) {
43 return
44 }
45
46 await mutateAsync(undefined, {
47 onSuccess: () => {
48 toast.success(t("salesChannels.toast.delete"))
49 navigate("/settings/sales-channels", { replace: true })
50 },
51 onError: (e) => {
52 toast.error(e.message)
53 },
54 })
55 }
56
57 return (
58 <Container className="divide-y p-0">
59 <div className="flex items-center justify-between px-6 py-4">
60 <Heading>{salesChannel.name}</Heading>
61 <div className="flex items-center gap-x-2">
62 <StatusBadge color={salesChannel.is_disabled ? "red" : "green"}>
63 {t(`general.${salesChannel.is_disabled ? "disabled" : "enabled"}`)}
64 </StatusBadge>
65 <ActionMenu
66 groups={[
67 {
68 actions: [
69 {
70 icon: <PencilSquare />,
71 label: t("actions.edit"),
72 to: `/settings/sales-channels/${salesChannel.id}/edit`,
73 },
74 ],
75 },
76 {
77 actions: [
78 {
79 icon: <Trash />,
80 label: t("actions.delete"),
81 onClick: handleDelete,
82 },
83 ],
84 },
85 ]}
86 />
87 </div>
88 </div>
89 <div className="text-ui-fg-subtle grid grid-cols-2 items-start px-6 py-4">
90 <Text size="small" leading="compact" weight="plus">
91 {t("fields.description")}
92 </Text>
93 <Text size="small" leading="compact">
94 {salesChannel.description || "-"}
95 </Text>
96 </div>
97 </Container>
98 )
99 }