"use client"; import { useState } from "react"; import type { Workspace } from "@mosaic/shared"; import { WorkspaceMemberRole } from "@mosaic/shared"; interface WorkspaceSettingsProps { workspace: Workspace; userRole: WorkspaceMemberRole; onUpdate: (name: string) => Promise; onDelete: () => Promise; } export function WorkspaceSettings({ workspace, userRole, onUpdate, onDelete, }: WorkspaceSettingsProps): React.JSX.Element { const [name, setName] = useState(workspace.name); const [isEditing, setIsEditing] = useState(false); const [isSaving, setIsSaving] = useState(false); const [isDeleting, setIsDeleting] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const canEdit = userRole === WorkspaceMemberRole.OWNER || userRole === WorkspaceMemberRole.ADMIN; const canDelete = userRole === WorkspaceMemberRole.OWNER; const handleSave = async (): Promise => { if (name.trim() === "" || name === workspace.name) { setIsEditing(false); setName(workspace.name); return; } setIsSaving(true); try { await onUpdate(name); setIsEditing(false); } catch (error) { console.error("Failed to update workspace:", error); alert("Failed to update workspace"); } finally { setIsSaving(false); } }; const handleDelete = async (): Promise => { setIsDeleting(true); try { await onDelete(); } catch (error) { console.error("Failed to delete workspace:", error); alert("Failed to delete workspace"); setIsDeleting(false); } }; return (

Workspace Settings

{/* Workspace Name */}
{isEditing ? (
{ setName(e.target.value); }} maxLength={100} disabled={isSaving} className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100" />
) : (

{workspace.name}

{canEdit && ( )}
)}
{/* Workspace ID */}
{workspace.id}
{/* Created Date */}

{new Date(workspace.createdAt).toLocaleString()}

{/* Delete Workspace */} {canDelete && (

Danger Zone

Deleting this workspace will permanently remove all associated data, including tasks, events, and projects. This action cannot be undone.

{showDeleteConfirm ? (

Are you sure you want to delete this workspace?

) : ( )}
)}
); }