|
1
|
// TODO: V1 policies are read-only in the dashboard (defined in code via |
|
2
|
// `definePolicies()``). The Edit / Delete action menu is commented out |
|
3
|
// below — uncomment to re-enable when policy management is opened to admins. |
|
4
|
|
|
5
|
// import { PencilSquare, Trash } from "@medusajs/icons" |
|
6
|
import { HttpTypes } from "@medusajs/types" |
|
7
|
import { |
|
8
|
Container, |
|
9
|
Heading, |
|
10
|
// Hint, |
|
11
|
// toast, |
|
12
|
// usePrompt, |
|
13
|
} from "@medusajs/ui" |
|
14
|
import { useTranslation } from "react-i18next" |
|
15
|
// import { useNavigate } from "react-router-dom" |
|
16
|
|
|
17
|
// import { ActionMenu } from "../../../../../components/common/action-menu" |
|
18
|
import { SectionRow } from "../../../../../components/common/section" |
|
19
|
// import { useDeleteRbacPolicy } from "../../../../../hooks/api/rbac-policies" |
|
20
|
// import { usePermissions } from "../../../../../providers/permissions-provider" |
|
21
|
|
|
22
|
type PolicyGeneralSectionProps = { |
|
23
|
policy: HttpTypes.AdminRbacPolicy |
|
24
|
} |
|
25
|
|
|
26
|
export const PolicyGeneralSection = ({ policy }: PolicyGeneralSectionProps) => { |
|
27
|
const { t } = useTranslation() |
|
28
|
// const navigate = useNavigate() |
|
29
|
// const prompt = usePrompt() |
|
30
|
// const { hasPermission } = usePermissions() |
|
31
|
|
|
32
|
// const { mutateAsync: deletePolicy, isPending: isDeleting } = |
|
33
|
// useDeleteRbacPolicy(policy.id) |
|
34
|
|
|
35
|
// const handleDelete = async () => { |
|
36
|
// const confirmed = await prompt({ |
|
37
|
// title: t("policies.delete.title"), |
|
38
|
// description: t("policies.delete.description", { key: policy.key }), |
|
39
|
// confirmText: t("actions.delete"), |
|
40
|
// cancelText: t("actions.cancel"), |
|
41
|
// }) |
|
42
|
// |
|
43
|
// if (!confirmed) { |
|
44
|
// return |
|
45
|
// } |
|
46
|
// |
|
47
|
// try { |
|
48
|
// await deletePolicy() |
|
49
|
// toast.success(t("policies.delete.successToast", { key: policy.key })) |
|
50
|
// navigate("/settings/policies", { replace: true }) |
|
51
|
// } catch (error) { |
|
52
|
// toast.error((error as Error).message) |
|
53
|
// } |
|
54
|
// } |
|
55
|
|
|
56
|
// const canUpdate = hasPermission("rbac_policy:update") |
|
57
|
// const canDelete = hasPermission("rbac_policy:delete") |
|
58
|
|
|
59
|
return ( |
|
60
|
<Container className="divide-y p-0"> |
|
61
|
<div className="flex items-center justify-between px-6 py-4"> |
|
62
|
<Heading>{policy.name ?? policy.key}</Heading> |
|
63
|
{/* |
|
64
|
<ActionMenu |
|
65
|
groups={[ |
|
66
|
{ |
|
67
|
actions: [ |
|
68
|
{ |
|
69
|
icon: <PencilSquare />, |
|
70
|
label: t("actions.edit"), |
|
71
|
to: `edit`, |
|
72
|
disabled: !canUpdate, |
|
73
|
disabledTooltip: ( |
|
74
|
<Hint variant="error"> |
|
75
|
{t("permissions.accessDenied.action")} |
|
76
|
</Hint> |
|
77
|
), |
|
78
|
}, |
|
79
|
], |
|
80
|
}, |
|
81
|
{ |
|
82
|
actions: [ |
|
83
|
{ |
|
84
|
icon: <Trash />, |
|
85
|
label: t("actions.delete"), |
|
86
|
onClick: handleDelete, |
|
87
|
disabled: !canDelete || isDeleting, |
|
88
|
disabledTooltip: ( |
|
89
|
<Hint variant="error"> |
|
90
|
{t("permissions.accessDenied.action")} |
|
91
|
</Hint> |
|
92
|
), |
|
93
|
}, |
|
94
|
], |
|
95
|
}, |
|
96
|
]} |
|
97
|
/> |
|
98
|
*/} |
|
99
|
</div> |
|
100
|
<SectionRow title={t("fields.key")} value={policy.key} /> |
|
101
|
<SectionRow title={t("fields.resource")} value={policy.resource} /> |
|
102
|
<SectionRow title={t("fields.operation")} value={policy.operation} /> |
|
103
|
<SectionRow title={t("fields.name")} value={policy.name} /> |
|
104
|
<SectionRow title={t("fields.description")} value={policy.description} /> |
|
105
|
</Container> |
|
106
|
) |
|
107
|
} |