1 import { GlobeEurope, PencilSquare, Trash } from "@medusajs/icons"
2 import { HttpTypes } from "@medusajs/types"
3 import { Container, Heading, Text, usePrompt } from "@medusajs/ui"
4 import { useTranslation } from "react-i18next"
5 import { ActionMenu } from "../../../../../components/common/action-menu"
6 import { useDeleteCollection } from "../../../../../hooks/api/collections"
7 import { useNavigate } from "react-router-dom"
8 import { useFeatureFlag } from "../../../../../providers/feature-flag-provider"
9
10 type CollectionGeneralSectionProps = {
11 collection: HttpTypes.AdminCollection
12 }
13
14 export const CollectionGeneralSection = ({
15 collection,
16 }: CollectionGeneralSectionProps) => {
17 const { t } = useTranslation()
18 const prompt = usePrompt()
19 const navigate = useNavigate()
20 const isTranslationsEnabled = useFeatureFlag("translation")
21
22 const { mutateAsync } = useDeleteCollection(collection.id!)
23
24 const handleDelete = async () => {
25 const res = await prompt({
26 title: t("general.areYouSure"),
27 description: t("collections.deleteWarning", {
28 count: 1,
29 title: collection.title,
30 }),
31 })
32
33 if (!res) {
34 return
35 }
36
37 await mutateAsync()
38 navigate("../", { replace: true })
39 }
40
41 return (
42 <Container className="divide-y p-0">
43 <div className="flex items-center justify-between px-6 py-4">
44 <Heading>{collection.title}</Heading>
45 <ActionMenu
46 groups={[
47 {
48 actions: [
49 {
50 icon: <PencilSquare />,
51 label: t("actions.edit"),
52 to: `/collections/${collection.id}/edit`,
53 disabled: !collection.id,
54 },
55 ],
56 },
57 ...(isTranslationsEnabled
58 ? [
59 {
60 actions: [
61 {
62 label: t("translations.actions.manage"),
63 to: `/settings/translations/edit?reference=product_collection&reference_id=${collection.id}`,
64 icon: <GlobeEurope />,
65 },
66 ],
67 },
68 ]
69 : []),
70 {
71 actions: [
72 {
73 icon: <Trash />,
74 label: t("actions.delete"),
75 onClick: handleDelete,
76 disabled: !collection.id,
77 },
78 ],
79 },
80 ]}
81 />
82 </div>
83 <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
84 <Text size="small" leading="compact" weight="plus">
85 {t("fields.handle")}
86 </Text>
87 <Text size="small">/{collection.handle}</Text>
88 </div>
89 </Container>
90 )
91 }