Skip to content

Commit ccedf35

Browse files
committed
feat: qr code
1 parent c312102 commit ccedf35

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

bun.lockb

388 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"prettier": "^3.0.3",
6161
"prettier-plugin-organize-imports": "^3.2.3",
6262
"prettier-plugin-tailwindcss": "^0.5.6",
63+
"qrcode.react": "^3.1.0",
6364
"react": "^18.2.0",
6465
"react-dom": "^18.2.0",
6566
"react-hook-form": "^7.47.0",

src/app/(protected)/network/page.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ModalHeader,
1313
Select,
1414
SelectItem,
15+
Snippet,
1516
Table,
1617
TableBody,
1718
TableCell,
@@ -20,9 +21,10 @@ import {
2021
TableRow,
2122
useDisclosure
2223
} from '@nextui-org/react'
23-
import { IconPlus, IconRefresh, IconTrash } from '@tabler/icons-react'
24+
import { IconPlus, IconQrcode, IconRefresh, IconTrash } from '@tabler/icons-react'
2425
import dayjs from 'dayjs'
2526
import { differenceWith } from 'lodash'
27+
import { QRCodeSVG } from 'qrcode.react'
2628
import { FC, Fragment, Key, useCallback, useMemo } from 'react'
2729
import { useTranslation } from 'react-i18next'
2830
import {
@@ -44,6 +46,7 @@ type Node = {
4446
name: string
4547
tag?: string | null
4648
protocol: string
49+
link: string
4750
subscriptionID?: string | null
4851
}
4952

@@ -226,6 +229,35 @@ const GroupContent: FC<{
226229
)
227230
}
228231

232+
const CheckNodeQRCodeButton: FC<{ name: string; link: string }> = ({ name, link }) => {
233+
const {
234+
isOpen: isCheckNodeQRCodeOpen,
235+
onOpenChange: onCheckNodeQRCodeOpenChange,
236+
onOpen: onCheckNodeQRCodeOpen
237+
} = useDisclosure()
238+
239+
return (
240+
<Fragment>
241+
<Button color="primary" isIconOnly onPress={onCheckNodeQRCodeOpen}>
242+
<IconQrcode />
243+
</Button>
244+
245+
<Modal isOpen={isCheckNodeQRCodeOpen} onOpenChange={onCheckNodeQRCodeOpenChange}>
246+
<ModalContent>
247+
<ModalHeader>{name}</ModalHeader>
248+
<ModalBody className="flex flex-col items-center gap-8 p-8">
249+
<QRCodeSVG className="h-64 w-64" value={link} />
250+
251+
<Snippet symbol={false} variant="bordered">
252+
<span className="whitespace-break-spaces break-all">{link}</span>
253+
</Snippet>
254+
</ModalBody>
255+
</ModalContent>
256+
</Modal>
257+
</Fragment>
258+
)
259+
}
260+
229261
const RemoveNodeButton: FC<{ id: string; name: string; refetch: () => Promise<unknown> }> = ({ id, name, refetch }) => {
230262
const { t } = useTranslation()
231263

@@ -297,7 +329,13 @@ const NodeTable: FC<{
297329
return item.tag || item.name
298330

299331
case 'action':
300-
return <RemoveNodeButton id={item.id} name={item.tag || item.name} refetch={refetch} />
332+
return (
333+
<div className="flex items-center gap-2">
334+
<CheckNodeQRCodeButton name={item.tag || item.name} link={item.link} />
335+
336+
<RemoveNodeButton id={item.id} name={item.tag || item.name} refetch={refetch} />
337+
</div>
338+
)
301339

302340
default:
303341
return getKeyValue(item, columnKey)

0 commit comments

Comments
 (0)