|
1
|
import { useParams } from "react-router-dom" |
|
2
|
import { LayoutComposer } from "@medusajs/dashboard/components" |
|
3
|
import { JsonViewSection } from "../../../components/json-view-section" |
|
4
|
import { useGiftCard } from "../../../hooks/api/gift-cards" |
|
5
|
import GiftCardBalanceSection from "./components/gift-card-balance-section" |
|
6
|
import GiftCardGeneralSection from "./components/gift-card-general-section" |
|
7
|
import GiftCardNoteSection from "./components/gift-card-note-section" |
|
8
|
import GiftCardOrderSection from "./components/gift-card-order-section" |
|
9
|
import GiftCardTransactionsSection from "./components/gift-card-transactions-section" |
|
10
|
import { AdminGiftCard, AdminStoreCreditAccount } from "../../../../types" |
|
11
|
|
|
12
|
type GiftCardWithStoreCreditAccount = AdminGiftCard & { |
|
13
|
store_credit_account: AdminStoreCreditAccount |
|
14
|
} |
|
15
|
|
|
16
|
const GiftCardDetailsPage = () => { |
|
17
|
const { id } = useParams() |
|
18
|
const { gift_card: giftCard, isLoading } = useGiftCard(id!, { |
|
19
|
fields: "*line_item.product,*store_credit_account", |
|
20
|
}) |
|
21
|
|
|
22
|
if (isLoading) { |
|
23
|
return <>Loading</> |
|
24
|
} |
|
25
|
|
|
26
|
if (!isLoading && !giftCard) { |
|
27
|
return <>Gift card not found</> |
|
28
|
} |
|
29
|
|
|
30
|
const storeCreditAccount = (giftCard as GiftCardWithStoreCreditAccount) |
|
31
|
?.store_credit_account |
|
32
|
|
|
33
|
return ( |
|
34
|
<LayoutComposer |
|
35
|
widgetsZonePrefix="gift_card.details" |
|
36
|
preferredLayoutId="core:two-column" |
|
37
|
data={giftCard} |
|
38
|
sections={{ |
|
39
|
main: ( |
|
40
|
<> |
|
41
|
<LayoutComposer.Entry id="GiftCardGeneralSection"> |
|
42
|
<GiftCardGeneralSection giftCard={giftCard!} /> |
|
43
|
</LayoutComposer.Entry> |
|
44
|
|
|
45
|
{storeCreditAccount && ( |
|
46
|
<LayoutComposer.Entry id="GiftCardTransactionsSection"> |
|
47
|
<GiftCardTransactionsSection |
|
48
|
storeCreditAccount={storeCreditAccount} |
|
49
|
/> |
|
50
|
</LayoutComposer.Entry> |
|
51
|
)} |
|
52
|
|
|
53
|
<LayoutComposer.Entry id="JsonViewSection"> |
|
54
|
<JsonViewSection data={giftCard!} /> |
|
55
|
</LayoutComposer.Entry> |
|
56
|
</> |
|
57
|
), |
|
58
|
side: ( |
|
59
|
<> |
|
60
|
{storeCreditAccount && ( |
|
61
|
<LayoutComposer.Entry id="GiftCardBalanceSection"> |
|
62
|
<GiftCardBalanceSection |
|
63
|
storeCreditAccount={storeCreditAccount} |
|
64
|
giftCard={giftCard!} |
|
65
|
/> |
|
66
|
</LayoutComposer.Entry> |
|
67
|
)} |
|
68
|
|
|
69
|
<LayoutComposer.Entry id="GiftCardNoteSection"> |
|
70
|
<GiftCardNoteSection giftCard={giftCard!} /> |
|
71
|
</LayoutComposer.Entry> |
|
72
|
<LayoutComposer.Entry id="GiftCardOrderSection"> |
|
73
|
<GiftCardOrderSection giftCard={giftCard!} /> |
|
74
|
</LayoutComposer.Entry> |
|
75
|
</> |
|
76
|
), |
|
77
|
}} |
|
78
|
/> |
|
79
|
) |
|
80
|
} |
|
81
|
|
|
82
|
export default GiftCardDetailsPage |