|
1
|
import { PencilSquare, Trash } from "@medusajs/icons" |
|
2
|
import { HttpTypes } from "@medusajs/types" |
|
3
|
import { StatusBadge, Text } from "@medusajs/ui" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
import { ActionMenu } from "../../../../../components/common/action-menu" |
|
6
|
import { formatPercentage } from "../../../../../lib/percentage-helpers" |
|
7
|
import { useDeleteTaxRateAction } from "../../hooks" |
|
8
|
|
|
9
|
type TaxRateLineProps = { |
|
10
|
taxRate: HttpTypes.AdminTaxRate |
|
11
|
isSublevelTaxRate?: boolean |
|
12
|
} |
|
13
|
|
|
14
|
export const TaxRateLine = ({ |
|
15
|
taxRate, |
|
16
|
isSublevelTaxRate, |
|
17
|
}: TaxRateLineProps) => { |
|
18
|
const { t } = useTranslation() |
|
19
|
|
|
20
|
return ( |
|
21
|
<div className="text-ui-fg-subtle grid grid-cols-[1fr_1fr_auto] items-center gap-4 px-6 py-4"> |
|
22
|
<div className="flex items-center gap-x-1.5"> |
|
23
|
<Text size="small" weight="plus" leading="compact"> |
|
24
|
{taxRate.name} |
|
25
|
</Text> |
|
26
|
{taxRate.code && ( |
|
27
|
<div className="flex items-center gap-x-1.5"> |
|
28
|
<Text size="small" leading="compact"> |
|
29
|
· |
|
30
|
</Text> |
|
31
|
<Text size="small" leading="compact"> |
|
32
|
{taxRate.code} |
|
33
|
</Text> |
|
34
|
</div> |
|
35
|
)} |
|
36
|
</div> |
|
37
|
<Text size="small" leading="compact"> |
|
38
|
{formatPercentage(taxRate.rate)} |
|
39
|
</Text> |
|
40
|
<div className="flex items-center justify-end gap-x-2"> |
|
41
|
{isSublevelTaxRate && ( |
|
42
|
<StatusBadge color={taxRate.is_combinable ? "green" : "grey"}> |
|
43
|
{taxRate.is_combinable |
|
44
|
? t("taxRegions.fields.isCombinable.true") |
|
45
|
: t("taxRegions.fields.isCombinable.false")} |
|
46
|
</StatusBadge> |
|
47
|
)} |
|
48
|
<TaxRateActions taxRate={taxRate} /> |
|
49
|
</div> |
|
50
|
</div> |
|
51
|
) |
|
52
|
} |
|
53
|
|
|
54
|
const TaxRateActions = ({ taxRate }: { taxRate: HttpTypes.AdminTaxRate }) => { |
|
55
|
const { t } = useTranslation() |
|
56
|
const handleDelete = useDeleteTaxRateAction(taxRate) |
|
57
|
|
|
58
|
return ( |
|
59
|
<ActionMenu |
|
60
|
groups={[ |
|
61
|
{ |
|
62
|
actions: [ |
|
63
|
{ |
|
64
|
label: t("actions.edit"), |
|
65
|
icon: <PencilSquare />, |
|
66
|
to: `tax-rates/${taxRate.id}/edit`, |
|
67
|
}, |
|
68
|
], |
|
69
|
}, |
|
70
|
{ |
|
71
|
actions: [ |
|
72
|
{ |
|
73
|
label: t("actions.delete"), |
|
74
|
icon: <Trash />, |
|
75
|
onClick: handleDelete, |
|
76
|
}, |
|
77
|
], |
|
78
|
}, |
|
79
|
]} |
|
80
|
/> |
|
81
|
) |
|
82
|
} |