'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { ArrowLeft, Copy, Check, Loader2, UserPlus, Share2, Globe, Lock, Mail, X, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; import { Avatar, AvatarFallback } from '@/components/ui/avatar'; interface ProjectMember { id: string; role: string; user: { id: string; name: string | null; email: string | null; }; } interface ProjectSharePageProps { projectId: string; } export default function ProjectSharePageClient({ projectId }: ProjectSharePageProps) { const [projectName, setProjectName] = useState(''); const [projectVisibility, setProjectVisibility] = useState(''); const [allowDownloads, setAllowDownloads] = useState(false); const [isLoading, setIsLoading] = useState(true); const [members, setMembers] = useState([]); const [copied, setCopied] = useState(false); const [error, setError] = useState(''); const [inviteEmail, setInviteEmail] = useState(''); const [isInviting, setIsInviting] = useState(false); const [inviteSuccess, setInviteSuccess] = useState(''); useEffect(() => { fetch(`/api/projects/${projectId}`) .then((res) => res.json()) .then((data) => { if (data.error) { setError(data.error); } else { const project = data.data; setProjectName(project.name || ''); setProjectVisibility(project.visibility || 'PRIVATE'); setAllowDownloads(project.allowDownloads ?? false); setMembers(project.members || []); } }) .catch(() => setError('Failed to load project')) .finally(() => setIsLoading(false)); }, [projectId]); const copyToClipboard = async (text: string) => { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const getDirectLink = () => { if (typeof window !== 'undefined') { return `${window.location.origin}/projects/${projectId}`; } return `/projects/${projectId}`; }; const handleInvite = async (e: React.FormEvent) => { e.preventDefault(); if (!inviteEmail.trim()) return; setIsInviting(true); setError(''); setInviteSuccess(''); try { // TODO: Implement invite API await new Promise((resolve) => setTimeout(resolve, 500)); setInviteSuccess(`Invitation sent to ${inviteEmail}`); setInviteEmail(''); setTimeout(() => setInviteSuccess(''), 3000); } catch { setError('Failed to send invitation'); } finally { setIsInviting(false); } }; const VisibilityIcon = () => { switch (projectVisibility) { case 'PUBLIC': return ; case 'INVITE': return ; default: return ; } }; const getVisibilityColor = () => { switch (projectVisibility) { case 'PUBLIC': return 'bg-green-500/10 text-green-500'; case 'INVITE': return 'bg-blue-500/10 text-blue-500'; default: return 'bg-orange-500/10 text-orange-500'; } }; const getVisibilityLabel = () => { switch (projectVisibility) { case 'PUBLIC': return { title: 'Public', description: 'Anyone with the link can view this project' }; case 'INVITE': return { title: 'Invite Only', description: 'Only people you invite can access' }; default: return { title: 'Private', description: 'Only you can access this project' }; } }; if (isLoading) { return (
); } const visibilityInfo = getVisibilityLabel(); return (
Back to Project
{/* Header Card */}
Share Project Share "{projectName}" with your team or clients
{/* Visibility Status */}
{visibilityInfo.title}
{visibilityInfo.description}
{(projectVisibility === 'PUBLIC' || projectVisibility === 'INVITE') && (
Viewer downloads:{' '} {allowDownloads ? 'enabled (includes anonymous visitors on public links)' : 'disabled'}
)}
{/* Invite People - Only show for INVITE visibility */} {projectVisibility === 'INVITE' && ( Invite People Send email invitations to specific people
setInviteEmail(e.target.value)} placeholder="email@example.com" className="h-11 flex-1" disabled={isInviting} />
{inviteSuccess && (
{inviteSuccess}
)} {/* Current Members */} {members.length > 0 && (
{members.map((member) => (
{member.user.name?.charAt(0) || member.user.email?.charAt(0) || '?'}
{member.user.name || 'Unknown'}
{member.user.email}
{member.role.toLowerCase()}
))}
)} {members.length === 0 && (

No members yet

Invite people to collaborate on this project

)}
)} {/* Public Link - Only show for PUBLIC visibility */} {projectVisibility === 'PUBLIC' && ( Public Link Share this link with anyone
)} {/* Private notice */} {projectVisibility === 'PRIVATE' && (

This project is private

Only you can access this project. Change visibility to share with others.

)} {error && (
{error}
)}
); }