'use client'; import * as React from 'react'; import { type DialogProps } from '@radix-ui/react-dialog'; import { toast } from 'react-hot-toast'; import { ServerActionResult, type Chat } from '@/lib/types'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { IconSpinner } from '@/components/ui/icons'; import { useCopyToClipboard } from '@/lib/hooks/use-copy-to-clipboard'; interface ChatShareDialogProps extends DialogProps { chat: Pick; shareChat: (id: string) => ServerActionResult; onCopy: () => void; } export function ChatShareDialog({ chat, shareChat, onCopy, ...props }: ChatShareDialogProps) { const { copyToClipboard } = useCopyToClipboard({ timeout: 1000 }); const [isSharePending, startShareTransition] = React.useTransition(); const copyShareLink = React.useCallback( async (chat: Chat) => { if (!chat.sharePath) { return toast.error('Could not copy share link to clipboard'); } const url = new URL(window.location.href); url.pathname = chat.sharePath; copyToClipboard(url.toString()); onCopy(); toast.success('Share link copied to clipboard', { style: { borderRadius: '10px', background: '#333', color: '#fff', fontSize: '14px', }, iconTheme: { primary: 'white', secondary: 'black', }, }); }, [copyToClipboard, onCopy], ); return ( Share link to chat Anyone with the URL will be able to view the shared chat.
{chat.title}
{chat.messages.length} messages
); }