Skip to content

Commit 20d0a25

Browse files
committed
ui: use dialog for invite popup
1 parent 1117555 commit 20d0a25

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

browser-chat/frontend/src/app.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ function App({ api }: AppProps) {
159159
{showLogView && <LogView onClose={() => setShowLogView(false)} />}
160160
{showInvitePopup && activeChannel && (
161161
<InvitePopup
162-
onClose={() => setShowInvitePopup(false)}
162+
open={showInvitePopup}
163+
onOpenChange={(x) => {
164+
console.log("openchange", x)
165+
setShowInvitePopup(x)
166+
}}
163167
channel={channels.find((c) => c.id === activeChannel)?.name || ""}
164168
getTicket={(opts) => api.getTicket(activeChannel!, opts)}
165169
/>

browser-chat/frontend/src/components/invitepopup.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { useState, useRef, useMemo } from "react"
44
import { Button } from "@/components/ui/button"
55
import { Checkbox } from "@/components/ui/checkbox"
66
import { Input } from "@/components/ui/input"
7+
import {
8+
Dialog,
9+
DialogContent,
10+
DialogFooter,
11+
DialogHeader,
12+
DialogTitle,
13+
DialogTrigger,
14+
} from "@/components/ui/dialog"
715
import { Copy } from "lucide-react"
816
import { TicketOpts } from "@/lib/api"
917

@@ -14,7 +22,8 @@ function ticketUrl(ticket: string) {
1422
}
1523

1624
interface InvitePopupProps {
17-
onClose: () => void
25+
open: boolean
26+
onOpenChange: (open: boolean) => void
1827
channel: string
1928
getTicket: (options: {
2029
includeMyself: boolean
@@ -23,7 +32,7 @@ interface InvitePopupProps {
2332
}) => string
2433
}
2534

26-
export function InvitePopup({ onClose, channel, getTicket }: InvitePopupProps) {
35+
export function InvitePopup({ open, onOpenChange, channel, getTicket }: InvitePopupProps) {
2736
const [ticketOptions, setTicketOptions] = useState<TicketOpts>({
2837
includeMyself: true,
2938
includeBootstrap: true,
@@ -40,27 +49,27 @@ export function InvitePopup({ onClose, channel, getTicket }: InvitePopupProps) {
4049
const cliCommand = `cargo run -- join ${ticket}`
4150

4251
return (
43-
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
44-
<div className="bg-background text-foreground p-6 rounded-lg w-full max-w-md shadow-lg border-2 border-primary/10">
45-
<h2 className="text-xl font-semibold mb-4">Invite to Channel</h2>
52+
<Dialog open={open} onOpenChange={onOpenChange}>
53+
<DialogTitle>Invite to channel</DialogTitle>
54+
<DialogContent>
4655
<div className="mb-4">
47-
<p className="font-semibold mb-2">Ticket:</p>
56+
<p className="font-semibold mb-2">Ticket</p>
4857
<div className="flex items-center">
49-
<span className="mr-2">{ticket.substring(0, 8)}...</span>
58+
<span className="mr-2 font-mono">{ticket.substring(0, 16)}...</span>
5059
<Button variant="outline" size="sm" onClick={() => copyToClipboard(ticket)}>
5160
<Copy className="w-4 h-4 mr-2" />
5261
Copy
5362
</Button>
5463
</div>
5564
</div>
5665
<div className="mb-4">
57-
<p className="font-semibold mb-2">Join Link:</p>
66+
<p className="font-semibold mb-2">Join link</p>
5867
<a href={ticketUrl(ticket)} className="text-blue-500 hover:underline" target="_blank">
59-
{ticketUrl(ticket.substring(0, 8))}...
68+
{ticketUrl(ticket.substring(0, 16))}...
6069
</a>
6170
</div>
6271
<div className="mb-4">
63-
<p className="font-semibold mb-2">Join from CLI:</p>
72+
<p className="font-semibold mb-2">Join from the command line</p>
6473
<Input
6574
ref={cliCommandRef}
6675
value={cliCommand}
@@ -74,7 +83,7 @@ export function InvitePopup({ onClose, channel, getTicket }: InvitePopupProps) {
7483
</Button>
7584
</div>
7685
<div className="mb-4">
77-
<h3 className="font-semibold mb-2">Configure Ticket:</h3>
86+
<h3 className="font-semibold mb-2">Configure ticket</h3>
7887
<div className="space-y-2">
7988
<div className="flex items-center">
8089
<Checkbox
@@ -110,9 +119,9 @@ export function InvitePopup({ onClose, channel, getTicket }: InvitePopupProps) {
110119
</div>
111120
{/* <Button onClick={generateTicket}>Generate Ticket</Button> */}
112121
<div className="flex justify-end">
113-
<Button onClick={onClose}>Close</Button>
122+
<Button onClick={(_) => onOpenChange(false)}>Close</Button>
114123
</div>
115-
</div>
116-
</div>
124+
</DialogContent>
125+
</Dialog>
117126
)
118127
}

0 commit comments

Comments
 (0)