|
1
|
import { PencilSquare, Trash } from "@medusajs/icons" |
|
2
|
import { HttpTypes } from "@medusajs/types" |
|
3
|
import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
import { useNavigate } from "react-router-dom" |
|
6
|
|
|
7
|
import { ActionMenu } from "../../../../../components/common/action-menu" |
|
8
|
import { useDeleteCustomerGroup } from "../../../../../hooks/api/customer-groups" |
|
9
|
|
|
10
|
type CustomerGroupGeneralSectionProps = { |
|
11
|
group: HttpTypes.AdminCustomerGroup |
|
12
|
} |
|
13
|
|
|
14
|
export const CustomerGroupGeneralSection = ({ |
|
15
|
group, |
|
16
|
}: CustomerGroupGeneralSectionProps) => { |
|
17
|
const { t } = useTranslation() |
|
18
|
const prompt = usePrompt() |
|
19
|
const navigate = useNavigate() |
|
20
|
|
|
21
|
const { mutateAsync } = useDeleteCustomerGroup(group.id) |
|
22
|
|
|
23
|
const handleDelete = async () => { |
|
24
|
const res = await prompt({ |
|
25
|
title: t("customerGroups.delete.title"), |
|
26
|
description: t("customerGroups.delete.description", { |
|
27
|
name: group.name, |
|
28
|
}), |
|
29
|
confirmText: t("actions.delete"), |
|
30
|
cancelText: t("actions.cancel"), |
|
31
|
}) |
|
32
|
|
|
33
|
if (!res) { |
|
34
|
return |
|
35
|
} |
|
36
|
|
|
37
|
await mutateAsync(undefined, { |
|
38
|
onSuccess: () => { |
|
39
|
toast.success( |
|
40
|
t("customerGroups.delete.successToast", { |
|
41
|
name: group.name, |
|
42
|
}) |
|
43
|
) |
|
44
|
|
|
45
|
navigate("/customer-groups", { replace: true }) |
|
46
|
}, |
|
47
|
onError: (error) => { |
|
48
|
toast.error(error.message) |
|
49
|
}, |
|
50
|
}) |
|
51
|
} |
|
52
|
|
|
53
|
return ( |
|
54
|
<Container className="divide-y p-0"> |
|
55
|
<div className="flex items-center justify-between px-6 py-4"> |
|
56
|
<Heading>{group.name}</Heading> |
|
57
|
<ActionMenu |
|
58
|
groups={[ |
|
59
|
{ |
|
60
|
actions: [ |
|
61
|
{ |
|
62
|
icon: <PencilSquare />, |
|
63
|
label: t("actions.edit"), |
|
64
|
to: `/customer-groups/${group.id}/edit`, |
|
65
|
}, |
|
66
|
], |
|
67
|
}, |
|
68
|
{ |
|
69
|
actions: [ |
|
70
|
{ |
|
71
|
icon: <Trash />, |
|
72
|
label: t("actions.delete"), |
|
73
|
onClick: handleDelete, |
|
74
|
}, |
|
75
|
], |
|
76
|
}, |
|
77
|
]} |
|
78
|
/> |
|
79
|
</div> |
|
80
|
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> |
|
81
|
<Text size="small" leading="compact" weight="plus"> |
|
82
|
{t("customers.domain")} |
|
83
|
</Text> |
|
84
|
<Text size="small" leading="compact"> |
|
85
|
{group.customers?.length || "-"} |
|
86
|
</Text> |
|
87
|
</div> |
|
88
|
</Container> |
|
89
|
) |
|
90
|
} |