mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
refactor(monorepo): decouple api and webui into workspaces packages
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { DualSidebar, DualSidebarItem } from '@/ui/components/dual-sidebar'
|
||||
import { NotificationList } from '@/ui/components/notification-list'
|
||||
import { TopNav } from '@/ui/components/top-nav'
|
||||
import { HomeIcon, NotificationFillIcon, UploadCloudIcon } from '@/ui/components/ui/icons'
|
||||
import { Toaster } from '@/ui/components/ui/sonner'
|
||||
import { UploadTasks } from '@/ui/components/upload-tasks'
|
||||
import { useAuthStore } from '@/ui/stores/auth'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useUploadStore } from '@/ui/stores/upload'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import {
|
||||
createRootRouteWithContext,
|
||||
Outlet,
|
||||
useNavigate,
|
||||
useRouterState,
|
||||
} from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
function RootComponent() {
|
||||
const user = useAuthStore((state) => state.user)
|
||||
const { uploading } = useUploadStore()
|
||||
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
||||
const navigate = useNavigate()
|
||||
|
||||
const showSidebar = user && (pathname.startsWith('/teams/') || pathname.startsWith('/projects/'))
|
||||
|
||||
if (!showSidebar) {
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
// Extract teamId from pathname if possible
|
||||
// Matches /teams/:teamId
|
||||
const teamIdMatch = pathname.match(/^\/teams\/([^/]+)/)
|
||||
const teamId = teamIdMatch ? teamIdMatch[1] : null
|
||||
|
||||
const projectIdMatch = pathname.match(/^\/projects\/([^/]+)/)
|
||||
const projectId = projectIdMatch ? projectIdMatch[1] : null
|
||||
|
||||
const { teamId: storedTeamId, setTeamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
if (teamId) {
|
||||
setTeamId(teamId)
|
||||
} else if (projectId) {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}
|
||||
}, [teamId, projectId, setTeamId, ensureTeamIdForProject])
|
||||
|
||||
const { data: me } = useQuery({
|
||||
queryKey: ['teams', storedTeamId, 'me'],
|
||||
queryFn: async () => {
|
||||
if (!storedTeamId) return null
|
||||
const res = await client.api.teams[':teamId'].me.$get({
|
||||
param: { teamId: storedTeamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch me')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!storedTeamId,
|
||||
})
|
||||
|
||||
const unreadCount = me?.unreadNotificationCount ?? 0
|
||||
const displayCount = unreadCount > 99 ? '99+' : unreadCount
|
||||
const badge =
|
||||
unreadCount > 0 ? (
|
||||
<div className="absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 bg-red-500 text-white rounded-full flex items-center justify-center text-[10px] font-bold border-2 border-slate-100 dark:border-slate-900 animate-pulse">
|
||||
{displayCount}
|
||||
</div>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-full bg-background overflow-hidden">
|
||||
<Toaster />
|
||||
<DualSidebar>
|
||||
<DualSidebarItem
|
||||
icon={<HomeIcon />}
|
||||
label="Dashboard"
|
||||
onItemClick={() => {
|
||||
if (storedTeamId) {
|
||||
navigate({
|
||||
to: '/teams/$teamId',
|
||||
params: { teamId: storedTeamId },
|
||||
})
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications" badge={badge}>
|
||||
<NotificationList />
|
||||
</DualSidebarItem>
|
||||
<DualSidebarItem
|
||||
icon={
|
||||
<UploadCloudIcon
|
||||
uploading={uploading > 0}
|
||||
className={uploading > 0 ? 'text-blue-500' : ''}
|
||||
/>
|
||||
}
|
||||
label="Uploads"
|
||||
>
|
||||
<UploadTasks />
|
||||
</DualSidebarItem>
|
||||
</DualSidebar>
|
||||
<div className="flex flex-col flex-1 md:pl-16 overflow-hidden relative">
|
||||
<TopNav />
|
||||
<main className="flex-1 overflow-hidden relative flex flex-col">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
import { QueryClient } from '@tanstack/react-query'
|
||||
|
||||
interface MyRouterContext {
|
||||
queryClient: QueryClient
|
||||
}
|
||||
|
||||
export const Route = createRootRouteWithContext<MyRouterContext>()({
|
||||
component: RootComponent,
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import { TeamSelector } from '@/ui/components/team-selector'
|
||||
import { useAuthStore } from '@/ui/stores/auth'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
function IndexPage() {
|
||||
const user = useAuthStore((state) => state.user)
|
||||
const navigate = useNavigate()
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) {
|
||||
navigate({
|
||||
to: '/login',
|
||||
})
|
||||
}
|
||||
}, [user, navigate])
|
||||
|
||||
if (!user) return null
|
||||
|
||||
return <TeamSelector />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/')({
|
||||
component: IndexPage,
|
||||
})
|
||||
@@ -0,0 +1,251 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Label } from '@/ui/components/ui/label'
|
||||
import { useAuthStore } from '@/ui/stores/auth'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute, redirect, useNavigate } from '@tanstack/react-router'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
import { signIn } from '@/ui/lib/auth-client'
|
||||
import { Loader2, Mail, Lock, ArrowRight, LogIn, CheckCircle2 } from 'lucide-react'
|
||||
import { ShumaiLogo } from '@/ui/components/ui/icons'
|
||||
|
||||
const loginSchema = z.object({
|
||||
email: z.string().email('Invalid email address'),
|
||||
password: z.string().min(1, 'Password is required'),
|
||||
})
|
||||
|
||||
type LoginSchema = z.infer<typeof loginSchema>
|
||||
|
||||
function LoginPage() {
|
||||
const navigate = useNavigate()
|
||||
const setUser = useAuthStore((state) => state.setUser)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const { data: signupInfo, isLoading: isSignupInfoLoading } = useQuery({
|
||||
queryKey: ['/signup-info'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api['signup-info'].$get()
|
||||
if (!res.ok) throw new Error('Failed to fetch signup info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (signupInfo?.userCount === 0) {
|
||||
navigate({ to: '/signup', search: { inviteCode: '' } })
|
||||
}
|
||||
}, [signupInfo, navigate])
|
||||
|
||||
const form = useForm<LoginSchema>({
|
||||
resolver: zodResolver(loginSchema),
|
||||
})
|
||||
|
||||
const onSubmit = async (data: LoginSchema) => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
const { data: session, error: signInError } = await signIn.email({
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
})
|
||||
|
||||
setLoading(false)
|
||||
if (signInError) {
|
||||
setError(signInError.message || 'Invalid credentials')
|
||||
return
|
||||
}
|
||||
|
||||
if (session) {
|
||||
setUser(session.user)
|
||||
navigate({ to: '/' })
|
||||
}
|
||||
}
|
||||
|
||||
if (isSignupInfoLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-zinc-100/80 dark:bg-black">
|
||||
<div className="relative flex flex-col items-center">
|
||||
<ShumaiLogo className="h-16 w-16 animate-pulse mb-4 text-rose-500 shadow-xl rounded-2xl" />
|
||||
<Loader2 className="h-6 w-6 animate-spin text-rose-500/70" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen w-full flex items-center justify-center p-4 md:p-8 bg-zinc-100/80 dark:bg-black font-sans overflow-hidden relative font-sans">
|
||||
{/* Drifting Background Mesh Blobs */}
|
||||
<div className="bg-rose-500/10 dark:bg-rose-600/5 w-[600px] h-[600px] rounded-full blur-[140px] absolute top-[-10%] left-[-10%] animate-drift-slow" />
|
||||
<div className="bg-orange-500/10 dark:bg-orange-600/5 w-[600px] h-[600px] rounded-full blur-[140px] absolute bottom-[-10%] right-[-10%] animate-drift-medium" />
|
||||
|
||||
{/* Main Glassmorphic Split-Pane Card */}
|
||||
<div className="relative max-w-4xl w-full flex flex-col md:flex-row rounded-3xl border border-zinc-200 dark:border-zinc-800 shadow-2xl bg-white dark:bg-zinc-900 overflow-hidden min-h-[580px] z-10 transition-all duration-300 hover:shadow-rose-500/5">
|
||||
{/* Left Pane (Brand Showcase) */}
|
||||
<div className="w-full md:w-1/2 bg-gradient-to-br from-rose-500/15 via-orange-500/10 to-amber-500/5 dark:from-rose-950/30 dark:via-orange-950/15 dark:to-zinc-900/40 p-8 md:p-12 flex flex-col justify-between border-b md:border-b-0 md:border-r border-zinc-200 dark:border-zinc-800 relative overflow-hidden">
|
||||
{/* Subtle Grid Overlay */}
|
||||
<div className="absolute inset-0 bg-[linear-gradient(to_right,#8080800a_1px,transparent_1px),linear-gradient(to_bottom,#8080800a_1px,transparent_1px)] bg-[size:14px_24px] [mask-image:radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)] pointer-events-none" />
|
||||
|
||||
{/* Logo & Brand */}
|
||||
<div className="relative flex items-center gap-3">
|
||||
<ShumaiLogo className="h-12 w-12 shadow-lg shadow-rose-500/10 rounded-2xl transition-transform duration-500 hover:scale-105" />
|
||||
<span className="text-xl font-extrabold tracking-tight bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500 bg-clip-text text-transparent">
|
||||
Shumai
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Marketing Copy / Feature Points */}
|
||||
<div className="relative my-8 md:my-0 space-y-6">
|
||||
<h2 className="text-3xl font-extrabold tracking-tight leading-tight text-zinc-900 dark:text-zinc-50">
|
||||
One workspace
|
||||
<br />
|
||||
for all your
|
||||
<br />
|
||||
<span className="bg-gradient-to-r from-rose-500 to-orange-500 bg-clip-text text-transparent">
|
||||
creative assets.
|
||||
</span>
|
||||
</h2>
|
||||
<p className="text-zinc-600 dark:text-zinc-400 text-sm leading-relaxed max-w-sm">
|
||||
Upload and index your files, enrich them with custom metadata schemas, draw
|
||||
annotations directly on media, and gather instant feedback — all in one modern
|
||||
workspace built for creators.
|
||||
</p>
|
||||
|
||||
<ul className="space-y-3.5 pt-4">
|
||||
{[
|
||||
'Instant asset uploads & high-fidelity media players',
|
||||
'Custom metadata schemas & drawing canvas reviews',
|
||||
'Frictionless team workspaces & secure sharing',
|
||||
].map((text, i) => (
|
||||
<li
|
||||
key={i}
|
||||
className="flex items-center gap-3 text-sm text-zinc-700 dark:text-zinc-300 font-medium"
|
||||
>
|
||||
<CheckCircle2 className="w-5 h-5 text-rose-500 flex-shrink-0" />
|
||||
<span>{text}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Footer Label */}
|
||||
<div className="relative pt-4 border-t border-zinc-200/30 dark:border-zinc-800/30">
|
||||
<p className="text-xs text-zinc-500 dark:text-zinc-400 font-medium">
|
||||
Join our community of developers and designers.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Pane (Form Container) */}
|
||||
<div className="w-full md:w-1/2 p-8 md:p-12 flex flex-col justify-center">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold tracking-tight text-zinc-900 dark:text-zinc-50">
|
||||
Welcome Back
|
||||
</h1>
|
||||
<p className="text-zinc-500 dark:text-zinc-400 text-sm mt-1">
|
||||
Enter your credentials to access your account.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="mb-6 p-3 bg-red-500/10 border border-red-500/20 text-red-600 dark:text-red-400 rounded-xl text-sm text-center font-medium">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-5">
|
||||
<div className="space-y-2">
|
||||
<Label
|
||||
htmlFor="email"
|
||||
className="text-xs font-semibold text-zinc-600 dark:text-zinc-400 tracking-wide uppercase"
|
||||
>
|
||||
Email Address
|
||||
</Label>
|
||||
<div className="relative group">
|
||||
<Mail className="absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400 dark:text-zinc-600 transition-colors group-focus-within:text-rose-500" />
|
||||
<Input
|
||||
id="email"
|
||||
{...form.register('email')}
|
||||
placeholder="you@example.com"
|
||||
type="email"
|
||||
className="pl-10.5 h-11 border-zinc-200 dark:border-zinc-800 focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.email && (
|
||||
<p className="text-red-500 text-xs font-medium">
|
||||
{form.formState.errors.email.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label
|
||||
htmlFor="password"
|
||||
className="text-xs font-semibold text-zinc-600 dark:text-zinc-400 tracking-wide uppercase"
|
||||
>
|
||||
Password
|
||||
</Label>
|
||||
<div className="relative group">
|
||||
<Lock className="absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400 dark:text-zinc-600 transition-colors group-focus-within:text-rose-500" />
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
{...form.register('password')}
|
||||
placeholder="Your password"
|
||||
className="pl-10.5 h-11 border-zinc-200 dark:border-zinc-800 focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.password && (
|
||||
<p className="text-red-500 text-xs font-medium">
|
||||
{form.formState.errors.password.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
Logging in...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<LogIn className="w-4 h-4" />
|
||||
Login
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="mt-8 pt-6 border-t border-zinc-200/30 dark:border-zinc-800/30 text-center text-sm">
|
||||
<span className="text-zinc-500 dark:text-zinc-400">Don't have an account? </span>
|
||||
<a
|
||||
href="/signup"
|
||||
className="font-semibold text-rose-500 hover:text-rose-600 dark:text-rose-400 dark:hover:text-rose-300 transition-colors hover:underline inline-flex items-center gap-0.5"
|
||||
>
|
||||
Sign up <ArrowRight className="w-3.5 h-3.5" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/login')({
|
||||
component: LoginPage,
|
||||
beforeLoad: () => {
|
||||
if (useAuthStore.getState().user) {
|
||||
throw redirect({
|
||||
to: '/',
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,98 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useMutation, useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const collectionInfoQueryOptions = (collectionId: string) => ({
|
||||
queryKey: ['collections', collectionId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.collections[':collectionId'].$get({
|
||||
param: { collectionId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch collection')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
function CollectionPage() {
|
||||
const { projectId, collectionId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const { data: collection, refetch: refetchCollection } = useQuery({
|
||||
...collectionInfoQueryOptions(collectionId),
|
||||
})
|
||||
|
||||
const { mutate: updateCollection } = useMutation({
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mutationFn: async (updates: { name?: string; filter?: any }) => {
|
||||
const res = await client.api.collections[':collectionId'].$patch({
|
||||
param: { collectionId },
|
||||
json: updates,
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update collection')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
refetchCollection()
|
||||
},
|
||||
})
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch folder')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder || !collection) {
|
||||
return <div>Loading collection...</div>
|
||||
}
|
||||
|
||||
const sourceFolderId = collection.filter.sourceFolderId || rootFolderId
|
||||
|
||||
return (
|
||||
<FileSystemManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
assetId={sourceFolderId}
|
||||
rootFolderId={rootFolderId}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
collection={collection as any}
|
||||
onUpdateCollection={updateCollection}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/collections/$collectionId')({
|
||||
component: CollectionPage,
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <div>Loading collection...</div>,
|
||||
})
|
||||
@@ -0,0 +1,302 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { FileViewer } from '@/ui/components/file-viewer'
|
||||
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
||||
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
||||
import { ResizeHandle } from '@/ui/components/resize-handle'
|
||||
import { useMemberStore } from '@/ui/stores/members'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useTopNavStore } from '@/ui/stores/top-nav'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import { type Annotation } from '@/ui/types'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||
|
||||
import type { AssetInfo, CommentInfo } from '@shumai/dtos'
|
||||
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
|
||||
function FileViewPage() {
|
||||
const { projectId, fileId } = Route.useParams()
|
||||
const search = Route.useSearch()
|
||||
const versionAssetId = (search as { version?: string }).version
|
||||
const activeFileId = versionAssetId || fileId
|
||||
|
||||
const videoRef = useRef<Player | null>(null)
|
||||
const {
|
||||
fileViewRightSidebarCollapsed: isRightSidebarCollapsed,
|
||||
fileViewLeftSidebarCollapsed: isLeftSidebarCollapsed,
|
||||
setFileViewLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
||||
} = useUiStore()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
const [leftSidebarWidth, setLeftSidebarWidth] = useState(280)
|
||||
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||
const { mutate: patchMetadata } = useMutation<
|
||||
InferResponseType<typeof $patchMetadata>,
|
||||
Error,
|
||||
InferRequestType<typeof $patchMetadata>
|
||||
>({
|
||||
mutationFn: async (request) => {
|
||||
const res = await $patchMetadata(request)
|
||||
if (!res.ok) throw new Error('Failed to patch metadata')
|
||||
return (await res.json()) as unknown as InferResponseType<typeof $patchMetadata>
|
||||
},
|
||||
})
|
||||
const queryClient = useQueryClient()
|
||||
const { members, fetchMembers } = useMemberStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
useEffect(() => {
|
||||
if (teamId) {
|
||||
fetchMembers(teamId, true)
|
||||
}
|
||||
}, [teamId, fetchMembers])
|
||||
|
||||
const {
|
||||
data: stackData,
|
||||
isLoading: isStackLoading,
|
||||
isError: isStackError,
|
||||
isFetching: isStackFetching,
|
||||
} = useQuery({
|
||||
queryKey: ['files', fileId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.files[':fileId'].$get({
|
||||
param: { fileId: fileId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch stack')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!teamId,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
|
||||
const {
|
||||
data: versionData,
|
||||
isLoading: isVersionLoading,
|
||||
isError: isVersionError,
|
||||
isFetching: isVersionFetching,
|
||||
} = useQuery({
|
||||
queryKey: ['files', versionAssetId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.files[':fileId'].$get({
|
||||
param: { fileId: versionAssetId! },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch version')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!teamId && !!versionAssetId,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
|
||||
const { data: versionsList } = useQuery({
|
||||
queryKey: ['version_stacks', fileId, 'versions'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.version_stacks[':stackId'].versions.$get({
|
||||
param: { stackId: fileId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch versions')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!projectId && !!fileId && !!versionAssetId,
|
||||
})
|
||||
|
||||
const { data: projectInfo } = useQuery({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const navigate = useNavigate()
|
||||
const { setProjectState, clearProjectState } = useTopNavStore()
|
||||
|
||||
const isLoading = isStackLoading || (!!versionAssetId && isVersionLoading)
|
||||
const isError = isStackError || (!!versionAssetId && isVersionError)
|
||||
const isFetching = isStackFetching || (!!versionAssetId && isVersionFetching)
|
||||
const fileData = versionData || stackData
|
||||
const versionsDataList = versionAssetId ? versionsList : stackData?.versionStack?.versions
|
||||
|
||||
useEffect(() => {
|
||||
if (fileData && projectInfo && teamId) {
|
||||
setProjectState({
|
||||
teamId,
|
||||
projectId,
|
||||
projectName: projectInfo.name ?? '',
|
||||
ancestorFolders: fileData.ancestorFolders ?? [],
|
||||
currentAsset: {
|
||||
name: fileData.name,
|
||||
type: 'file',
|
||||
version: versionsDataList
|
||||
? (versionsDataList.find((v: { id: string }) => v.id === activeFileId)?.version ??
|
||||
versionsDataList.length)
|
||||
: undefined,
|
||||
},
|
||||
isRootFolder: false,
|
||||
fileId,
|
||||
versions: versionsDataList,
|
||||
onFolderClick: (id: string) => {
|
||||
navigate({
|
||||
to: '/projects/$projectId/folders/$folderId',
|
||||
params: { projectId, folderId: id },
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return () => clearProjectState()
|
||||
}, [
|
||||
teamId,
|
||||
projectId,
|
||||
projectInfo,
|
||||
fileData,
|
||||
versionsDataList,
|
||||
activeFileId,
|
||||
fileId,
|
||||
setProjectState,
|
||||
clearProjectState,
|
||||
navigate,
|
||||
])
|
||||
|
||||
if (isLoading && !fileData) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
|
||||
if (isError || !fileData || !projectInfo || !teamId) {
|
||||
return <div>File not found.</div>
|
||||
}
|
||||
|
||||
const handleSaveField = (fieldId: string, value: unknown) => {
|
||||
if (!teamId) return
|
||||
patchMetadata(
|
||||
{
|
||||
param: { fileId: activeFileId },
|
||||
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['files', activeFileId],
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const handleCommentSelect = (comment: CommentInfo) => {
|
||||
setSelectedCommentId(comment.id || null)
|
||||
const newAnnotations = comment.annotations as Annotation[]
|
||||
if (newAnnotations && newAnnotations.length > 0) {
|
||||
setAnnotations(newAnnotations)
|
||||
} else {
|
||||
setAnnotations([])
|
||||
}
|
||||
|
||||
if (comment.second !== null && comment.second !== undefined) {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.currentTime(comment.second)
|
||||
videoRef.current.pause()
|
||||
}
|
||||
} else if (newAnnotations && newAnnotations.length > 0) {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.pause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handlePlay = () => {
|
||||
setAnnotations([])
|
||||
setSelectedCommentId(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-1 flex-col bg-background">
|
||||
<div className="h-full flex flex-1 overflow-hidden">
|
||||
{!isLeftSidebarCollapsed && (
|
||||
<>
|
||||
<div style={{ width: leftSidebarWidth }} className="flex-shrink-0">
|
||||
<FileViewerLeftSidebar
|
||||
projectId={projectId}
|
||||
currentAssetId={activeFileId}
|
||||
parentFolderId={
|
||||
fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ??
|
||||
projectInfo.rootFolder ??
|
||||
''
|
||||
}
|
||||
onCollapse={() => setIsLeftSidebarCollapsed(true)}
|
||||
/>
|
||||
</div>
|
||||
<ResizeHandle
|
||||
onResize={(delta) => {
|
||||
setLeftSidebarWidth((prev) => Math.max(200, Math.min(500, prev + delta)))
|
||||
}}
|
||||
className="hidden md:block"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div className="flex-1 relative">
|
||||
{isFetching && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
<FileViewer
|
||||
file={fileData as unknown as AssetInfo}
|
||||
videoRef={videoRef}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
annotations={annotations}
|
||||
/>
|
||||
</div>
|
||||
{!isRightSidebarCollapsed && (
|
||||
<>
|
||||
<ResizeHandle
|
||||
onResize={(delta) => {
|
||||
setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta)))
|
||||
}}
|
||||
className="hidden md:block"
|
||||
/>
|
||||
<div style={{ width: rightSidebarWidth }} className="flex-shrink-0">
|
||||
<FileViewerRightSidebar
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
file={fileData as unknown as AssetInfo}
|
||||
onSaveField={handleSaveField}
|
||||
members={members}
|
||||
onCommentSelect={handleCommentSelect}
|
||||
currentTime={currentTime}
|
||||
onTyping={() => {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.pause()
|
||||
}
|
||||
}}
|
||||
selectedCommentId={selectedCommentId}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
||||
component: FileViewPage,
|
||||
validateSearch: (search: Record<string, unknown>) => {
|
||||
return {
|
||||
version: (search.version as string) || undefined,
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
function FolderPage() {
|
||||
const { projectId, folderId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: () =>
|
||||
(async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
return await res.json()
|
||||
})(),
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder) {
|
||||
return <div>Loading project...</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<FileSystemManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
assetId={folderId}
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/folders/$folderId')({
|
||||
component: FolderPage,
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <div>Loading project...</div>,
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
function ProjectPage() {
|
||||
const { projectId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to fetch folder')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder) {
|
||||
return <div>Loading project...</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<FileSystemManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
assetId={rootFolderId}
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/')({
|
||||
component: ProjectPage,
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <div>Loading project...</div>,
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
function RecentlyDeletedPage() {
|
||||
const { projectId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: () =>
|
||||
(async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
return await res.json()
|
||||
})(),
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder) {
|
||||
return <div>Loading project...</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<FileSystemManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
assetId="recently-deleted"
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/recently-deleted')({
|
||||
component: RecentlyDeletedPage,
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <div>Loading project...</div>,
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import ShareManager from '@/ui/components/share-manager'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
function SharePage() {
|
||||
const { projectId, shareId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch folder')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder) {
|
||||
return <div>Loading project...</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<ShareManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
shareId={shareId}
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/shares/$shareId')({
|
||||
component: SharePage,
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <div>Loading share link...</div>,
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute, Outlet } from '@tanstack/react-router'
|
||||
|
||||
function ShareLayout() {
|
||||
const { shareId } = Route.useParams()
|
||||
|
||||
const {
|
||||
data: shareInfo,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (isLoading) return <div className="flex h-screen items-center justify-center">Loading...</div>
|
||||
if (error || !shareInfo)
|
||||
return (
|
||||
<div className="flex h-screen items-center justify-center text-destructive">
|
||||
Share not found or inaccessible.
|
||||
</div>
|
||||
)
|
||||
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId')({
|
||||
component: ShareLayout,
|
||||
beforeLoad: ({ params: { shareId } }) => {
|
||||
return {
|
||||
password: localStorage.getItem(`share_pwd_${shareId}`) || '',
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareFilePage() {
|
||||
const { shareId, fileId } = Route.useParams()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFileId={fileId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
||||
component: PublicShareFilePage,
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareFolderPage() {
|
||||
const { shareId, folderId } = Route.useParams()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFolderId={folderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/folders/$folderId')({
|
||||
component: PublicShareFolderPage,
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareIndexPage() {
|
||||
const { shareId } = Route.useParams()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFolderId={shareInfo.rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/')({
|
||||
component: PublicShareIndexPage,
|
||||
})
|
||||
@@ -0,0 +1,332 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Label } from '@/ui/components/ui/label'
|
||||
import { Loader2, Mail, Lock, CheckCircle2, ArrowRight, UserPlus } from 'lucide-react'
|
||||
import { useAuthStore } from '@/ui/stores/auth'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute, redirect, useNavigate } from '@tanstack/react-router'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
import { signUp } from '@/ui/lib/auth-client'
|
||||
import { useState } from 'react'
|
||||
import { ShumaiLogo } from '@/ui/components/ui/icons'
|
||||
|
||||
const signupSchema = z.object({
|
||||
email: z.string().email('Invalid email address'),
|
||||
password: z.string().min(3, 'Password must be at least 3 characters'),
|
||||
inviteCode: z.string().optional(),
|
||||
})
|
||||
|
||||
type SignupSchema = z.infer<typeof signupSchema>
|
||||
|
||||
function SignupPage() {
|
||||
const navigate = useNavigate()
|
||||
const search = Route.useSearch()
|
||||
const inviteCode = (search as { inviteCode?: string }).inviteCode
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const { data: inviteInfo } = useQuery({
|
||||
queryKey: ['invite', inviteCode],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.invite[':code'].$get({
|
||||
param: { code: inviteCode! },
|
||||
})
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed to fetch invite info')
|
||||
}
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!inviteCode,
|
||||
})
|
||||
|
||||
const { data: signupInfo, isLoading: isSignupInfoLoading } = useQuery({
|
||||
queryKey: ['/signup-info'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api['signup-info'].$get()
|
||||
if (!res.ok) throw new Error('Failed to fetch signup info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const setUser = useAuthStore((state) => state.setUser)
|
||||
|
||||
const form = useForm<SignupSchema>({
|
||||
resolver: zodResolver(signupSchema),
|
||||
defaultValues: {
|
||||
inviteCode: inviteCode,
|
||||
},
|
||||
})
|
||||
|
||||
const onSubmit = async (data: SignupSchema) => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
const { data: session, error: signUpError } = await signUp.email({
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
name: data.email, // Use email as the username
|
||||
inviteCode: data.inviteCode,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
setLoading(false)
|
||||
if (signUpError) {
|
||||
setError(signUpError.message || 'Signup failed')
|
||||
return
|
||||
}
|
||||
|
||||
if (session) {
|
||||
setUser(session.user)
|
||||
navigate({ to: '/' })
|
||||
}
|
||||
}
|
||||
|
||||
if (isSignupInfoLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-zinc-100/80 dark:bg-black">
|
||||
<div className="relative flex flex-col items-center">
|
||||
<ShumaiLogo className="h-16 w-16 animate-pulse mb-4 text-rose-500 shadow-xl rounded-2xl" />
|
||||
<Loader2 className="h-6 w-6 animate-spin text-rose-500/70" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const isFirstUser = signupInfo?.userCount === 0
|
||||
const isPublicSignupDisabled = !isFirstUser && !signupInfo?.enablePublicSignup && !inviteCode
|
||||
|
||||
if (isPublicSignupDisabled) {
|
||||
return (
|
||||
<div className="min-h-screen w-full flex items-center justify-center p-4 md:p-8 bg-zinc-100/80 dark:bg-black font-sans overflow-hidden relative">
|
||||
{/* Background Mesh Blobs */}
|
||||
<div className="bg-rose-500/10 dark:bg-rose-600/5 w-[500px] h-[500px] rounded-full blur-[120px] absolute top-[-10%] left-[-10%] animate-drift-slow" />
|
||||
<div className="bg-orange-500/10 dark:bg-orange-600/5 w-[500px] h-[500px] rounded-full blur-[120px] absolute bottom-[-10%] right-[-10%] animate-drift-medium" />
|
||||
|
||||
<Card className="w-full max-w-md relative z-10 border border-zinc-200 dark:border-zinc-850 shadow-2xl bg-white dark:bg-zinc-900 rounded-3xl overflow-hidden">
|
||||
<CardHeader className="text-center pt-8 pb-4">
|
||||
<div className="flex justify-center mb-4">
|
||||
<ShumaiLogo className="h-16 w-16 shadow-lg shadow-rose-500/10 rounded-2xl" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl font-bold tracking-tight bg-gradient-to-r from-rose-500 to-orange-500 bg-clip-text text-transparent">
|
||||
Registration Disabled
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-2 text-zinc-600 dark:text-zinc-400">
|
||||
Public registration is currently disabled. You will need an invite code to join this
|
||||
team.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex flex-col gap-4 pb-8 text-center text-sm border-t border-zinc-200/30 dark:border-zinc-800/30 pt-6">
|
||||
<p className="text-zinc-500 dark:text-zinc-400">
|
||||
Already have an account?{' '}
|
||||
<a
|
||||
href="/login"
|
||||
className="font-semibold text-rose-500 hover:text-rose-600 dark:text-rose-400 dark:hover:text-rose-300 transition-colors hover:underline inline-flex items-center gap-1"
|
||||
>
|
||||
Login here <ArrowRight className="w-3.5 h-3.5" />
|
||||
</a>
|
||||
</p>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen w-full flex items-center justify-center p-4 md:p-8 bg-zinc-100/80 dark:bg-black font-sans overflow-hidden relative">
|
||||
{/* Drifting Background Mesh Blobs */}
|
||||
<div className="bg-rose-500/10 dark:bg-rose-600/5 w-[600px] h-[600px] rounded-full blur-[140px] absolute top-[-10%] left-[-10%] animate-drift-slow" />
|
||||
<div className="bg-orange-500/10 dark:bg-orange-600/5 w-[600px] h-[600px] rounded-full blur-[140px] absolute bottom-[-10%] right-[-10%] animate-drift-medium" />
|
||||
|
||||
{/* Main Glassmorphic Split-Pane Card */}
|
||||
<div className="relative max-w-4xl w-full flex flex-col md:flex-row rounded-3xl border border-zinc-200 dark:border-zinc-800 shadow-2xl bg-white dark:bg-zinc-900 overflow-hidden min-h-[580px] z-10 transition-all duration-300 hover:shadow-rose-500/5">
|
||||
{/* Left Pane (Brand Showcase) */}
|
||||
<div className="w-full md:w-1/2 bg-gradient-to-br from-rose-500/15 via-orange-500/10 to-amber-500/5 dark:from-rose-950/30 dark:via-orange-950/15 dark:to-zinc-900/40 p-8 md:p-12 flex flex-col justify-between border-b md:border-b-0 md:border-r border-zinc-200 dark:border-zinc-800 relative overflow-hidden">
|
||||
{/* Subtle Grid Overlay */}
|
||||
<div className="absolute inset-0 bg-[linear-gradient(to_right,#8080800a_1px,transparent_1px),linear-gradient(to_bottom,#8080800a_1px,transparent_1px)] bg-[size:14px_24px] [mask-image:radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)] pointer-events-none" />
|
||||
|
||||
{/* Logo & Brand */}
|
||||
<div className="relative flex items-center gap-3">
|
||||
<ShumaiLogo className="h-12 w-12 shadow-lg shadow-rose-500/10 rounded-2xl transition-transform duration-500 hover:scale-105" />
|
||||
<span className="text-xl font-extrabold tracking-tight bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500 bg-clip-text text-transparent">
|
||||
Shumai
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Marketing Copy / Feature Points */}
|
||||
<div className="relative my-8 md:my-0 space-y-6">
|
||||
<h2 className="text-3xl font-extrabold tracking-tight leading-tight text-zinc-900 dark:text-zinc-50">
|
||||
One workspace
|
||||
<br />
|
||||
for all your
|
||||
<br />
|
||||
<span className="bg-gradient-to-r from-rose-500 to-orange-500 bg-clip-text text-transparent">
|
||||
creative assets.
|
||||
</span>
|
||||
</h2>
|
||||
<p className="text-zinc-600 dark:text-zinc-400 text-sm leading-relaxed max-w-sm">
|
||||
Upload and index your files, enrich them with custom metadata schemas, draw
|
||||
annotations directly on media, and gather instant feedback — all in one modern
|
||||
workspace built for creators.
|
||||
</p>
|
||||
|
||||
<ul className="space-y-3.5 pt-4">
|
||||
{[
|
||||
'Instant asset uploads & high-fidelity media players',
|
||||
'Custom metadata schemas & drawing canvas reviews',
|
||||
'Frictionless team workspaces & secure sharing',
|
||||
].map((text, i) => (
|
||||
<li
|
||||
key={i}
|
||||
className="flex items-center gap-3 text-sm text-zinc-700 dark:text-zinc-300 font-medium"
|
||||
>
|
||||
<CheckCircle2 className="w-5 h-5 text-rose-500 flex-shrink-0" />
|
||||
<span>{text}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Context Banners (First User / Invite Info) */}
|
||||
<div className="relative pt-4 border-t border-zinc-200/30 dark:border-zinc-800/30">
|
||||
{isFirstUser && (
|
||||
<div className="flex items-start gap-3 p-3 bg-amber-500/10 border border-amber-500/20 text-amber-800 dark:text-amber-300 rounded-2xl text-xs leading-relaxed font-medium">
|
||||
<span>🎉</span>
|
||||
<span>You will be the owner of the default workspace as the first user!</span>
|
||||
</div>
|
||||
)}
|
||||
{inviteInfo && !('error' in inviteInfo) && (
|
||||
<div className="flex items-start gap-3 p-3 bg-rose-500/10 border border-rose-500/20 text-rose-800 dark:text-rose-300 rounded-2xl text-xs leading-relaxed font-medium">
|
||||
<span>👋</span>
|
||||
<span>
|
||||
<strong>{inviteInfo.inviterName}</strong> invited you to join{' '}
|
||||
<strong>{inviteInfo.teamName || inviteInfo.projectName}</strong> as a{' '}
|
||||
<strong>{inviteInfo.role}</strong>.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{!isFirstUser && !inviteInfo && (
|
||||
<p className="text-xs text-zinc-500 dark:text-zinc-400 font-medium">
|
||||
Join our community of developers and designers.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Pane (Form Container) */}
|
||||
<div className="w-full md:w-1/2 p-8 md:p-12 flex flex-col justify-center">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold tracking-tight text-zinc-900 dark:text-zinc-50">
|
||||
Create Account
|
||||
</h1>
|
||||
<p className="text-zinc-500 dark:text-zinc-400 text-sm mt-1">
|
||||
Start building and organizing your space.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="mb-6 p-3 bg-red-500/10 border border-red-500/20 text-red-600 dark:text-red-400 rounded-xl text-sm text-center font-medium">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-5">
|
||||
<div className="space-y-2">
|
||||
<Label
|
||||
htmlFor="email"
|
||||
className="text-xs font-semibold text-zinc-600 dark:text-zinc-400 tracking-wide uppercase"
|
||||
>
|
||||
Email Address
|
||||
</Label>
|
||||
<div className="relative group">
|
||||
<Mail className="absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400 dark:text-zinc-600 transition-colors group-focus-within:text-rose-500" />
|
||||
<Input
|
||||
id="email"
|
||||
{...form.register('email')}
|
||||
placeholder="you@example.com"
|
||||
type="email"
|
||||
className="pl-10.5 h-11 border-zinc-200 dark:border-zinc-800 focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.email && (
|
||||
<p className="text-red-500 text-xs font-medium">
|
||||
{form.formState.errors.email.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label
|
||||
htmlFor="password"
|
||||
className="text-xs font-semibold text-zinc-600 dark:text-zinc-400 tracking-wide uppercase"
|
||||
>
|
||||
Password
|
||||
</Label>
|
||||
<div className="relative group">
|
||||
<Lock className="absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400 dark:text-zinc-600 transition-colors group-focus-within:text-rose-500" />
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
{...form.register('password')}
|
||||
placeholder="At least 3 characters"
|
||||
className="pl-10.5 h-11 border-zinc-200 dark:border-zinc-800 focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
{form.formState.errors.password && (
|
||||
<p className="text-red-500 text-xs font-medium">
|
||||
{form.formState.errors.password.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
Creating account...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<UserPlus className="w-4 h-4" />
|
||||
Sign Up
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="mt-8 pt-6 border-t border-zinc-200/30 dark:border-zinc-800/30 text-center text-sm">
|
||||
<span className="text-zinc-500 dark:text-zinc-400">Already have an account? </span>
|
||||
<a
|
||||
href="/login"
|
||||
className="font-semibold text-rose-500 hover:text-rose-600 dark:text-rose-400 dark:hover:text-rose-300 transition-colors hover:underline inline-flex items-center gap-0.5"
|
||||
>
|
||||
Login <ArrowRight className="w-3.5 h-3.5" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/signup')({
|
||||
component: SignupPage,
|
||||
validateSearch: (search: Record<string, unknown>) => {
|
||||
return {
|
||||
inviteCode: (search.inviteCode as string) || undefined,
|
||||
}
|
||||
},
|
||||
beforeLoad: () => {
|
||||
if (useAuthStore.getState().user) {
|
||||
throw redirect({
|
||||
to: '/',
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,415 @@
|
||||
import type { ProjectInfo } from '@shumai/dtos'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { MembersDialog } from '@/ui/components/members-dialog'
|
||||
import { ProjectDialog } from '@/ui/components/project-dialog'
|
||||
import { SortDropdown } from '@/ui/components/sort-dropdown'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
import { Avatar, AvatarFallback } from '@/ui/components/ui/avatar'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import { ShumaiLogo } from '@/ui/components/ui/icons'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { formatDateAgo } from '@/ui/lib/time'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { MoreHorizontal, PlusIcon } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
function TeamPage() {
|
||||
const { teamId } = Route.useParams()
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
// State for clicked project for animation
|
||||
const [clickedProjectId, setClickedProjectId] = useState<string | null>(null)
|
||||
|
||||
// State for Project Dialog
|
||||
const [isProjectDialogOpen, setIsProjectDialogOpen] = useState(false)
|
||||
const [projectDialogMode, setProjectDialogMode] = useState<'create' | 'edit'>('create')
|
||||
const [selectedProject, setSelectedProject] = useState<ProjectInfo | undefined>(undefined)
|
||||
|
||||
// State for Delete Alert
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
||||
const [projectToDelete, setProjectToDelete] = useState<ProjectInfo | undefined>(undefined)
|
||||
const [deleteConfirmText, setDeleteConfirmText] = useState('')
|
||||
|
||||
// State for Members Dialog
|
||||
const [isMembersDialogOpen, setIsMembersDialogOpen] = useState(false)
|
||||
|
||||
// Sort State
|
||||
const [sortBy, setSortBy] = useState<string>('name')
|
||||
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc')
|
||||
|
||||
const $getProjects = client.api.teams[':teamId'].projects.$get
|
||||
const { data: projects } = useSuspenseQuery({
|
||||
queryKey: ['teams', teamId, 'projects', sortBy, sortDirection],
|
||||
queryFn: async () => {
|
||||
const res = await $getProjects({
|
||||
param: { teamId: teamId },
|
||||
query: { sortBy, sortDirection },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch projects')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const { data: members } = useQuery({
|
||||
queryKey: ['teams', teamId, 'members'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].members.$get({
|
||||
param: { teamId: teamId },
|
||||
query: {},
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch members')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const { data: me } = useQuery({
|
||||
queryKey: ['teams', teamId, 'me'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].me.$get({
|
||||
param: { teamId: teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch me')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const $inviteTeam = client.api.teams[':teamId'].invite.$post
|
||||
const inviteMutation = useMutation<
|
||||
InferResponseType<typeof $inviteTeam>,
|
||||
Error,
|
||||
InferRequestType<typeof $inviteTeam>
|
||||
>({
|
||||
mutationFn: async (args) => {
|
||||
const res = await $inviteTeam(args)
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed to invite')
|
||||
}
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const deleteProjectMutation = useMutation({
|
||||
mutationFn: async (projectId: string) => {
|
||||
const res = await client.api.projects[':projectId'].$delete({
|
||||
param: { projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to delete project')
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const toggleProjectNotificationsMutation = useMutation({
|
||||
mutationFn: async (project: ProjectInfo) => {
|
||||
const res = await client.api.projects[':projectId'].$put({
|
||||
param: { projectId: project.id! },
|
||||
json: {
|
||||
enableNotification: !project.enableNotification,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update project notification settings')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'projects'] })
|
||||
toast.success('Project notification settings updated')
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err instanceof Error ? err.message : 'Failed to update project notification settings',
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const handleCreateProjectClick = () => {
|
||||
setProjectDialogMode('create')
|
||||
setSelectedProject(undefined)
|
||||
setIsProjectDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleCreateCardClick = () => {
|
||||
setClickedProjectId('create')
|
||||
setTimeout(() => {
|
||||
setClickedProjectId(null)
|
||||
}, 100)
|
||||
|
||||
setTimeout(() => {
|
||||
handleCreateProjectClick()
|
||||
}, 200)
|
||||
}
|
||||
|
||||
const handleEditProjectClick = (project: ProjectInfo) => {
|
||||
setProjectDialogMode('edit')
|
||||
setSelectedProject(project)
|
||||
setIsProjectDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleDeleteProjectClick = (project: ProjectInfo) => {
|
||||
setProjectToDelete(project)
|
||||
setDeleteConfirmText('')
|
||||
setIsDeleteDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleConfirmDelete = async () => {
|
||||
if (projectToDelete && deleteConfirmText === 'delete') {
|
||||
try {
|
||||
await deleteProjectMutation.mutateAsync(projectToDelete.id!)
|
||||
setIsDeleteDialogOpen(false)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleCardClick = (projectId: string, e: React.MouseEvent) => {
|
||||
if (e.detail > 1) return
|
||||
|
||||
setClickedProjectId(projectId)
|
||||
|
||||
// Restore scale after 100ms for "shrink and restore" effect
|
||||
setTimeout(() => {
|
||||
setClickedProjectId(null)
|
||||
}, 100)
|
||||
|
||||
// Navigate after 200ms
|
||||
setTimeout(() => {
|
||||
navigate({
|
||||
to: '/projects/$projectId',
|
||||
params: { projectId },
|
||||
})
|
||||
}, 200)
|
||||
}
|
||||
|
||||
const handleInvite = async (role: 'editor' | 'reviewer') => {
|
||||
const res = await inviteMutation.mutateAsync({
|
||||
param: { teamId: teamId },
|
||||
json: { role },
|
||||
})
|
||||
return res.code
|
||||
}
|
||||
|
||||
const getInitials = (name?: string) => {
|
||||
if (!name) return '??'
|
||||
return name
|
||||
.split(' ')
|
||||
.map((n) => n[0])
|
||||
.slice(0, 2)
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
const handleSortChange = (newSortBy: string, newSortDirection: 'asc' | 'desc') => {
|
||||
setSortBy(newSortBy)
|
||||
setSortDirection(newSortDirection)
|
||||
}
|
||||
|
||||
const safeMembers = Array.isArray(members) ? members : []
|
||||
|
||||
return (
|
||||
<div className="flex-1 overflow-y-auto p-4">
|
||||
<div className="flex flex-wrap items-center justify-between mb-4 gap-4">
|
||||
<h1 className="text-2xl font-bold">Projects</h1>
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<div
|
||||
className="flex items-center -space-x-2 cursor-pointer hover:opacity-90"
|
||||
onClick={() => setIsMembersDialogOpen(true)}
|
||||
>
|
||||
{safeMembers.slice(0, 3).map((member) => (
|
||||
<Avatar key={member.id} className="border-2 border-background w-8 h-8">
|
||||
<AvatarFallback className="text-[10px]">{getInitials(member.name)}</AvatarFallback>
|
||||
</Avatar>
|
||||
))}
|
||||
{safeMembers.length > 3 && (
|
||||
<div className="flex items-center justify-center w-8 h-8 rounded-full border-2 border-background bg-muted text-[10px] font-medium">
|
||||
+{safeMembers.length - 3}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<SortDropdown
|
||||
sortBy={sortBy}
|
||||
sortDirection={sortDirection}
|
||||
onSortChange={handleSortChange}
|
||||
/>
|
||||
<Button
|
||||
className="bg-orange-600 hover:bg-orange-700 text-white gap-2"
|
||||
onClick={handleCreateProjectClick}
|
||||
>
|
||||
<PlusIcon className="w-4 h-4" />
|
||||
Create Project
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4">
|
||||
{projects.data?.map((project: ProjectInfo) => (
|
||||
<div
|
||||
key={project.id}
|
||||
className={cn(
|
||||
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out',
|
||||
clickedProjectId === project.id ? 'scale-95' : 'scale-100',
|
||||
)}
|
||||
onClick={(e) => handleCardClick(project.id!, e)}
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<div className="relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20">
|
||||
{project.coverImage ? (
|
||||
<img
|
||||
src={project.coverImage}
|
||||
alt={project.name}
|
||||
className="w-full h-full object-cover rounded"
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center text-muted-foreground font-bold tracking-wider z-10">
|
||||
<ShumaiLogo className="w-8 h-8 text-zinc-400" />
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute bottom-0 left-0 w-full h-[65%] bg-linear-to-t from-black/35 to-black/0" />
|
||||
<p className="absolute left-1 bottom-2 text-white">{project.name}</p>
|
||||
</div>
|
||||
<div className="px-2 h-10 flex justify-between items-center">
|
||||
<p className="truncate pr-1 text-xs text-muted-foreground">
|
||||
Updated {formatDateAgo((project.updatedAt as string) ?? '')}
|
||||
</p>
|
||||
<div onClick={(e) => e.stopPropagation()}>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="hover:bg-muted outline-none flex px-1">
|
||||
<MoreHorizontal className="w-5 h-5 text-muted-foreground" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleEditProjectClick(project)
|
||||
}}
|
||||
>
|
||||
Project Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="flex items-center justify-between gap-4 cursor-pointer"
|
||||
onSelect={(e) => {
|
||||
e.preventDefault()
|
||||
toggleProjectNotificationsMutation.mutate(project)
|
||||
}}
|
||||
>
|
||||
<span>Notification</span>
|
||||
<Switch
|
||||
checked={project.enableNotification ?? true}
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => handleDeleteProjectClick(project)}
|
||||
>
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div
|
||||
className={cn(
|
||||
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group',
|
||||
clickedProjectId === 'create' ? 'scale-95' : 'scale-100',
|
||||
)}
|
||||
onClick={handleCreateCardClick}
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<div className="relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors">
|
||||
<PlusIcon className="w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors" />
|
||||
</div>
|
||||
<div className="px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors">
|
||||
<p className="text-sm text-muted-foreground group-hover:text-orange-600 transition-colors">
|
||||
Create Project
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ProjectDialog
|
||||
open={isProjectDialogOpen}
|
||||
onOpenChange={setIsProjectDialogOpen}
|
||||
mode={projectDialogMode}
|
||||
teamId={teamId}
|
||||
project={selectedProject}
|
||||
/>
|
||||
|
||||
<AlertDialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action cannot be undone. This will permanently delete the project "
|
||||
{projectToDelete?.name}" and all its assets.
|
||||
<div className="mt-4 flex flex-col gap-2 text-foreground">
|
||||
<span className="text-sm font-medium">
|
||||
Type <strong>delete</strong> to confirm:
|
||||
</span>
|
||||
<Input
|
||||
value={deleteConfirmText}
|
||||
onChange={(e) => setDeleteConfirmText(e.target.value)}
|
||||
placeholder="delete"
|
||||
className="h-9"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteProjectMutation.isPending}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
handleConfirmDelete()
|
||||
}}
|
||||
disabled={deleteConfirmText !== 'delete' || deleteProjectMutation.isPending}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteProjectMutation.isPending ? 'Deleting...' : 'Delete'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<MembersDialog
|
||||
open={isMembersDialogOpen}
|
||||
onOpenChange={setIsMembersDialogOpen}
|
||||
title="Team Members"
|
||||
members={safeMembers}
|
||||
isOwner={me?.role === 'owner'}
|
||||
onInvite={handleInvite}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/teams/$teamId/')({
|
||||
component: TeamPage,
|
||||
})
|
||||
@@ -0,0 +1,402 @@
|
||||
import { VideoTranscodeStrategy } from '@shumai/dtos'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { AgentsSettings } from '@/ui/components/settings/AgentsSettings'
|
||||
import { ProvidersSettings } from '@/ui/components/settings/ProvidersSettings'
|
||||
import { SandboxSettings } from '@/ui/components/settings/SandboxSettings'
|
||||
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
||||
import { NotificationSettings } from '@/ui/components/settings/NotificationSettings'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { Bot, Cpu, Film, Loader2, Puzzle, Shield, User, Bell } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
|
||||
type SettingsTab =
|
||||
| 'general'
|
||||
| 'transcode'
|
||||
| 'skills'
|
||||
| 'providers'
|
||||
| 'agents'
|
||||
| 'sandbox'
|
||||
| 'notifications'
|
||||
|
||||
function TeamSettingsPage() {
|
||||
const { teamId } = Route.useParams()
|
||||
const queryClient = useQueryClient()
|
||||
const [activeTab, setActiveTab] = useState<SettingsTab>('general')
|
||||
|
||||
const {
|
||||
data: settings,
|
||||
isLoading: isSettingsLoading,
|
||||
error: settingsError,
|
||||
} = useQuery({
|
||||
queryKey: ['teams', teamId, 'settings'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].settings.$get({
|
||||
param: { teamId: teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch settings')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const { data: me, isLoading: isMeLoading } = useQuery({
|
||||
queryKey: ['teams', teamId, 'me'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].me.$get({
|
||||
param: { teamId: teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch me')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!teamId,
|
||||
})
|
||||
|
||||
const { mutate: updateSettings } = useMutation({
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mutationFn: async (data: { teamId: string; data: { key: string; value: any } }) => {
|
||||
const res = await client.api.teams[':teamId'].settings.$patch({
|
||||
param: { teamId: data.teamId },
|
||||
json: { key: data.data.key, value: data.data.value },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update settings')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['teams', teamId, 'settings'],
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const handleVideoStrategyChange = (value: VideoTranscodeStrategy) => {
|
||||
updateSettings({
|
||||
teamId,
|
||||
data: {
|
||||
key: 'transcode.videoStrategy',
|
||||
value: value,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (isSettingsLoading || isMeLoading) {
|
||||
return (
|
||||
<div className="flex h-screen items-center justify-center">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (settingsError) {
|
||||
return <div className="p-8 text-center text-red-500">Failed to load settings.</div>
|
||||
}
|
||||
|
||||
let currentVideoStrategy =
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(settings as any)?.transcode?.videoStrategy || VideoTranscodeStrategy.best_match
|
||||
if (currentVideoStrategy === 'single' || currentVideoStrategy === 'disable') {
|
||||
currentVideoStrategy = VideoTranscodeStrategy.best_match
|
||||
} else if (currentVideoStrategy === 'full') {
|
||||
currentVideoStrategy = VideoTranscodeStrategy.all
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300">
|
||||
<div className="flex flex-col md:flex-row h-full">
|
||||
{/* Sidebar */}
|
||||
<div className="w-full h-full md:w-72 bg-sidebar border-b md:border-b-0 md:border-r border-sidebar-border z-10 md:left-16 overflow-y-auto transition-colors duration-300">
|
||||
<nav className="p-4 space-y-1 mt-4">
|
||||
<div className="mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider">
|
||||
Settings
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('general')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'general'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<User className="w-5 h-5" />
|
||||
General
|
||||
{activeTab === 'general' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('transcode')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'transcode'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Film className="w-5 h-5" />
|
||||
Media Processing
|
||||
{activeTab === 'transcode' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('notifications')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'notifications'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Bell className="w-5 h-5" />
|
||||
Notifications
|
||||
{activeTab === 'notifications' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="mt-6 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border">
|
||||
AI
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('providers')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'providers'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Cpu className="w-5 h-5" />
|
||||
Providers
|
||||
{activeTab === 'providers' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('skills')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'skills'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Puzzle className="w-5 h-5" />
|
||||
Skills
|
||||
{activeTab === 'skills' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('agents')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'agents'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Bot className="w-5 h-5" />
|
||||
Agents
|
||||
{activeTab === 'agents' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('sandbox')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'sandbox'
|
||||
? 'bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border'
|
||||
: 'text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<Shield className="w-5 h-5" />
|
||||
Agent Sandbox
|
||||
{activeTab === 'sandbox' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary" />
|
||||
)}
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Main Content Area */}
|
||||
<main className="flex-1 bg-background/50 h-full flex flex-col transition-colors duration-300 overflow-y-hidden">
|
||||
<div className="flex-1 flex flex-col max-w-4xl w-full mx-auto p-6 md:p-10 overflow-hidden">
|
||||
<div className="flex-none flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-foreground">
|
||||
{activeTab === 'general' && 'General Settings'}
|
||||
{activeTab === 'transcode' && 'Media Processing'}
|
||||
{activeTab === 'skills' && 'Skills Management'}
|
||||
{activeTab === 'providers' && 'AI Providers'}
|
||||
{activeTab === 'agents' && 'AI Agents'}
|
||||
{activeTab === 'sandbox' && 'Agent Sandbox Settings'}
|
||||
{activeTab === 'notifications' && 'Notification Settings'}
|
||||
</h2>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{activeTab === 'general' && 'View your personal information and team role.'}
|
||||
{activeTab === 'transcode' &&
|
||||
"Manage your team's media transcoding configurations."}
|
||||
{activeTab === 'skills' && 'Add, update and configure AI skills for the team.'}
|
||||
{activeTab === 'providers' &&
|
||||
'Configure AI providers and their models for this team.'}
|
||||
{activeTab === 'agents' && 'Manage AI agents and their personalities.'}
|
||||
{activeTab === 'sandbox' &&
|
||||
'Configure security and network restrictions for the AI agent.'}
|
||||
{activeTab === 'notifications' &&
|
||||
'Configure your personal notification preferences for this team.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-hidden animate-in fade-in slide-in-from-bottom-4 duration-500">
|
||||
{activeTab === 'general' && (
|
||||
<div className="h-full overflow-y-auto space-y-6 pr-1">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Personal Info</CardTitle>
|
||||
<CardDescription>View your personal information.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col space-y-2">
|
||||
<span className="text-sm font-medium text-muted-foreground">Name</span>
|
||||
<span className="text-lg">{me?.name}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{me?.role === 'owner' && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Team Settings</CardTitle>
|
||||
<CardDescription>Manage your team's general settings.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<h3 className="text-base font-medium">Enable Public Signup</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Allow users to sign up without an invite code.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
checked={(settings as any)?.enablePublicSignup || false}
|
||||
onCheckedChange={(checked) =>
|
||||
updateSettings({
|
||||
teamId,
|
||||
data: {
|
||||
key: 'enablePublicSignup',
|
||||
value: checked,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'transcode' && (
|
||||
<div className="h-full overflow-y-auto pr-1">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Transcode Settings</CardTitle>
|
||||
<CardDescription>
|
||||
<span className="block mb-2">
|
||||
Manage your team's media transcoding configurations.
|
||||
</span>
|
||||
<span className="block">
|
||||
Strategy: We select the best resolution from your list that supports the
|
||||
input quality. Content is never upscaled.
|
||||
</span>
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{/* Video Strategy */}
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-medium">Video Strategy</h3>
|
||||
<div className="space-y-3">
|
||||
<div
|
||||
className={cn(
|
||||
'cursor-pointer rounded-lg border p-4 transition-all hover:border-primary',
|
||||
currentVideoStrategy === VideoTranscodeStrategy.best_match
|
||||
? 'border-primary bg-primary/5'
|
||||
: 'border-border',
|
||||
)}
|
||||
onClick={() =>
|
||||
handleVideoStrategyChange(VideoTranscodeStrategy.best_match)
|
||||
}
|
||||
>
|
||||
<div className="font-semibold">Best match</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Generates a single optimal resolution matching the source quality.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'cursor-pointer rounded-lg border p-4 transition-all hover:border-primary',
|
||||
currentVideoStrategy === VideoTranscodeStrategy.all
|
||||
? 'border-primary bg-primary/5'
|
||||
: 'border-border',
|
||||
)}
|
||||
onClick={() => handleVideoStrategyChange(VideoTranscodeStrategy.all)}
|
||||
>
|
||||
<div className="font-semibold">All resolutions</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Generates all supported resolutions up to the source quality.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'skills' && (
|
||||
<div className="h-full overflow-y-auto pr-1">
|
||||
<SkillsConfigCard teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'providers' && <ProvidersSettings teamId={teamId} />}
|
||||
|
||||
{activeTab === 'agents' && (
|
||||
<div className="h-full overflow-y-auto pr-1">
|
||||
<AgentsSettings teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'sandbox' && (
|
||||
<div className="h-full overflow-y-auto pr-1">
|
||||
<SandboxSettings teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'notifications' && <NotificationSettings teamId={teamId} />}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/teams/$teamId/settings')({
|
||||
component: TeamSettingsPage,
|
||||
})
|
||||
Reference in New Issue
Block a user