Download apps/web/src/App.tsx from phucsd/olokaflow: direct link, hf CLI and curl.
- Browser
- Download file 41.2 kB
-
https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/web/src/App.tsx
- Command line
-
hf download hf://spaces/phucsd/olokaflow/apps/web/src/App.tsx
-
curl -L -o App.tsx https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/web/src/App.tsx
41.2 kB
import React, { useEffect, useState } from 'react';
import {
Film,
Mic,
FolderOpen,
Layers,
Palette,
Cpu,
Cloud,
Trash2,
CheckCircle2,
RefreshCw,
Sparkles,
Plus,
ShieldCheck,
Lock,
Unlock,
Users,
LogOut,
LogIn,
FileSpreadsheet,
} from 'lucide-react';
import { api } from './api';
import type {
Project,
AIProviderProfile,
AIRoleRoutingEntry,
AssetItem,
BrandKit,
FrozenRecipe,
} from '@olokaflow/shared';
import { StudioWorkspaceView } from './components/StudioWorkspaceView';
import { BatchStudioView } from './components/BatchStudioView';
import { AIProfileHubView } from './components/AIProfileHubView';
import { AssetLibraryView } from './components/AssetLibraryView';
import { CatalogBrowserView } from './components/CatalogBrowserView';
import { Button, Badge } from './components/ui/primitives';
type MainTab =
| 'studio'
| 'batch'
| 'voices'
| 'assets'
| 'catalog'
| 'brands'
| 'ai_profiles'
| 'vault';
export const App: React.FC = () => {
const [activeTab, setActiveTab] = useState<MainTab>('studio');
const [projects, setProjects] = useState<Project[]>([]);
const [activeProjectId, setActiveProjectId] = useState<string>('');
const [catalog, setCatalog] = useState<any>(null);
const [profiles, setProfiles] = useState<AIProviderProfile[]>([]);
const [routings, setRoutings] = useState<AIRoleRoutingEntry[]>([]);
const [assets, setAssets] = useState<AssetItem[]>([]);
const [brands, setBrands] = useState<BrandKit[]>([]);
const [recipes, setRecipes] = useState<FrozenRecipe[]>([]);
const [vaultStatus, setVaultStatus] = useState<any>(null);
const [syncingVault, setSyncingVault] = useState(false);
// Auth Login Gate & Team Governance State
const [authChecked, setAuthChecked] = useState(false);
const [requireAuthGate, setRequireAuthGate] = useState(false);
const [currentUser, setCurrentUser] = useState<any | null>(null);
const [showLoginModal, setShowLoginModal] = useState(false);
const [loginEmail, setLoginEmail] = useState('admin@olokaflow.ai');
const [loginPassword, setLoginPassword] = useState('admin123');
const [loginError, setLoginError] = useState('');
const [loginBusy, setLoginBusy] = useState(false);
const [teamUsers, setTeamUsers] = useState<any[]>([]);
const [newUserEmail, setNewUserEmail] = useState('');
const [newUserName, setNewUserName] = useState('');
const [newUserPassword, setNewUserPassword] = useState('');
const [newUserRole, setNewUserRole] = useState<'creator' | 'admin'>('creator');
const [newUserQuota, setNewUserQuota] = useState(5000000);
// Brand Kit quick form state
const [newBrandName, setNewBrandName] = useState('');
const [newBrandTagline, setNewBrandTagline] = useState('');
const [newBrandPrimary, setNewBrandPrimary] = useState('#E11D48');
const [newBrandAccent, setNewBrandAccent] = useState('#18181B');
useEffect(() => {
void loadAllState();
}, []);
async function loadAllState() {
try {
const [authRes, projRes, catRes, aiRes, astRes, brdRes, vltRes, usrRes] =
await Promise.all([
api.getAuthMe().catch(() => ({
authenticated: false,
requireAuthGate: false,
user: null,
})),
api.getProjects(),
api.getCatalog(),
api.getAIProfiles(),
api.getAssets(),
api.getBrandsAndRecipes(),
api.getVaultStatus(),
api.getUsers().catch(() => ({ users: [] })),
]);
setRequireAuthGate(Boolean(authRes.requireAuthGate));
setCurrentUser(authRes.user || null);
setAuthChecked(true);
const pList = projRes.projects || [];
setProjects(pList);
if (!activeProjectId && pList.length > 0) {
setActiveProjectId(pList[0].id);
}
setCatalog(catRes);
setProfiles(aiRes.profiles || []);
setRoutings(aiRes.routings || []);
setAssets(astRes.assets || []);
setBrands(brdRes.brands || []);
setRecipes(brdRes.recipes || []);
setVaultStatus(vltRes);
setTeamUsers(usrRes.users || []);
} catch (err) {
console.error('Load state error:', err);
setAuthChecked(true);
}
}
async function handleLoginSubmit(e: React.FormEvent) {
e.preventDefault();
setLoginBusy(true);
setLoginError('');
try {
const res = await api.login(loginEmail.trim(), loginPassword);
setCurrentUser(res.user);
setShowLoginModal(false);
await loadAllState();
} catch (err: any) {
setLoginError(err.message || 'Đăng nhập thất bại');
} finally {
setLoginBusy(false);
}
}
async function handleToggleAuthGate(nextVal: boolean) {
try {
const res = await api.setAuthGate(nextVal);
setRequireAuthGate(res.requireAuthGate);
if (nextVal && !currentUser) {
setShowLoginModal(true);
}
} catch (err: any) {
alert(`Lỗi cập nhật Auth Gate: ${err.message}`);
}
}
async function handleCreateTeamUser(e: React.FormEvent) {
e.preventDefault();
if (!newUserEmail.trim()) return;
try {
await api.createUser({
email: newUserEmail.trim(),
name: newUserName.trim() || 'Creator',
password: newUserPassword || 'oloka123',
role: newUserRole,
tokenQuota: Number(newUserQuota) || 5000000,
});
setNewUserEmail('');
setNewUserName('');
setNewUserPassword('');
await loadAllState();
} catch (err: any) {
alert(`Lỗi tạo tài khoản: ${err.message}`);
}
}
const activeProject =
projects.find((p) => p.id === activeProjectId) || projects[0] || null;
const navItems: Array<{
id: MainTab;
label: string;
icon: React.ComponentType<{ className?: string }>;
badge?: string | number;
}> = [
{
id: 'studio',
label: 'Fliki Video Studio',
icon: Film,
badge: projects.length,
},
{
id: 'batch',
label: 'Sản Xuất Hàng Loạt',
icon: FileSpreadsheet,
badge: 'Batch',
},
{
id: 'voices',
label: 'Giọng Đọc & Clone',
icon: Mic,
badge: catalog?.voices?.length || 25,
},
{
id: 'assets',
label: 'Kho Media & Cào URL',
icon: FolderOpen,
badge: assets.length,
},
{
id: 'catalog',
label: 'HyperFrames Catalog',
icon: Layers,
badge: '4-Tier',
},
{
id: 'brands',
label: 'Brand Kits & Recipes',
icon: Palette,
badge: brands.length + recipes.length,
},
{
id: 'ai_profiles',
label: 'Cấu Hình AI & Test API',
icon: Cpu,
badge: profiles.length,
},
{
id: 'vault',
label: 'HF Vault & Quản Trị Team',
icon: Cloud,
badge: teamUsers.length,
},
];
async function handleCreateBrand(e: React.FormEvent) {
e.preventDefault();
if (!newBrandName.trim()) return;
await api.saveBrand({
name: `Bộ nhận diện ${newBrandName}`,
brandName: newBrandName.trim(),
tagline: newBrandTagline.trim() || 'Sáng tạo video tự động chuẩn thương hiệu',
primaryColor: newBrandPrimary,
accentColor: newBrandAccent,
});
setNewBrandName('');
setNewBrandTagline('');
await loadAllState();
}
// Full-Screen Login Gate when requireAuthGate is enabled and user is not logged in
if (authChecked && requireAuthGate && !currentUser) {
return (
<div className="min-h-screen bg-[#FAF9F6] flex items-center justify-center p-4">
<form
onSubmit={handleLoginSubmit}
className="fliki-card p-7 bg-white max-w-md w-full space-y-5 shadow-lg"
>
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-[#E11D48] text-white flex items-center justify-center shadow-xs">
<Film className="w-5 h-5 stroke-[2.2]" />
</div>
<div>
<div className="flex items-center gap-1.5">
<span className="font-extrabold text-lg tracking-tight text-zinc-900">
OlokaFlow Studio
</span>
<Badge variant="crimson" mono>
AUTH GATE
</Badge>
</div>
<p className="text-xs text-zinc-500">
Đăng nhập để truy cập hệ thống tạo video HyperFrames 60fps
</p>
</div>
</div>
{loginError && (
<div className="p-3 rounded-xl bg-rose-50 border border-rose-200 text-xs font-semibold text-[#E11D48]">
{loginError}
</div>
)}
<div className="space-y-3">
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Email đăng nhập
</label>
<input
type="email"
value={loginEmail}
onChange={(e) => setLoginEmail(e.target.value)}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2.5 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]"
required
/>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Mật khẩu
</label>
<input
type="password"
value={loginPassword}
onChange={(e) => setLoginPassword(e.target.value)}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2.5 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]"
required
/>
</div>
</div>
<Button
type="submit"
variant="primary"
size="lg"
className="w-full"
disabled={loginBusy}
>
<LogIn className="w-4 h-4" />
<span>{loginBusy ? 'Đang xác thực...' : 'Đăng Nhập Vào Studio'}</span>
</Button>
</form>
</div>
);
}
return (
<div className="min-h-screen flex bg-[#FAF9F6] text-zinc-900">
{/* =====================================================================
LEFT EDITORIAL NAVIGATION RAIL (DESIGN.MD + TASTE-DESIGN + SHADCN)
===================================================================== */}
<aside className="w-64 shrink-0 bg-white border-r border-zinc-200/90 flex flex-col justify-between sticky top-0 h-screen z-30">
<div className="p-4 space-y-5 overflow-y-auto">
{/* Brand Logo Lockup */}
<div className="flex items-center gap-3 px-2 pt-1">
<div className="w-9 h-9 rounded-xl bg-[#E11D48] text-white flex items-center justify-center shadow-xs">
<Film className="w-4 h-4 stroke-[2.2]" />
</div>
<div>
<div className="flex items-center gap-1.5">
<span className="font-extrabold text-base tracking-tight text-zinc-900">
OlokaFlow
</span>
<span className="px-1.5 py-0.5 rounded-md bg-rose-50 text-[#E11D48] border border-rose-200 text-[10px] font-mono font-semibold">
PRO
</span>
</div>
<p className="text-[11px] text-zinc-500 font-medium">
HyperFrames Video Studio
</p>
</div>
</div>
{/* Primary Navigation Items */}
<nav className="space-y-1">
{navItems.map((item) => {
const isAct = activeTab === item.id;
const Icon = item.icon;
return (
<button
key={item.id}
onClick={() => setActiveTab(item.id)}
className={`w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-xs font-semibold transition-all cursor-pointer ${
isAct
? 'bg-rose-50/90 text-[#E11D48] border border-rose-200/80 shadow-2xs'
: 'text-zinc-600 hover:bg-zinc-100/80 hover:text-zinc-900 border border-transparent'
}`}
>
<div className="flex items-center gap-2.5">
<Icon
className={`w-4 h-4 ${
isAct ? 'text-[#E11D48]' : 'text-zinc-500'
}`}
/>
<span>{item.label}</span>
</div>
{item.badge !== undefined && (
<span
className={`px-1.5 py-0.5 rounded-md text-[10px] font-mono tabular-nums font-semibold ${
isAct
? 'bg-[#E11D48] text-white'
: 'bg-zinc-100 text-zinc-600'
}`}
>
{item.badge}
</span>
)}
</button>
);
})}
</nav>
{/* Recent Projects Quick Switcher */}
<div className="pt-3 border-t border-zinc-200/80 space-y-2">
<div className="flex items-center justify-between px-2">
<span className="text-[10px] font-bold uppercase tracking-wider text-zinc-400">
Dự án gần đây
</span>
<span className="text-[10px] font-mono tabular-nums text-zinc-400">
{projects.length}
</span>
</div>
<div className="space-y-1 max-h-48 overflow-y-auto pr-1">
{projects.map((p) => {
const isSel =
activeProject?.id === p.id && activeTab === 'studio';
return (
<button
key={p.id}
onClick={() => {
setActiveProjectId(p.id);
setActiveTab('studio');
}}
className={`w-full text-left px-2.5 py-2 rounded-xl text-xs transition-all cursor-pointer flex items-center justify-between gap-2 ${
isSel
? 'bg-zinc-900 text-white font-semibold'
: 'text-zinc-600 hover:bg-zinc-100 font-medium'
}`}
>
<span className="truncate">{p.title}</span>
<span
className={`text-[10px] font-mono tabular-nums shrink-0 ${
isSel ? 'text-rose-300' : 'text-zinc-400'
}`}
>
{p.aspectRatio}
</span>
</button>
);
})}
</div>
</div>
</div>
{/* Bottom Auth & System Telemetry Card */}
<div className="p-3.5 border-t border-zinc-200/80 bg-zinc-50/70 space-y-2.5">
<div className="flex items-center justify-between">
{currentUser ? (
<div className="flex items-center justify-between w-full gap-2">
<div className="min-w-0">
<div className="text-xs font-bold text-zinc-900 truncate">
{currentUser.name}
</div>
<div className="text-[10px] font-mono text-zinc-500 truncate">
{currentUser.role.toUpperCase()} • {currentUser.email}
</div>
</div>
<button
type="button"
onClick={async () => {
await api.logout();
setCurrentUser(null);
}}
className="p-1.5 rounded-lg hover:bg-zinc-200 text-zinc-500 hover:text-zinc-900 cursor-pointer"
title="Đăng xuất"
>
<LogOut className="w-3.5 h-3.5" />
</button>
</div>
) : (
<div className="flex items-center justify-between w-full gap-2">
<button
type="button"
onClick={() => setShowLoginModal(true)}
className="text-xs font-semibold text-zinc-700 hover:text-[#E11D48] flex items-center gap-1.5 cursor-pointer"
>
<LogIn className="w-3.5 h-3.5 text-[#E11D48]" />
<span>Đăng nhập Admin</span>
</button>
<button
type="button"
onClick={() => handleToggleAuthGate(!requireAuthGate)}
className={`px-2 py-0.5 rounded-md text-[10px] font-mono font-semibold flex items-center gap-1 cursor-pointer ${
requireAuthGate
? 'bg-rose-100 text-[#E11D48]'
: 'bg-zinc-200/80 text-zinc-600'
}`}
title="Bật/Tắt cổng đăng nhập bắt buộc cho toàn trang"
>
{requireAuthGate ? (
<>
<Lock className="w-2.5 h-2.5" />
<span>LOCKED</span>
</>
) : (
<>
<Unlock className="w-2.5 h-2.5" />
<span>OPEN</span>
</>
)}
</button>
</div>
)}
</div>
<div className="flex items-center justify-between text-[11px] pt-1 border-t border-zinc-200/60">
<span className="font-semibold text-zinc-600 flex items-center gap-1.5">
<span className="w-2 h-2 rounded-full bg-emerald-500" />
OlokaTTS + Modal
</span>
<span className="font-mono tabular-nums text-[10px] text-emerald-700 font-semibold">
60 FPS
</span>
</div>
</div>
</aside>
{/* =====================================================================
MAIN WORKSPACE CANVAS
===================================================================== */}
<main className="flex-1 min-w-0 p-5 lg:p-6 max-w-[1600px] mx-auto w-full">
{activeTab === 'studio' && (
<StudioWorkspaceView
projects={projects}
activeProject={activeProject}
catalog={catalog}
brands={brands}
recipes={recipes}
profiles={profiles}
assets={assets}
onSelectProject={(id) => setActiveProjectId(id)}
onRefreshAll={loadAllState}
/>
)}
{activeTab === 'batch' && (
<BatchStudioView
catalog={catalog}
brands={brands}
recipes={recipes}
onOpenProjectInStudio={(id) => {
setActiveProjectId(id);
setActiveTab('studio');
}}
onRefreshAll={loadAllState}
/>
)}
{activeTab === 'voices' && (
<CatalogBrowserView
catalog={catalog}
initialSubTab="voices"
onRefreshCatalog={loadAllState}
/>
)}
{activeTab === 'assets' && (
<AssetLibraryView assets={assets} onRefresh={loadAllState} />
)}
{activeTab === 'catalog' && (
<CatalogBrowserView
catalog={catalog}
initialSubTab="blueprints"
onRefreshCatalog={loadAllState}
/>
)}
{activeTab === 'ai_profiles' && (
<AIProfileHubView
profiles={profiles}
routings={routings}
onRefresh={loadAllState}
/>
)}
{/* BRAND KITS & FROZEN RECIPES TAB */}
{activeTab === 'brands' && (
<div className="space-y-6">
<div className="fliki-card p-6 bg-white flex flex-wrap items-center justify-between gap-4">
<div>
<Badge variant="crimson" className="mb-1.5">
<Palette className="w-3 h-3" />
Brand Governance & Frozen Recipes
</Badge>
<h2 className="text-xl font-bold tracking-tight text-zinc-900">
Quản Trị Bộ Nhận Diện Thương Hiệu & Công Thức Dựng Video
</h2>
<p className="text-xs text-zinc-500 mt-0.5">
Đồng bộ màu sắc thương hiệu, phông chữ, giọng đọc mặc định và công thức chuyển động xuyên suốt mọi video.
</p>
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-12 gap-5">
{/* Create Brand Form */}
<form
onSubmit={handleCreateBrand}
className="lg:col-span-5 fliki-card p-5 bg-white space-y-4"
>
<h3 className="text-sm font-bold text-zinc-900 flex items-center gap-2">
<Plus className="w-4 h-4 text-[#E11D48]" />
Thêm Bộ Nhận Diện Thương Hiệu (Brand Kit)
</h3>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Tên thương hiệu *
</label>
<input
type="text"
value={newBrandName}
onChange={(e) => setNewBrandName(e.target.value)}
placeholder="VD: Oloka Cloud AI..."
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]"
required
/>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Thông điệp (Tagline)
</label>
<input
type="text"
value={newBrandTagline}
onChange={(e) => setNewBrandTagline(e.target.value)}
placeholder="VD: Giải pháp tự động hóa doanh nghiệp..."
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]"
/>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Màu chủ đạo (Primary)
</label>
<input
type="color"
value={newBrandPrimary}
onChange={(e) => setNewBrandPrimary(e.target.value)}
className="w-full h-9 rounded-lg border border-zinc-200 cursor-pointer"
/>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Màu nhấn (Accent)
</label>
<input
type="color"
value={newBrandAccent}
onChange={(e) => setNewBrandAccent(e.target.value)}
className="w-full h-9 rounded-lg border border-zinc-200 cursor-pointer"
/>
</div>
</div>
<Button type="submit" variant="primary" className="w-full">
<Plus className="w-3.5 h-3.5" />
Lưu Brand Kit
</Button>
</form>
{/* Existing Brand Kits & Recipes */}
<div className="lg:col-span-7 space-y-4">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
{brands.map((b: any) => (
<div key={b.id} className="fliki-card p-4 bg-white space-y-2">
<div className="flex items-center justify-between">
<span className="text-sm font-bold text-zinc-900">
{b.name}
</span>
<div className="flex items-center gap-1.5">
<span
className="w-4 h-4 rounded-full border border-zinc-300"
style={{ backgroundColor: b.primaryColor }}
/>
<span
className="w-4 h-4 rounded-full border border-zinc-300"
style={{
backgroundColor: b.accentColor || b.secondaryColor,
}}
/>
</div>
</div>
<p className="text-xs text-zinc-500">
{b.tagline || b.defaultCtaText}
</p>
<div className="text-[11px] font-mono text-zinc-400">
Voice: {b.defaultVoiceId} • Font:{' '}
{b.headingFont || 'Plus Jakarta Sans'}
</div>
</div>
))}
</div>
<div className="fliki-card p-5 bg-white space-y-3">
<h4 className="text-xs font-bold uppercase tracking-wider text-zinc-500 flex items-center gap-1.5">
<Sparkles className="w-3.5 h-3.5 text-[#E11D48]" />
Công Thức Dựng Video Đóng Băng (Frozen Recipes)
</h4>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
{recipes.map((r: any) => (
<div
key={r.id}
className="p-3.5 rounded-xl bg-zinc-50 border border-zinc-200/80 space-y-1.5"
>
<div className="text-xs font-bold text-zinc-900">
{r.name}
</div>
<p className="text-[11px] text-zinc-500">
{r.description}
</p>
<div className="text-[10px] font-mono tabular-nums text-[#E11D48] font-semibold">
Preset: {r.framePresetId} •{' '}
{r.defaultAspectRatio || r.aspectRatio}
</div>
</div>
))}
</div>
</div>
</div>
</div>
</div>
)}
{/* HF CLOUD VAULT, TEAM GOVERNANCE & PROJECT MANAGEMENT TAB */}
{activeTab === 'vault' && (
<div className="space-y-6">
<div className="fliki-card p-6 bg-white flex flex-wrap items-center justify-between gap-4">
<div>
<Badge variant="emerald" className="mb-1.5">
<ShieldCheck className="w-3 h-3" />
Hugging Face Private Dataset Vault + Team Auth Gate
</Badge>
<h2 className="text-xl font-bold tracking-tight text-zinc-900">
Đồng Bộ Lưu Trữ Đám Mây Vĩnh Viễn, Bảo Mật Đăng Nhập & Quản Trị Team
</h2>
<p className="text-xs text-zinc-500 mt-0.5">
Tự động sao lưu SQLite WAL, cấu hình AI đã mã hóa và toàn bộ dự án HyperFrames lên Private Dataset{' '}
<span className="font-mono text-zinc-700">
{vaultStatus?.vaultRepo || 'phucsd/olokaflow-vault'}
</span>
.
</p>
</div>
<div className="flex items-center gap-2 flex-wrap">
<Button
variant={requireAuthGate ? 'outlineCrimson' : 'secondary'}
onClick={() => handleToggleAuthGate(!requireAuthGate)}
>
{requireAuthGate ? (
<>
<Lock className="w-3.5 h-3.5" />
<span>Cổng Đăng Nhập: ĐANG BẬT (Bấm để Mở)</span>
</>
) : (
<>
<Unlock className="w-3.5 h-3.5" />
<span>Cổng Đăng Nhập: ĐANG MỞ (Bấm để Khóa)</span>
</>
)}
</Button>
<Button
variant="primary"
disabled={syncingVault}
onClick={async () => {
setSyncingVault(true);
try {
const res = await api.triggerVaultBackup();
setVaultStatus(res);
} finally {
setSyncingVault(false);
}
}}
>
<RefreshCw
className={`w-3.5 h-3.5 ${syncingVault ? 'animate-spin' : ''}`}
/>
{syncingVault
? 'Đang đồng bộ lên HF Vault...'
: 'Sao Lưu Ngay Lên HF Private Dataset'}
</Button>
</div>
</div>
{/* Team Governance Grid */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-5">
<form
onSubmit={handleCreateTeamUser}
className="lg:col-span-5 fliki-card p-5 bg-white space-y-3.5"
>
<h3 className="text-sm font-bold text-zinc-900 flex items-center gap-2">
<Users className="w-4 h-4 text-[#E11D48]" />
<span>Cấp Tài Khoản Thành Viên Mới (Team Member)</span>
</h3>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Email đăng nhập *
</label>
<input
type="email"
value={newUserEmail}
onChange={(e) => setNewUserEmail(e.target.value)}
placeholder="editor@olokaflow.ai"
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900"
required
/>
</div>
<div className="grid grid-cols-2 gap-2.5">
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Tên hiển thị
</label>
<input
type="text"
value={newUserName}
onChange={(e) => setNewUserName(e.target.value)}
placeholder="Video Editor"
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs text-zinc-900"
/>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Mật khẩu khởi tạo
</label>
<input
type="text"
value={newUserPassword}
onChange={(e) => setNewUserPassword(e.target.value)}
placeholder="oloka123"
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-mono text-zinc-900"
/>
</div>
</div>
<div className="grid grid-cols-2 gap-2.5">
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Phân quyền (Role)
</label>
<select
value={newUserRole}
onChange={(e) =>
setNewUserRole(e.target.value as 'creator' | 'admin')
}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-semibold text-zinc-800"
>
<option value="creator">Creator (Biên tập Video)</option>
<option value="admin">Admin (Toàn quyền)</option>
</select>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Hạn mức Token
</label>
<input
type="number"
value={newUserQuota}
onChange={(e) => setNewUserQuota(Number(e.target.value))}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-mono tabular-nums text-zinc-900"
/>
</div>
</div>
<Button type="submit" variant="primary" className="w-full">
<Plus className="w-3.5 h-3.5" />
<span>Tạo Tài Khoản Thành Viên</span>
</Button>
</form>
<div className="lg:col-span-7 fliki-card p-5 bg-white space-y-3">
<div className="flex items-center justify-between">
<h3 className="text-sm font-bold text-zinc-900">
Danh Sách Thành Viên & Hạn Mức Sử Dụng ({teamUsers.length})
</h3>
<Badge variant="default" mono>
Default Admin: admin@olokaflow.ai / admin123
</Badge>
</div>
<div className="divide-y divide-zinc-100 border border-zinc-200 rounded-xl overflow-hidden">
{teamUsers.map((u) => (
<div
key={u.id}
className="p-3.5 bg-white flex flex-wrap items-center justify-between gap-2"
>
<div>
<div className="flex items-center gap-2">
<span className="text-xs font-bold text-zinc-900">
{u.name}
</span>
<Badge
variant={u.role === 'admin' ? 'crimson' : 'default'}
mono
>
{u.role.toUpperCase()}
</Badge>
</div>
<div className="text-xs font-mono text-zinc-500 mt-0.5">
{u.email} • Đã dùng:{' '}
{Number(u.tokensUsed || 0).toLocaleString()} /{' '}
{Number(u.tokenQuota || 0).toLocaleString()} tokens
</div>
</div>
{u.id !== 'usr-admin' && (
<Button
variant="danger"
size="sm"
onClick={async () => {
await api.deleteUser(u.id);
await loadAllState();
}}
>
<Trash2 className="w-3.5 h-3.5" />
<span>Xóa</span>
</Button>
)}
</div>
))}
</div>
</div>
</div>
<div className="fliki-card p-6 bg-white space-y-4">
<div className="flex items-center justify-between">
<h3 className="text-sm font-bold text-zinc-900">
Danh Sách Toàn Bộ Dự Án Video
</h3>
<span className="text-xs font-mono tabular-nums text-zinc-500">
{projects.length} dự án
</span>
</div>
<div className="divide-y divide-zinc-100 border border-zinc-200 rounded-xl overflow-hidden">
{projects.map((p) => (
<div
key={p.id}
className="p-4 bg-white hover:bg-zinc-50/80 flex flex-wrap items-center justify-between gap-3"
>
<div>
<div className="flex items-center gap-2">
<span className="text-sm font-bold text-zinc-900">
{p.title}
</span>
<Badge variant="default" mono>
{p.aspectRatio} • {Math.round(p.totalDurationSec || 0)}s
</Badge>
<Badge
variant={
p.status === 'ready' || p.status === 'rendered'
? 'emerald'
: 'amber'
}
>
<CheckCircle2 className="w-3 h-3" />
{p.status}
</Badge>
</div>
<p className="text-xs text-zinc-500 mt-1 line-clamp-1">
{p.prompt}
</p>
</div>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="sm"
onClick={() => {
setActiveProjectId(p.id);
setActiveTab('studio');
}}
>
<Film className="w-3.5 h-3.5" />
Mở trong Studio
</Button>
<Button
variant="danger"
size="sm"
onClick={async () => {
await api.deleteProject(p.id);
await loadAllState();
}}
>
<Trash2 className="w-3.5 h-3.5" />
Xóa
</Button>
</div>
</div>
))}
</div>
</div>
</div>
)}
</main>
{/* LOGIN MODAL (WHEN CLICKING LOGIN FROM SIDEBAR) */}
{showLoginModal && (
<div className="fixed inset-0 z-50 bg-zinc-950/50 backdrop-blur-xs flex items-center justify-center p-4">
<form
onSubmit={handleLoginSubmit}
className="fliki-card p-6 bg-white max-w-md w-full space-y-4 shadow-2xl"
>
<div className="flex items-center justify-between border-b border-zinc-100 pb-3">
<h3 className="text-base font-bold text-zinc-900">
Đăng nhập Tài khoản OlokaFlow
</h3>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setShowLoginModal(false)}
>
Đóng
</Button>
</div>
{loginError && (
<div className="p-2.5 rounded-xl bg-rose-50 border border-rose-200 text-xs font-semibold text-[#E11D48]">
{loginError}
</div>
)}
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Email
</label>
<input
type="email"
value={loginEmail}
onChange={(e) => setLoginEmail(e.target.value)}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900"
required
/>
</div>
<div>
<label className="block text-xs font-semibold text-zinc-700 mb-1">
Mật khẩu
</label>
<input
type="password"
value={loginPassword}
onChange={(e) => setLoginPassword(e.target.value)}
className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900"
required
/>
</div>
<Button
type="submit"
variant="primary"
className="w-full"
disabled={loginBusy}
>
<LogIn className="w-3.5 h-3.5" />
<span>{loginBusy ? 'Đang đăng nhập...' : 'Đăng Nhập'}</span>
</Button>
</form>
</div>
)}
</div>
);
};
export default App;
import React, { useEffect, useState } from 'react';
import {
Film,
Mic,
FolderOpen,
Layers,
Palette,
Cpu,
Cloud,
Trash2,
CheckCircle2,
RefreshCw,
Sparkles,
Plus,
ShieldCheck,
Lock,
Unlock,
Users,
LogOut,
LogIn,
FileSpreadsheet,
} from 'lucide-react';
import { api } from './api';
import type {
Project,
AIProviderProfile,
AIRoleRoutingEntry,
AssetItem,
BrandKit,
FrozenRecipe,
} from '@olokaflow/shared';
import { StudioWorkspaceView } from './components/StudioWorkspaceView';
import { BatchStudioView } from './components/BatchStudioView';
import { AIProfileHubView } from './components/AIProfileHubView';
import { AssetLibraryView } from './components/AssetLibraryView';
import { CatalogBrowserView } from './components/CatalogBrowserView';
import { Button, Badge } from './components/ui/primitives';
type MainTab =
| 'studio'
| 'batch'
| 'voices'
| 'assets'
| 'catalog'
| 'brands'
| 'ai_profiles'
| 'vault';
export const App: React.FC = () => {
const [activeTab, setActiveTab] = useState<MainTab>('studio');
const [projects, setProjects] = useState<Project[]>([]);
const [activeProjectId, setActiveProjectId] = useState<string>('');
const [catalog, setCatalog] = useState<any>(null);
const [profiles, setProfiles] = useState<AIProviderProfile[]>([]);
const [routings, setRoutings] = useState<AIRoleRoutingEntry[]>([]);
const [assets, setAssets] = useState<AssetItem[]>([]);
const [brands, setBrands] = useState<BrandKit[]>([]);
const [recipes, setRecipes] = useState<FrozenRecipe[]>([]);
const [vaultStatus, setVaultStatus] = useState<any>(null);
const [syncingVault, setSyncingVault] = useState(false);
// Auth Login Gate & Team Governance State
const [authChecked, setAuthChecked] = useState(false);
const [requireAuthGate, setRequireAuthGate] = useState(false);
const [currentUser, setCurrentUser] = useState<any | null>(null);
const [showLoginModal, setShowLoginModal] = useState(false);
const [loginEmail, setLoginEmail] = useState('admin@olokaflow.ai');
const [loginPassword, setLoginPassword] = useState('admin123');
const [loginError, setLoginError] = useState('');
const [loginBusy, setLoginBusy] = useState(false);
const [teamUsers, setTeamUsers] = useState<any[]>([]);
const [newUserEmail, setNewUserEmail] = useState('');
const [newUserName, setNewUserName] = useState('');
const [newUserPassword, setNewUserPassword] = useState('');
const [newUserRole, setNewUserRole] = useState<'creator' | 'admin'>('creator');
const [newUserQuota, setNewUserQuota] = useState(5000000);
// Brand Kit quick form state
const [newBrandName, setNewBrandName] = useState('');
const [newBrandTagline, setNewBrandTagline] = useState('');
const [newBrandPrimary, setNewBrandPrimary] = useState('#E11D48');
const [newBrandAccent, setNewBrandAccent] = useState('#18181B');
useEffect(() => {
void loadAllState();
}, []);
async function loadAllState() {
try {
const [authRes, projRes, catRes, aiRes, astRes, brdRes, vltRes, usrRes] =
await Promise.all([
api.getAuthMe().catch(() => ({
authenticated: false,
requireAuthGate: false,
user: null,
})),
api.getProjects(),
api.getCatalog(),
api.getAIProfiles(),