|
1
|
import { Channels, PencilSquare } from "@medusajs/icons" |
|
2
|
import { HttpTypes } from "@medusajs/types" |
|
3
|
import { Container, Heading, Text } from "@medusajs/ui" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
|
|
6
|
import { ActionMenu } from "../../../../../components/common/action-menu" |
|
7
|
import { NoRecords } from "../../../../../components/common/empty-table-content" |
|
8
|
import { IconAvatar } from "../../../../../components/common/icon-avatar" |
|
9
|
import { ListSummary } from "../../../../../components/common/list-summary" |
|
10
|
import { useSalesChannels } from "../../../../../hooks/api/sales-channels" |
|
11
|
|
|
12
|
type LocationsSalesChannelsSectionProps = { |
|
13
|
location: HttpTypes.AdminStockLocation |
|
14
|
} |
|
15
|
|
|
16
|
function LocationsSalesChannelsSection({ |
|
17
|
location, |
|
18
|
}: LocationsSalesChannelsSectionProps) { |
|
19
|
const { t } = useTranslation() |
|
20
|
const { count } = useSalesChannels({ limit: 1, fields: "id" }) |
|
21
|
|
|
22
|
const hasConnectedChannels = !!location.sales_channels?.length |
|
23
|
|
|
24
|
return ( |
|
25
|
<Container className="flex flex-col px-6 py-4"> |
|
26
|
<div className="flex items-center justify-between"> |
|
27
|
<Heading level="h2">{t("stockLocations.salesChannels.header")}</Heading> |
|
28
|
<ActionMenu |
|
29
|
groups={[ |
|
30
|
{ |
|
31
|
actions: [ |
|
32
|
{ |
|
33
|
label: t("actions.edit"), |
|
34
|
to: "sales-channels", |
|
35
|
icon: <PencilSquare />, |
|
36
|
}, |
|
37
|
], |
|
38
|
}, |
|
39
|
]} |
|
40
|
/> |
|
41
|
</div> |
|
42
|
{hasConnectedChannels ? ( |
|
43
|
<div className="flex flex-col gap-y-4 pt-4"> |
|
44
|
<div className="grid grid-cols-[28px_1fr] items-center gap-x-3"> |
|
45
|
<IconAvatar> |
|
46
|
<Channels className="text-ui-fg-subtle" /> |
|
47
|
</IconAvatar> |
|
48
|
<ListSummary |
|
49
|
n={3} |
|
50
|
className="text-ui-fg-base" |
|
51
|
inline |
|
52
|
list={location.sales_channels?.map((sc) => sc.name) ?? []} |
|
53
|
/> |
|
54
|
</div> |
|
55
|
<Text className="text-ui-fg-subtle" size="small" leading="compact"> |
|
56
|
{t("stockLocations.salesChannels.connectedTo", { |
|
57
|
count: location.sales_channels?.length, |
|
58
|
total: count, |
|
59
|
})} |
|
60
|
</Text> |
|
61
|
</div> |
|
62
|
) : ( |
|
63
|
<NoRecords |
|
64
|
className="h-fit pb-2 pt-6" |
|
65
|
action={{ |
|
66
|
label: t("stockLocations.salesChannels.action"), |
|
67
|
to: "sales-channels", |
|
68
|
}} |
|
69
|
message={t("stockLocations.salesChannels.noChannels")} |
|
70
|
/> |
|
71
|
)} |
|
72
|
</Container> |
|
73
|
) |
|
74
|
} |
|
75
|
|
|
76
|
export default LocationsSalesChannelsSection |