-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreceive-payment.tsx
More file actions
159 lines (153 loc) · 4.28 KB
/
Copy pathreceive-payment.tsx
File metadata and controls
159 lines (153 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"use client";
import { useSearchParams } from "next/navigation";
import { QRCodeSVG } from "qrcode.react";
import type { FC, ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { ResponsiveCard } from "@/components/responsive-card";
import { Button } from "@/components/ui/button";
import { CardContent } from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useClipboard } from "@/hooks/use-clipboard";
import { useSetQueryParam } from "@/hooks/use-set-query-parameter";
import type { Currency, Integer } from "@/lib/shared/types";
import { formatMoney } from "@/lib/shared/utils/format";
export const ReceivePayment: FC<{
frontendUrl: string | undefined;
lnInvoice: string | undefined;
czechQRCode: string | undefined;
cashTabContent?: ReactNode;
key?: string;
totalAmount: Integer;
currency: Currency;
note?: string;
}> = ({
frontendUrl,
lnInvoice,
czechQRCode,
cashTabContent,
key,
totalAmount,
currency,
note,
}) => {
const finalKey = key ? `${key}.` : "";
const { t } = useTranslation();
const searchParams = useSearchParams();
const tab = searchParams.get(`${finalKey}tab`);
const setQueryParam = useSetQueryParam();
const { copy } = useClipboard();
return (
<Tabs value={tab ?? "web"} className="flex flex-col justify-start">
<TabsList>
<TabsTrigger
value="web"
onClick={() => setQueryParam(`${finalKey}tab`, null)}
>
{t("payments:detail.tabs.web-payment")}
</TabsTrigger>
{lnInvoice && (
<TabsTrigger
value="ln"
onClick={() => setQueryParam(`${finalKey}tab`, "ln")}
>
{t("payments:detail.tabs.btc-ln-payment")}
</TabsTrigger>
)}
{czechQRCode && (
<TabsTrigger
value="bankTransferCZ"
onClick={() => setQueryParam(`${finalKey}tab`, "bankTransferCZ")}
>
{t("payments:detail.tabs.cz-qr-payment")}
</TabsTrigger>
)}
{cashTabContent && (
<TabsTrigger
value="cash"
onClick={() => setQueryParam(`${finalKey}tab`, "cash")}
>
{t("payments:detail.tabs.cash")}
</TabsTrigger>
)}
</TabsList>
<div className={"flex flex-col items-center my-8 gap-4"}>
<strong className={"text-2xl"}>
{formatMoney({
value: totalAmount,
currency,
})}
</strong>
{note && (
<div className={"truncate w-full line-clamp-2 break-all text-xs"}>
{note}
</div>
)}
</div>
{frontendUrl && (
<TabsContent value="web">
<Button>
<QRCodeSVG size={512} value={frontendUrl} marginSize={2} />
</Button>
<ResponsiveCard className={"h-full flex"}>
<CardContent className={"flex"}>
<div className={"flex flex-1 flex-col gap-2"}>
<div
className={"rounded h-full flex justify-center items-center"}
>
<QRCodeSVG size={512} value={frontendUrl} marginSize={2} />
</div>
</div>
</CardContent>
</ResponsiveCard>
</TabsContent>
)}
{lnInvoice && (
<TabsContent value="ln">
<Button
className={
"w-full aspect-square h-auto p-6 bg-white dark:bg-white dark:hover:bg-gray-300"
}
variant={"outline"}
onClick={() =>
copy(lnInvoice, {
customMessage: t(
"payments:detail.messages.ln-invoice-copied-to-clipboard",
),
})
}
>
<QRCodeSVG
className={"w-full h-full size-6"}
size={512}
value={lnInvoice}
/>
</Button>
</TabsContent>
)}
{czechQRCode && (
<TabsContent value="bankTransferCZ" className={"h-full"}>
<ResponsiveCard className={"h-full flex"}>
<CardContent className={"flex"}>
<div className={"flex flex-1 flex-col gap-2"}>
<div
className={"rounded h-full flex justify-center items-center"}
>
<QRCodeSVG size={512} value={czechQRCode} marginSize={2} />
</div>
</div>
</CardContent>
</ResponsiveCard>
</TabsContent>
)}
{cashTabContent && (
<TabsContent value="cash" className={"h-full"}>
<ResponsiveCard className={"h-full flex"}>
<CardContent className={"flex items-center justify-center"}>
<div className={"w-full max-w-sm"}>{cashTabContent}</div>
</CardContent>
</ResponsiveCard>
</TabsContent>
)}
</Tabs>
);
};