feat: Implement user profile management, add multi-language interactive transcripts, and lay groundwork for SSO.
This commit is contained in:
@@ -4,7 +4,7 @@ import { useState, useEffect } from 'react';
|
||||
import { cmsApi, Organization, getImageUrl } from '@/lib/api';
|
||||
import { useAuth } from '@/context/AuthContext';
|
||||
import Image from 'next/image';
|
||||
import { Plus, Building2, Globe, Calendar, ExternalLink, ShieldCheck, Palette, Upload, Save, X } from 'lucide-react';
|
||||
import { Plus, Building2, Globe, Calendar, ExternalLink, ShieldCheck, Palette, Upload, Save, X, Fingerprint, Key, Settings2 } from 'lucide-react';
|
||||
|
||||
export default function OrganizationsPage() {
|
||||
const [organizations, setOrganizations] = useState<Organization[]>([]);
|
||||
@@ -21,6 +21,14 @@ export default function OrganizationsPage() {
|
||||
const [isSavingBranding, setIsSavingBranding] = useState(false);
|
||||
const [uploadingLogo, setUploadingLogo] = useState(false);
|
||||
|
||||
// SSO States
|
||||
const [isSSOModalOpen, setIsSSOModalOpen] = useState(false);
|
||||
const [issuerUrl, setIssuerUrl] = useState('');
|
||||
const [clientId, setClientId] = useState('');
|
||||
const [clientSecret, setClientSecret] = useState('');
|
||||
const [ssoEnabled, setSsoEnabled] = useState(false);
|
||||
const [isSavingSSO, setIsSavingSSO] = useState(false);
|
||||
|
||||
const { user } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -96,6 +104,50 @@ export default function OrganizationsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const openSSOConfig = async (org: Organization) => {
|
||||
setSelectedOrg(org);
|
||||
setIsSSOModalOpen(true);
|
||||
// Temporarily set org in localStorage for API calls
|
||||
localStorage.setItem('studio_selected_org_id', org.id);
|
||||
try {
|
||||
const config = await cmsApi.getSSOConfig();
|
||||
if (config) {
|
||||
setIssuerUrl(config.issuer_url);
|
||||
setClientId(config.client_id);
|
||||
setClientSecret(config.client_secret);
|
||||
setSsoEnabled(config.enabled);
|
||||
} else {
|
||||
setIssuerUrl('');
|
||||
setClientId('');
|
||||
setClientSecret('');
|
||||
setSsoEnabled(false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load SSO config', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSSOSave = async () => {
|
||||
if (!selectedOrg) return;
|
||||
|
||||
setIsSavingSSO(true);
|
||||
try {
|
||||
await cmsApi.updateSSOConfig({
|
||||
issuer_url: issuerUrl,
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
enabled: ssoEnabled
|
||||
});
|
||||
setIsSSOModalOpen(false);
|
||||
alert('SSO configuration saved successfully!');
|
||||
} catch (error) {
|
||||
console.error('Failed to save SSO config', error);
|
||||
alert('Failed to save SSO config. Please ensure all fields are correct.');
|
||||
} finally {
|
||||
setIsSavingSSO(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (user?.role !== 'admin') {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[60vh] text-center">
|
||||
@@ -173,15 +225,21 @@ export default function OrganizationsPage() {
|
||||
{org.id.split('-')[0]}...
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<button
|
||||
onClick={() => openBranding(org)}
|
||||
className="py-2 px-4 text-sm font-medium border border-blue-500/20 bg-blue-500/5 hover:bg-blue-500/10 text-blue-400 rounded-lg transition-colors flex items-center justify-center gap-2"
|
||||
className="py-2 px-2 text-[10px] font-medium border border-blue-500/20 bg-blue-500/5 hover:bg-blue-500/10 text-blue-400 rounded-lg transition-colors flex items-center justify-center gap-1"
|
||||
>
|
||||
<Palette className="w-3 h-3" /> Branding
|
||||
<Palette className="w-3 h-3" /> Brand
|
||||
</button>
|
||||
<button className="py-2 px-4 text-sm font-medium border border-white/5 bg-white/5 hover:bg-white/10 rounded-lg transition-colors flex items-center justify-center gap-2">
|
||||
Details <ExternalLink className="w-3 h-3" />
|
||||
<button
|
||||
onClick={() => openSSOConfig(org)}
|
||||
className="py-2 px-2 text-[10px] font-medium border border-blue-500/20 bg-blue-500/5 hover:bg-blue-500/10 text-blue-400 rounded-lg transition-colors flex items-center justify-center gap-1"
|
||||
>
|
||||
<Fingerprint className="w-3 h-3" /> SSO
|
||||
</button>
|
||||
<button className="py-2 px-2 text-[10px] font-medium border border-white/5 bg-white/5 hover:bg-white/10 rounded-lg transition-colors flex items-center justify-center gap-1 text-gray-400">
|
||||
Docs <ExternalLink className="w-3 h-3" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -376,6 +434,114 @@ export default function OrganizationsPage() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{/* SSO Configuration Modal */}
|
||||
{isSSOModalOpen && selectedOrg && (
|
||||
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200">
|
||||
<div className="w-full max-w-xl glass border border-white/10 rounded-2xl p-8 shadow-2xl">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-blue-500/10 text-blue-400">
|
||||
<Fingerprint className="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-xl font-bold">Single Sign-On (OIDC)</h2>
|
||||
<p className="text-sm text-gray-400">{selectedOrg.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={() => setIsSSOModalOpen(false)} className="p-2 hover:bg-white/5 rounded-full transition-colors">
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between p-4 rounded-xl bg-white/5 border border-white/10">
|
||||
<div>
|
||||
<h3 className="font-medium text-white">Enable OIDC SSO</h3>
|
||||
<p className="text-xs text-gray-500">Allow users to log in via your identity provider.</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setSsoEnabled(!ssoEnabled)}
|
||||
className={`w-12 h-6 rounded-full transition-colors relative ${ssoEnabled ? 'bg-blue-600' : 'bg-gray-700'}`}
|
||||
>
|
||||
<div className={`absolute top-1 w-4 h-4 bg-white rounded-full transition-all ${ssoEnabled ? 'right-1' : 'left-1'}`} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 pt-2">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-400 mb-1.5">Issuer URL</label>
|
||||
<div className="relative">
|
||||
<Globe className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
|
||||
<input
|
||||
type="url"
|
||||
value={issuerUrl}
|
||||
onChange={(e) => setIssuerUrl(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg pl-10 pr-4 py-2.5 focus:outline-none focus:ring-2 focus:ring-blue-500/50 transition-all font-mono text-sm"
|
||||
placeholder="https://accounts.google.com or https://okta.com/..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-400 mb-1.5">Client ID</label>
|
||||
<div className="relative">
|
||||
<ShieldCheck className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
|
||||
<input
|
||||
type="text"
|
||||
value={clientId}
|
||||
onChange={(e) => setClientId(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg pl-10 pr-4 py-2.5 focus:outline-none focus:ring-2 focus:ring-blue-500/50 transition-all font-mono text-sm"
|
||||
placeholder="Your OIDC Client ID"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-400 mb-1.5">Client Secret</label>
|
||||
<div className="relative">
|
||||
<Key className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
|
||||
<input
|
||||
type="password"
|
||||
value={clientSecret}
|
||||
onChange={(e) => setClientSecret(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg pl-10 pr-4 py-2.5 focus:outline-none focus:ring-2 focus:ring-blue-500/50 transition-all font-mono text-sm"
|
||||
placeholder="••••••••••••••••"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-4 rounded-xl bg-blue-500/10 border border-blue-500/20 space-y-2">
|
||||
<div className="flex items-center gap-2 text-blue-400 text-xs font-bold">
|
||||
<Settings2 className="w-4 h-4" /> CONFIGURATION STEPS
|
||||
</div>
|
||||
<p className="text-[10px] text-blue-300 leading-relaxed">
|
||||
1. Register OpenCCB as an application in your Identity Provider (Okta, Google, Azure AD).<br />
|
||||
2. Set the Redirect URI to: <span className="font-mono bg-blue-500/20 px-1">http://localhost:3001/auth/sso/callback</span><br />
|
||||
3. Copy the Issuer URL, Client ID, and Client Secret here.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 mt-8">
|
||||
<button
|
||||
onClick={() => setIsSSOModalOpen(false)}
|
||||
className="flex-1 px-4 py-3 bg-white/5 hover:bg-white/10 border border-white/10 rounded-xl transition-all font-medium"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSSOSave}
|
||||
disabled={isSavingSSO}
|
||||
className="flex-[2] px-8 py-3 bg-blue-600 hover:bg-blue-500 text-white rounded-xl transition-all shadow-lg shadow-blue-500/20 font-bold flex items-center justify-center gap-2"
|
||||
>
|
||||
{isSavingSSO ? <div className="w-5 h-5 border-2 border-white/20 border-t-white rounded-full animate-spin" /> : <Save className="w-5 h-5" />}
|
||||
Save SSO Settings
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, Suspense } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { cmsApi } from "@/lib/api";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
function CallbackHandler() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { login } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
const token = searchParams.get("token");
|
||||
if (token) {
|
||||
// Temporarily store token so getMe can use it
|
||||
localStorage.setItem('studio_token', token);
|
||||
|
||||
cmsApi.getMe()
|
||||
.then((user) => {
|
||||
login(user, token);
|
||||
router.push("/");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("SSO Error:", err);
|
||||
localStorage.removeItem('studio_token');
|
||||
router.push("/auth/login?error=sso_failed");
|
||||
});
|
||||
} else {
|
||||
router.push("/auth/login");
|
||||
}
|
||||
}, [searchParams, login, router]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<Loader2 className="w-12 h-12 text-blue-500 animate-spin" />
|
||||
<h2 className="text-xl font-bold text-white text-center">
|
||||
Completing your sign in...
|
||||
</h2>
|
||||
<p className="text-gray-400">Please wait a moment.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AuthCallbackPage() {
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-950 flex items-center justify-center p-4">
|
||||
<Suspense fallback={
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<Loader2 className="w-12 h-12 text-blue-500 animate-spin" />
|
||||
</div>
|
||||
}>
|
||||
<CallbackHandler />
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -16,6 +16,8 @@ export default function StudioLoginPage() {
|
||||
const [fullName, setFullName] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [ssoMode, setSSOMode] = useState(false);
|
||||
const [orgIdForSSO, setOrgIdForSSO] = useState("");
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -86,83 +88,107 @@ export default function StudioLoginPage() {
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{!isLogin && (
|
||||
{!ssoMode ? (
|
||||
<>
|
||||
{!isLogin && (
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Full Name
|
||||
</label>
|
||||
<div className="relative">
|
||||
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
value={fullName}
|
||||
onChange={(e) => setFullName(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="John Doe"
|
||||
autoComplete="name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Organization Name (Optional)
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Building2 className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
value={organizationName}
|
||||
onChange={(e) => setOrganizationName(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="Your School or Company"
|
||||
autoComplete="organization"
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2 pl-1">
|
||||
If left blank, an organization will be created based on your email domain.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Full Name
|
||||
Email
|
||||
</label>
|
||||
<div className="relative">
|
||||
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
value={fullName}
|
||||
onChange={(e) => setFullName(e.target.value)}
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="John Doe"
|
||||
autoComplete="name"
|
||||
placeholder="instructor@example.com"
|
||||
autoComplete="email"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Organization Name (Optional)
|
||||
Password
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Building2 className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
value={organizationName}
|
||||
onChange={(e) => setOrganizationName(e.target.value)}
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="Your School or Company"
|
||||
autoComplete="organization"
|
||||
placeholder="••••••••"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2 pl-1">
|
||||
If left blank, an organization will be created based on your email domain.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Organization ID
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Building2 className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
value={orgIdForSSO}
|
||||
onChange={(e) => setOrgIdForSSO(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="00000000-0000-0000-0000-000000000000"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2 pl-1">
|
||||
Contact your administrator if you don't know your Organization ID.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Email
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="instructor@example.com"
|
||||
autoComplete="email"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-300 mb-2">
|
||||
Password
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl py-3 pl-11 pr-4 text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="••••••••"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-500/10 border border-red-500/20 rounded-xl p-3 text-red-400 text-sm">
|
||||
{error}
|
||||
@@ -172,9 +198,39 @@ export default function StudioLoginPage() {
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
onClick={(e) => {
|
||||
if (ssoMode) {
|
||||
e.preventDefault();
|
||||
if (!orgIdForSSO) {
|
||||
setError("Organization ID is required");
|
||||
return;
|
||||
}
|
||||
cmsApi.initSSOLogin(orgIdForSSO);
|
||||
}
|
||||
}}
|
||||
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-xl transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{loading ? "Processing..." : isLogin ? "Sign In" : "Create Account"}
|
||||
{loading ? "Processing..." : ssoMode ? "Continue with SSO" : isLogin ? "Sign In" : "Create Account"}
|
||||
</button>
|
||||
|
||||
<div className="relative my-6">
|
||||
<div className="absolute inset-0 flex items-center">
|
||||
<span className="w-full border-t border-white/10"></span>
|
||||
</div>
|
||||
<div className="relative flex justify-center text-xs uppercase">
|
||||
<span className="bg-[#020617] px-2 text-gray-500">Or</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSSOMode(!ssoMode);
|
||||
setError("");
|
||||
}}
|
||||
className="w-full bg-white/5 hover:bg-white/10 text-white font-bold py-3 rounded-xl border border-white/10 transition-colors"
|
||||
>
|
||||
{ssoMode ? "Use Email & Password" : "Login with Enterprise SSO"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ export default function LessonEditor({ params }: { params: { id: string; lessonI
|
||||
<span className="text-2xl">🪄</span>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold italic tracking-tight">AI Content Assistant</h3>
|
||||
<p className="text-xs text-gray-400 mt-1 uppercase tracking-widest font-bold">Automate your content creation</p>
|
||||
<p className="text-xs text-gray-400 mt-1 uppercase tracking-widest font-bold">Automate your content creation with Local AI</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -453,14 +453,17 @@ export default function LessonEditor({ params }: { params: { id: string; lessonI
|
||||
<span className="text-xl">
|
||||
{lesson.transcription_status === 'queued' || lesson.transcription_status === 'processing' ? '⏳' : '🎤'}
|
||||
</span>
|
||||
<div className="text-[10px] font-black uppercase tracking-widest opacity-80">Video/Audio</div>
|
||||
<div className="text-[10px] font-black uppercase tracking-widest opacity-80">Transcription & Translation</div>
|
||||
<div className="font-bold">
|
||||
{lesson.transcription_status === 'queued'
|
||||
? `Queued (${formatTime(transcriptionTimer)})`
|
||||
: lesson.transcription_status === 'processing'
|
||||
? `Transcribing (${formatTime(transcriptionTimer)})`
|
||||
: lesson.transcription ? 'Update Transcript' : 'Transcribe Video'}
|
||||
? `Processing (${formatTime(transcriptionTimer)})`
|
||||
: lesson.transcription ? 'Regenerate Content' : 'Transcribe & Translate'}
|
||||
</div>
|
||||
{lesson.transcription && !lesson.transcription.es && lesson.transcription_status === 'completed' && (
|
||||
<div className="text-[8px] text-amber-500 font-bold uppercase">Translation missing</div>
|
||||
)}
|
||||
{(lesson.transcription_status === 'queued' || lesson.transcription_status === 'processing') && (
|
||||
<div className="absolute bottom-0 left-0 h-1 bg-blue-500 animate-[progress_2s_ease-in-out_infinite]" style={{ width: '100%' }}></div>
|
||||
)}
|
||||
@@ -502,7 +505,7 @@ export default function LessonEditor({ params }: { params: { id: string; lessonI
|
||||
<span className="text-2xl">✨</span>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold font-black italic tracking-tight">AI Lesson Summary</h3>
|
||||
<p className="text-xs text-gray-400 mt-1 uppercase tracking-widest font-bold">Key insights generated by intelligence</p>
|
||||
<p className="text-xs text-gray-400 mt-1 uppercase tracking-widest font-bold">Key insights generated from content</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,24 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { cmsApi } from "@/lib/api";
|
||||
import { Save, Shield, Mail, User as UserIcon, Building } from "lucide-react";
|
||||
import { cmsApi, getImageUrl } from "@/lib/api";
|
||||
import {
|
||||
Save,
|
||||
Shield,
|
||||
Mail,
|
||||
User as UserIcon,
|
||||
Building,
|
||||
Camera,
|
||||
Languages,
|
||||
FileText,
|
||||
LogOut,
|
||||
Trash2
|
||||
} from "lucide-react";
|
||||
|
||||
export default function ProfilePage() {
|
||||
const { user, logout } = useAuth();
|
||||
const [fullName, setFullName] = useState(user?.full_name || "");
|
||||
const [email, setEmail] = useState(user?.email || "");
|
||||
const [bio, setBio] = useState(user?.bio || "");
|
||||
const [language, setLanguage] = useState(user?.language || "en");
|
||||
const [avatarUrl, setAvatarUrl] = useState(user?.avatar_url || "");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setFullName(user.full_name);
|
||||
setEmail(user.email);
|
||||
setBio(user.bio || "");
|
||||
setLanguage(user.language || "en");
|
||||
setAvatarUrl(user.avatar_url || "");
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const handleAvatarUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file || !user) return;
|
||||
|
||||
try {
|
||||
setUploading(true);
|
||||
const res = await cmsApi.uploadAsset(file);
|
||||
setAvatarUrl(res.url);
|
||||
|
||||
// Auto-save the new avatar URL
|
||||
await cmsApi.updateUser(user.id, { avatar_url: res.url });
|
||||
setMessage({ type: 'success', text: 'Avatar updated successfully!' });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setMessage({ type: 'error', text: 'Failed to upload avatar.' });
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!user) return;
|
||||
@@ -29,14 +68,12 @@ export default function ProfilePage() {
|
||||
|
||||
await cmsApi.updateUser(user.id, {
|
||||
full_name: fullName,
|
||||
// In this simplified version, we don't allow email change here to avoid complexity
|
||||
bio,
|
||||
language,
|
||||
avatar_url: avatarUrl
|
||||
});
|
||||
|
||||
setMessage({ type: 'success', text: 'Profile updated successfully!' });
|
||||
|
||||
// Optionally update the local user state if needed,
|
||||
// but usually a page refresh or context update would be better.
|
||||
// For now, let's just show the message.
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setMessage({ type: 'error', text: 'Failed to update profile.' });
|
||||
@@ -48,101 +85,196 @@ export default function ProfilePage() {
|
||||
if (!user) return null;
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto py-12 px-6">
|
||||
<div className="max-w-5xl mx-auto py-12 px-6">
|
||||
<div className="mb-12">
|
||||
<h1 className="text-4xl font-black tracking-tight text-white mb-2">User Profile</h1>
|
||||
<p className="text-gray-400">Manage your personal information and account settings.</p>
|
||||
<p className="text-gray-400">Manage your identity and preferences across the platform.</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
|
||||
{/* Profile Card */}
|
||||
<div className="md:col-span-1">
|
||||
<div className="glass p-8 rounded-3xl border border-white/5 flex flex-col items-center text-center">
|
||||
<div className="w-24 h-24 rounded-full bg-blue-600/20 border-2 border-blue-500/30 flex items-center justify-center font-black text-3xl text-blue-400 mb-4 shadow-2xl shadow-blue-500/20">
|
||||
{user.full_name.charAt(0)}
|
||||
</div>
|
||||
<h2 className="text-xl font-bold text-white">{user.full_name}</h2>
|
||||
<span className="text-xs font-black uppercase tracking-widest text-blue-500 mt-1">{user.role}</span>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
{/* Left Column: Profile Card */}
|
||||
<div className="lg:col-span-1 space-y-6">
|
||||
<div className="glass p-8 rounded-[2rem] border border-white/5 flex flex-col items-center text-center relative overflow-hidden group">
|
||||
{/* Avatar Section */}
|
||||
<div className="relative mb-6">
|
||||
<div className="w-32 h-32 rounded-full bg-blue-600/20 border-4 border-white/5 flex items-center justify-center overflow-hidden shadow-2xl relative">
|
||||
{avatarUrl ? (
|
||||
<img
|
||||
src={getImageUrl(avatarUrl)}
|
||||
alt={fullName}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="text-5xl font-black text-blue-400">
|
||||
{fullName.charAt(0)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="w-full h-px bg-white/5 my-6" />
|
||||
|
||||
<div className="w-full flex flex-col gap-4 text-left">
|
||||
<div className="flex items-center gap-3 text-sm text-gray-400">
|
||||
<Building size={16} className="text-gray-600" />
|
||||
<span className="truncate">Org: {user.organization_id}</span>
|
||||
{uploading && (
|
||||
<div className="absolute inset-0 bg-black/60 flex items-center justify-center">
|
||||
<div className="w-8 h-8 border-2 border-white/20 border-t-white rounded-full animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-sm text-gray-400">
|
||||
<Shield size={16} className="text-gray-600" />
|
||||
<span>Role: {user.role}</span>
|
||||
|
||||
<button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="absolute bottom-0 right-0 w-10 h-10 bg-blue-600 hover:bg-blue-500 rounded-full flex items-center justify-center text-white shadow-xl border-4 border-[#0a0a0b] transition-transform active:scale-90"
|
||||
>
|
||||
<Camera size={18} />
|
||||
</button>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
className="hidden"
|
||||
accept="image/*"
|
||||
onChange={handleAvatarUpload}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<h2 className="text-2xl font-black text-white">{fullName}</h2>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<span className="text-[10px] font-black uppercase tracking-widest text-blue-500 bg-blue-500/10 px-3 py-1 rounded-full border border-blue-500/10">
|
||||
{user.role}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-full h-px bg-white/5 my-8" />
|
||||
|
||||
<div className="w-full space-y-4 text-left">
|
||||
<div className="flex items-center gap-4 p-3 rounded-2xl bg-white/5 border border-white/5">
|
||||
<Building size={18} className="text-gray-500" />
|
||||
<div className="min-w-0">
|
||||
<p className="text-[10px] font-black uppercase tracking-tighter text-gray-500">Organization</p>
|
||||
<p className="text-xs font-bold text-white truncate">{user.organization_id}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 p-3 rounded-2xl bg-white/5 border border-white/5">
|
||||
<Shield size={18} className="text-gray-500" />
|
||||
<div className="min-w-0">
|
||||
<p className="text-[10px] font-black uppercase tracking-tighter text-gray-500">Access Level</p>
|
||||
<p className="text-xs font-bold text-white truncate capitalize">{user.role}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={logout}
|
||||
className="mt-8 w-full py-3 rounded-xl border border-white/10 text-sm font-bold text-gray-400 hover:text-white hover:bg-white/5 transition-all"
|
||||
className="mt-10 w-full py-4 rounded-2xl border border-white/5 bg-white/5 text-sm font-black text-gray-400 hover:text-white hover:bg-red-500/10 hover:border-red-500/20 transition-all flex items-center justify-center gap-3 group/logout"
|
||||
>
|
||||
Logout Session
|
||||
<LogOut size={18} className="group-hover/logout:-translate-x-1 transition-transform" />
|
||||
Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Settings Form */}
|
||||
<div className="md:col-span-2 space-y-6">
|
||||
<form onSubmit={handleSave} className="glass p-8 rounded-3xl border border-white/5 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-black uppercase tracking-widest text-gray-500 flex items-center gap-2">
|
||||
<UserIcon size={14} /> Full Name
|
||||
{/* Right Column: Settings Form */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
<form onSubmit={handleSave} className="glass p-10 rounded-[2.5rem] border border-white/5 space-y-8">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-black uppercase tracking-[0.2em] text-gray-500 flex items-center gap-2">
|
||||
<UserIcon size={14} className="text-blue-500" /> Personal Name
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={fullName}
|
||||
onChange={(e) => setFullName(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-2xl px-6 py-4 text-white focus:outline-none focus:border-blue-500/50 focus:ring-4 focus:ring-blue-500/5 transition-all outline-none"
|
||||
placeholder="Enter your full name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 opacity-60">
|
||||
<label className="text-xs font-black uppercase tracking-[0.2em] text-gray-500 flex items-center gap-2">
|
||||
<Mail size={14} className="text-blue-500" /> Email Address
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
disabled
|
||||
className="w-full bg-black/20 border border-white/5 rounded-2xl px-6 py-4 text-white/50 cursor-not-allowed"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-black uppercase tracking-[0.2em] text-gray-500 flex items-center gap-2">
|
||||
<FileText size={14} className="text-blue-500" /> Biography
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={fullName}
|
||||
onChange={(e) => setFullName(e.target.value)}
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-blue-500/50 transition-colors"
|
||||
placeholder="Enter your full name"
|
||||
required
|
||||
<textarea
|
||||
value={bio}
|
||||
onChange={(e) => setBio(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-2xl px-6 py-4 text-white focus:outline-none focus:border-blue-500/50 focus:ring-4 focus:ring-blue-500/5 transition-all min-h-[140px] resize-none outline-none"
|
||||
placeholder="Tell us a bit about yourself..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 opacity-60">
|
||||
<label className="text-xs font-black uppercase tracking-widest text-gray-500 flex items-center gap-2">
|
||||
<Mail size={14} /> Email Address
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-black uppercase tracking-[0.2em] text-gray-500 flex items-center gap-2">
|
||||
<Languages size={14} className="text-blue-500" /> Preferred Language
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
disabled
|
||||
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-white/50 cursor-not-allowed"
|
||||
/>
|
||||
<p className="text-[10px] text-gray-500 italic">Email cannot be changed currently.</p>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
{[
|
||||
{ code: 'en', label: 'English', flag: '🇺🇸' },
|
||||
{ code: 'es', label: 'Spanish', flag: '🇪🇸' },
|
||||
{ code: 'pt', label: 'Portuguese', flag: '🇧🇷' }
|
||||
].map((lang) => (
|
||||
<button
|
||||
key={lang.code}
|
||||
type="button"
|
||||
onClick={() => setLanguage(lang.code)}
|
||||
className={`flex items-center justify-center gap-3 p-4 rounded-2xl border transition-all ${language === lang.code
|
||||
? 'bg-blue-600 border-blue-500 text-white shadow-lg shadow-blue-500/20'
|
||||
: 'bg-black/20 border-white/5 text-gray-400 hover:border-white/20 hover:text-white'
|
||||
}`}
|
||||
>
|
||||
<span className="text-xl">{lang.flag}</span>
|
||||
<span className="text-sm font-bold">{lang.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{message && (
|
||||
<div className={`p-4 rounded-xl text-sm font-medium ${message.type === 'success' ? 'bg-green-500/10 text-green-400 border border-green-500/20' : 'bg-red-500/10 text-red-400 border border-red-500/20'}`}>
|
||||
<div className={`p-5 rounded-2xl text-sm font-bold animate-in fade-in slide-in-from-top-4 ${message.type === 'success'
|
||||
? 'bg-green-500/10 text-green-400 border border-green-500/20'
|
||||
: 'bg-red-500/10 text-red-400 border border-red-500/20'
|
||||
}`}>
|
||||
{message.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="w-full py-4 bg-blue-600 hover:bg-blue-500 disabled:bg-blue-600/50 rounded-xl font-black text-white shadow-lg shadow-blue-500/20 transition-all active:scale-[0.98] flex items-center justify-center gap-3"
|
||||
>
|
||||
{saving ? (
|
||||
<div className="w-5 h-5 border-2 border-white/20 border-t-white rounded-full animate-spin" />
|
||||
) : (
|
||||
<Save size={20} />
|
||||
)}
|
||||
Save Changes
|
||||
</button>
|
||||
<div className="pt-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="w-full py-5 bg-blue-600 hover:bg-blue-500 disabled:bg-blue-600/50 rounded-2xl font-black text-white shadow-2xl shadow-blue-500/20 transition-all active:scale-[0.98] flex items-center justify-center gap-3 text-lg"
|
||||
>
|
||||
{saving ? (
|
||||
<div className="w-6 h-6 border-3 border-white/20 border-t-white rounded-full animate-spin" />
|
||||
) : (
|
||||
<Save size={24} />
|
||||
)}
|
||||
Sync Profile Data
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div className="glass p-6 rounded-3xl border border-red-500/10 bg-red-500/5 items-center justify-between flex">
|
||||
<div>
|
||||
<h3 className="text-red-400 font-bold">Danger Zone</h3>
|
||||
<p className="text-xs text-red-400/60 mt-0.5">Deleting your account is permanent.</p>
|
||||
{/* Danger Zone */}
|
||||
<div className="glass p-8 rounded-[2rem] border border-red-500/10 bg-red-500/5 flex items-center justify-between">
|
||||
<div className="flex items-center gap-6">
|
||||
<div className="w-14 h-14 rounded-2xl bg-red-500/10 flex items-center justify-center text-red-400 border border-red-500/20 shadow-lg">
|
||||
<Trash2 size={24} />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-red-400 font-black text-lg">Danger Zone</h3>
|
||||
<p className="text-xs text-red-400/60 mt-1">This will permanently delete your identity and data.</p>
|
||||
</div>
|
||||
</div>
|
||||
<button className="px-4 py-2 border border-red-500/20 rounded-lg text-xs font-black text-red-400 hover:bg-red-500/10 transition-colors uppercase tracking-widest">
|
||||
Delete Account
|
||||
<button className="px-8 py-3 border border-red-500/20 rounded-xl text-xs font-black text-red-400 hover:bg-red-500/10 transition-all uppercase tracking-widest active:scale-95">
|
||||
Purge Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -107,6 +107,19 @@ export interface User {
|
||||
full_name: string;
|
||||
role: string;
|
||||
organization_id?: string;
|
||||
avatar_url?: string;
|
||||
bio?: string;
|
||||
language?: string;
|
||||
}
|
||||
|
||||
export interface OrganizationSSOConfig {
|
||||
organization_id: string;
|
||||
issuer_url: string;
|
||||
client_id: string;
|
||||
client_secret: string;
|
||||
enabled: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AuthResponse {
|
||||
@@ -231,6 +244,7 @@ export const cmsApi = {
|
||||
// Auth
|
||||
register: (payload: AuthPayload): Promise<AuthResponse> => apiFetch('/auth/register', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
login: (payload: AuthPayload): Promise<AuthResponse> => apiFetch('/auth/login', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
getMe: (): Promise<User> => apiFetch('/auth/me'),
|
||||
|
||||
// Courses
|
||||
getCourses: (): Promise<Course[]> => apiFetch('/courses'),
|
||||
@@ -266,7 +280,7 @@ export const cmsApi = {
|
||||
|
||||
// Users
|
||||
getAllUsers: (): Promise<User[]> => apiFetch('/users'),
|
||||
updateUser: (id: string, payload: { role?: string, organization_id?: string, full_name?: string }): Promise<void> => apiFetch(`/users/${id}`, { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
updateUser: (id: string, payload: { role?: string, organization_id?: string, full_name?: string, avatar_url?: string, bio?: string, language?: string }): Promise<void> => apiFetch(`/users/${id}`, { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
|
||||
// Webhooks
|
||||
getWebhooks: (): Promise<Webhook[]> => apiFetch('/webhooks'),
|
||||
@@ -332,6 +346,13 @@ export const cmsApi = {
|
||||
});
|
||||
},
|
||||
|
||||
// SSO
|
||||
getSSOConfig: (): Promise<OrganizationSSOConfig | null> => apiFetch('/organization/sso'),
|
||||
updateSSOConfig: (payload: Partial<OrganizationSSOConfig>): Promise<OrganizationSSOConfig> => apiFetch('/organization/sso', { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
initSSOLogin: (orgId: string): void => {
|
||||
window.location.href = `${API_BASE_URL}/auth/sso/login/${orgId}`;
|
||||
},
|
||||
|
||||
// Background Tasks
|
||||
getBackgroundTasks: (): Promise<BackgroundTask[]> => apiFetch('/tasks'),
|
||||
retryTask: (id: string): Promise<void> => apiFetch(`/tasks/${id}/retry`, { method: 'POST' }),
|
||||
|
||||
Reference in New Issue
Block a user