Simplify navigation and modernize profile and sign-in
This commit is contained in:
+169
-486
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState, type FormEvent, type KeyboardEvent } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { authFetch, clearToken, getApiBase, getToken } from '../lib/auth'
|
||||
|
||||
type ProfileInfo = {
|
||||
@@ -9,542 +9,225 @@ type ProfileInfo = {
|
||||
email?: string | null
|
||||
role: string
|
||||
auth_provider: string
|
||||
invite_management_enabled?: boolean
|
||||
password_change_supported?: boolean
|
||||
password_provider?: 'local' | 'jellyfin' | null
|
||||
}
|
||||
|
||||
type ProfileStats = {
|
||||
total: number
|
||||
ready: number
|
||||
pending: number
|
||||
in_progress: number
|
||||
declined: number
|
||||
working: number
|
||||
partial: number
|
||||
approved: number
|
||||
last_request_at?: string | null
|
||||
share: number
|
||||
global_total: number
|
||||
most_active_user?: { username: string; total: number } | null
|
||||
}
|
||||
|
||||
type ActivityEntry = {
|
||||
ip: string
|
||||
user_agent: string
|
||||
first_seen_at: string
|
||||
last_seen_at: string
|
||||
hit_count: number
|
||||
}
|
||||
|
||||
type ProfileActivity = {
|
||||
last_ip?: string | null
|
||||
last_user_agent?: string | null
|
||||
last_seen_at?: string | null
|
||||
device_count: number
|
||||
recent: ActivityEntry[]
|
||||
}
|
||||
|
||||
type ProfileResponse = {
|
||||
user: ProfileInfo
|
||||
stats: ProfileStats
|
||||
activity: ProfileActivity
|
||||
stats?: { total: number; ready: number; in_progress: number }
|
||||
activity?: { recent: ActivityEntry[] }
|
||||
}
|
||||
|
||||
type ProfileTab = 'overview' | 'activity' | 'security'
|
||||
|
||||
const normalizeProfileTab = (value?: string | null): ProfileTab => {
|
||||
if (value === 'activity' || value === 'security') {
|
||||
return value
|
||||
}
|
||||
return 'overview'
|
||||
}
|
||||
|
||||
const formatDate = (value?: string | null) => {
|
||||
if (!value) return 'Never'
|
||||
type Notice = { tone: 'status' | 'error'; message: string } | null
|
||||
type ProfileTab = 'overview' | 'security' | 'activity'
|
||||
const TABS: { key: ProfileTab; label: string }[] = [
|
||||
{ key: 'overview', label: 'Account' },
|
||||
{ key: 'security', label: 'Security' },
|
||||
{ key: 'activity', label: 'Activity' },
|
||||
]
|
||||
const normalizeTab = (value: string | null): ProfileTab => value === 'security' || value === 'activity' ? value : 'overview'
|
||||
const formatDate = (value?: string) => {
|
||||
if (!value) return 'Not recorded'
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.valueOf())) return value
|
||||
return date.toLocaleString()
|
||||
return Number.isNaN(date.valueOf()) ? 'Not recorded' : date.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })
|
||||
}
|
||||
|
||||
const isValidEmail = (value: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim())
|
||||
|
||||
const parseBrowser = (agent?: string | null) => {
|
||||
if (!agent) return 'Unknown'
|
||||
const value = agent.toLowerCase()
|
||||
if (value.includes('edg/')) return 'Edge'
|
||||
if (value.includes('chrome/') && !value.includes('edg/')) return 'Chrome'
|
||||
if (value.includes('firefox/')) return 'Firefox'
|
||||
if (value.includes('safari/') && !value.includes('chrome/')) return 'Safari'
|
||||
return 'Unknown'
|
||||
const deviceName = (agent: string) => {
|
||||
const value = (agent || '').toLowerCase()
|
||||
const browser = value.includes('edg/') ? 'Edge' : value.includes('firefox/') || value.includes('fxios/') ? 'Firefox'
|
||||
: value.includes('chrome/') || value.includes('crios/') ? 'Chrome' : value.includes('safari/') ? 'Safari' : 'Browser'
|
||||
const device = /iphone|ipad/.test(value) ? 'iOS' : value.includes('android') ? 'Android'
|
||||
: value.includes('windows') ? 'Windows' : value.includes('macintosh') ? 'Mac' : value.includes('linux') ? 'Linux' : ''
|
||||
return device ? `${browser} on ${device}` : browser
|
||||
}
|
||||
const responseMessage = async (response: Response, fallback: string) => {
|
||||
const data = await response.json().catch(() => null)
|
||||
return typeof data?.detail === 'string' && data.detail.trim() ? data.detail : fallback
|
||||
}
|
||||
|
||||
export default function ProfilePage() {
|
||||
const router = useRouter()
|
||||
const [profile, setProfile] = useState<ProfileInfo | null>(null)
|
||||
const [stats, setStats] = useState<ProfileStats | null>(null)
|
||||
const [activity, setActivity] = useState<ProfileActivity | null>(null)
|
||||
const [data, setData] = useState<ProfileResponse | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadError, setLoadError] = useState('')
|
||||
const [activeTab, setActiveTab] = useState<ProfileTab>('overview')
|
||||
const [email, setEmail] = useState('')
|
||||
const [emailSaving, setEmailSaving] = useState(false)
|
||||
const [emailStatus, setEmailStatus] = useState<{ tone: 'status' | 'error'; message: string } | null>(null)
|
||||
const [emailNotice, setEmailNotice] = useState<Notice>(null)
|
||||
const [currentPassword, setCurrentPassword] = useState('')
|
||||
const [newPassword, setNewPassword] = useState('')
|
||||
const [confirmPassword, setConfirmPassword] = useState('')
|
||||
const [status, setStatus] = useState<{ tone: 'status' | 'error'; message: string } | null>(null)
|
||||
const [activeTab, setActiveTab] = useState<ProfileTab>('overview')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [passwordSaving, setPasswordSaving] = useState(false)
|
||||
const [passwordNotice, setPasswordNotice] = useState<Notice>(null)
|
||||
const [showAllActivity, setShowAllActivity] = useState(false)
|
||||
|
||||
const inviteLink = useMemo(() => '/profile/invites', [])
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return
|
||||
const syncTabFromLocation = () => {
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
setActiveTab(normalizeProfileTab(params.get('tab')))
|
||||
const loadProfile = useCallback(async () => {
|
||||
if (!getToken()) { router.replace('/login'); return }
|
||||
setLoading(true)
|
||||
setLoadError('')
|
||||
try {
|
||||
const response = await authFetch(`${getApiBase()}/auth/profile`)
|
||||
if (response.status === 401) { clearToken(); router.replace('/login'); return }
|
||||
if (!response.ok) throw new Error('Could not load your profile. Please try again.')
|
||||
const profile = await response.json() as ProfileResponse
|
||||
setData(profile)
|
||||
setEmail(profile.user.email ?? '')
|
||||
} catch {
|
||||
setLoadError('Could not load your profile. Please try again.')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
syncTabFromLocation()
|
||||
window.addEventListener('popstate', syncTabFromLocation)
|
||||
return () => window.removeEventListener('popstate', syncTabFromLocation)
|
||||
}, [router])
|
||||
|
||||
useEffect(() => { void loadProfile() }, [loadProfile])
|
||||
useEffect(() => {
|
||||
const syncTab = () => setActiveTab(normalizeTab(new URLSearchParams(window.location.search).get('tab')))
|
||||
syncTab()
|
||||
window.addEventListener('popstate', syncTab)
|
||||
return () => window.removeEventListener('popstate', syncTab)
|
||||
}, [])
|
||||
|
||||
const selectTab = (tab: ProfileTab) => {
|
||||
setActiveTab(tab)
|
||||
router.replace(tab === 'overview' ? '/profile' : `/profile?tab=${tab}`)
|
||||
router.replace(tab === 'overview' ? '/profile' : `/profile?tab=${tab}`, { scroll: false })
|
||||
}
|
||||
const tabKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {
|
||||
let next = index
|
||||
if (event.key === 'ArrowRight') next = (index + 1) % TABS.length
|
||||
else if (event.key === 'ArrowLeft') next = (index + TABS.length - 1) % TABS.length
|
||||
else if (event.key === 'Home') next = 0
|
||||
else if (event.key === 'End') next = TABS.length - 1
|
||||
else return
|
||||
event.preventDefault()
|
||||
selectTab(TABS[next].key)
|
||||
document.getElementById(`profile-tab-${TABS[next].key}`)?.focus()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
const load = async () => {
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const profileResponse = await authFetch(`${baseUrl}/auth/profile`)
|
||||
if (!profileResponse.ok) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
const data = (await profileResponse.json()) as ProfileResponse
|
||||
const user = data?.user ?? {}
|
||||
setProfile({
|
||||
username: user?.username ?? 'Unknown',
|
||||
email: user?.email ?? null,
|
||||
role: user?.role ?? 'user',
|
||||
auth_provider: user?.auth_provider ?? 'local',
|
||||
invite_management_enabled: Boolean(user?.invite_management_enabled ?? false),
|
||||
password_change_supported: Boolean(user?.password_change_supported ?? false),
|
||||
password_provider:
|
||||
user?.password_provider === 'jellyfin' || user?.password_provider === 'local'
|
||||
? user.password_provider
|
||||
: null,
|
||||
})
|
||||
setEmail(user?.email ?? '')
|
||||
setStats(data?.stats ?? null)
|
||||
setActivity(data?.activity ?? null)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setStatus({ tone: 'error', message: 'Could not load your profile.' })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
void load()
|
||||
}, [router])
|
||||
|
||||
const submit = async (event: React.FormEvent) => {
|
||||
const saveEmail = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault()
|
||||
setStatus(null)
|
||||
if (!currentPassword || !newPassword) {
|
||||
setStatus({ tone: 'error', message: 'Enter your current password and a new password.' })
|
||||
if (emailSaving) return
|
||||
setEmailSaving(true)
|
||||
setEmailNotice(null)
|
||||
try {
|
||||
const response = await authFetch(`${getApiBase()}/auth/profile/email`, {
|
||||
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: email.trim() || null }),
|
||||
})
|
||||
if (response.status === 401) { clearToken(); router.replace('/login'); return }
|
||||
if (!response.ok) throw new Error(await responseMessage(response, 'Could not save your email. Please try again.'))
|
||||
const result = await response.json()
|
||||
const saved = typeof result.email === 'string' ? result.email : ''
|
||||
setData((current) => current ? { ...current, user: { ...current.user, email: saved || null } } : current)
|
||||
setEmail(saved)
|
||||
setEmailNotice({ tone: 'status', message: saved ? 'Email saved.' : 'Email removed.' })
|
||||
} catch (error) {
|
||||
setEmailNotice({ tone: 'error', message: error instanceof Error ? error.message : 'Could not save your email.' })
|
||||
} finally { setEmailSaving(false) }
|
||||
}
|
||||
|
||||
const savePassword = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault()
|
||||
if (passwordSaving) return
|
||||
setPasswordNotice(null)
|
||||
if (newPassword.trim().length < 8) {
|
||||
setPasswordNotice({ tone: 'error', message: 'Use at least 8 characters for your new password.' })
|
||||
return
|
||||
}
|
||||
if (newPassword !== confirmPassword) {
|
||||
setStatus({ tone: 'error', message: 'New password and confirmation do not match.' })
|
||||
setPasswordNotice({ tone: 'error', message: 'The new passwords do not match.' })
|
||||
return
|
||||
}
|
||||
setPasswordSaving(true)
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/auth/password`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
current_password: currentPassword,
|
||||
new_password: newPassword,
|
||||
}),
|
||||
const response = await authFetch(`${getApiBase()}/auth/password`, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ current_password: currentPassword, new_password: newPassword }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
let detail = 'Update failed'
|
||||
try {
|
||||
const payload = await response.json()
|
||||
if (typeof payload?.detail === 'string' && payload.detail.trim()) {
|
||||
detail = payload.detail
|
||||
}
|
||||
} catch {
|
||||
const text = await response.text().catch(() => '')
|
||||
if (text?.trim()) detail = text
|
||||
}
|
||||
throw new Error(detail)
|
||||
}
|
||||
const data = await response.json().catch(() => ({}))
|
||||
setCurrentPassword('')
|
||||
setNewPassword('')
|
||||
setConfirmPassword('')
|
||||
setStatus({
|
||||
tone: 'status',
|
||||
message:
|
||||
data?.provider === 'jellyfin'
|
||||
? 'Password updated across Jellyfin and Magent. Seerr continues to use the same Jellyfin password.'
|
||||
: 'Password updated.',
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
if (err instanceof Error && err.message) {
|
||||
setStatus({ tone: 'error', message: `Could not update password. ${err.message}` })
|
||||
} else {
|
||||
setStatus({ tone: 'error', message: 'Could not update password. Check your current password.' })
|
||||
}
|
||||
}
|
||||
if (!response.ok) throw new Error(await responseMessage(response, 'Could not change your password. Please try again.'))
|
||||
const result = await response.json()
|
||||
setCurrentPassword(''); setNewPassword(''); setConfirmPassword('')
|
||||
setPasswordNotice({ tone: 'status', message: result.provider === 'jellyfin'
|
||||
? 'Password updated for Grizzlyflix and Magent. Seerr uses the same password.'
|
||||
: 'Password updated.' })
|
||||
} catch (error) {
|
||||
setPasswordNotice({ tone: 'error', message: error instanceof Error ? error.message : 'Could not change your password.' })
|
||||
} finally { setPasswordSaving(false) }
|
||||
}
|
||||
|
||||
const saveEmail = async (event: React.FormEvent) => {
|
||||
event.preventDefault()
|
||||
const nextEmail = email.trim()
|
||||
setEmailStatus(null)
|
||||
if (nextEmail && !isValidEmail(nextEmail)) {
|
||||
setEmailStatus({ tone: 'error', message: 'Enter a valid email address.' })
|
||||
return
|
||||
}
|
||||
setEmailSaving(true)
|
||||
try {
|
||||
const response = await authFetch(`${getApiBase()}/auth/profile/email`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: nextEmail || null }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
let detail = 'Could not save your email address.'
|
||||
try {
|
||||
const payload = await response.json()
|
||||
if (typeof payload?.detail === 'string' && payload.detail.trim()) detail = payload.detail
|
||||
} catch {
|
||||
// Keep the plain fallback when the response is not JSON.
|
||||
}
|
||||
throw new Error(detail)
|
||||
}
|
||||
const data = await response.json()
|
||||
const savedEmail = typeof data?.email === 'string' ? data.email : ''
|
||||
setEmail(savedEmail)
|
||||
setProfile((current) => current ? { ...current, email: savedEmail || null } : current)
|
||||
setEmailStatus({
|
||||
tone: 'status',
|
||||
message: savedEmail
|
||||
? 'Contact email saved. Magent can now use it for account and issue updates.'
|
||||
: 'Contact email removed from your account.',
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setEmailStatus({
|
||||
tone: 'error',
|
||||
message: err instanceof Error ? err.message : 'Could not save your email address.',
|
||||
})
|
||||
} finally {
|
||||
setEmailSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const authProvider = profile?.auth_provider ?? 'local'
|
||||
const passwordProvider = profile?.password_provider ?? (authProvider === 'jellyfin' ? 'jellyfin' : 'local')
|
||||
const canManageInvites = profile?.role === 'admin' || Boolean(profile?.invite_management_enabled)
|
||||
const canChangePassword = Boolean(profile?.password_change_supported ?? (authProvider === 'local' || authProvider === 'jellyfin'))
|
||||
const securityHelpText =
|
||||
passwordProvider === 'jellyfin'
|
||||
? 'Reset your password here once. Magent updates Jellyfin directly, Seerr continues to use Jellyfin authentication, and Magent keeps the same password in sync.'
|
||||
: passwordProvider === 'local'
|
||||
? 'Change your Magent account password.'
|
||||
: 'Password changes are not available for this sign-in provider.'
|
||||
|
||||
if (loading) {
|
||||
return <main className="card">Loading profile...</main>
|
||||
}
|
||||
const user = data?.user
|
||||
const passwordProvider = user?.password_provider ?? (user?.auth_provider === 'jellyfin' ? 'jellyfin' : 'local')
|
||||
const canChangePassword = user?.password_change_supported ?? ['local', 'jellyfin'].includes(user?.auth_provider ?? '')
|
||||
const emailChanged = email.trim() !== (user?.email ?? '')
|
||||
const recent = data?.activity?.recent ?? []
|
||||
const notice = (value: Notice) => value && <p className={`account-notice is-${value.tone}`} role={value.tone === 'error' ? 'alert' : 'status'}>{value.message}</p>
|
||||
|
||||
return (
|
||||
<main className="card">
|
||||
<div className="user-directory-panel-header profile-page-header">
|
||||
<div>
|
||||
<h1>My profile</h1>
|
||||
<p className="lede">Review your account, activity, and security settings.</p>
|
||||
<main className="account-page">
|
||||
<header className="account-heading">
|
||||
<div><span className="account-eyebrow">YOUR ACCOUNT</span><h1>My profile</h1></div>
|
||||
{user && <div className="account-identity"><span className="account-avatar" aria-hidden="true">{user.username.slice(0, 1).toUpperCase()}</span><div><strong>{user.username}</strong><span>{user.role === 'admin' ? 'Administrator' : 'Member'}</span></div></div>}
|
||||
</header>
|
||||
|
||||
{loading ? <p className="account-empty" role="status">Loading your profile…</p> : loadError ? (
|
||||
<div className="account-empty"><p role="alert">{loadError}</p><button type="button" className="account-secondary" onClick={() => void loadProfile()}>Try again</button></div>
|
||||
) : user && <>
|
||||
<div className="account-tabs" role="tablist" aria-label="Profile sections">
|
||||
{TABS.map((tab, index) => <button key={tab.key} id={`profile-tab-${tab.key}`} type="button" role="tab"
|
||||
aria-selected={activeTab === tab.key} aria-controls={`profile-panel-${tab.key}`} tabIndex={activeTab === tab.key ? 0 : -1}
|
||||
onKeyDown={(event) => tabKeyDown(event, index)} onClick={() => selectTab(tab.key)}>{tab.label}</button>)}
|
||||
</div>
|
||||
{canManageInvites || canChangePassword ? (
|
||||
<div className="admin-inline-actions">
|
||||
{canManageInvites ? (
|
||||
<button type="button" className="ghost-button" onClick={() => router.push(inviteLink)}>
|
||||
Open invite page
|
||||
</button>
|
||||
) : null}
|
||||
{canChangePassword ? (
|
||||
<button type="button" onClick={() => selectTab('security')}>
|
||||
{passwordProvider === 'jellyfin' ? 'Reset Jellyfin password' : 'Change password'}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{profile && (
|
||||
<div className="status-banner">
|
||||
Signed in as <strong>{profile.username}</strong> ({profile.role}). Login type:{' '}
|
||||
{profile.auth_provider}.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="profile-tabbar">
|
||||
<div className="admin-segmented" role="tablist" aria-label="Profile sections">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={activeTab === 'overview'}
|
||||
className={activeTab === 'overview' ? 'is-active' : ''}
|
||||
onClick={() => selectTab('overview')}
|
||||
>
|
||||
Overview
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={activeTab === 'activity'}
|
||||
className={activeTab === 'activity' ? 'is-active' : ''}
|
||||
onClick={() => selectTab('activity')}
|
||||
>
|
||||
Activity
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={activeTab === 'security'}
|
||||
className={activeTab === 'security' ? 'is-active' : ''}
|
||||
onClick={() => selectTab('security')}
|
||||
>
|
||||
Password
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{activeTab === 'overview' && (
|
||||
<section className="profile-section profile-tab-panel">
|
||||
<div className="profile-quick-link-card profile-contact-card">
|
||||
<div>
|
||||
<h2>Contact email</h2>
|
||||
<p className="lede">
|
||||
Used for password recovery, invite messages, and updates about issues you report.
|
||||
</p>
|
||||
<section className="account-panel" id="profile-panel-overview" role="tabpanel" aria-labelledby="profile-tab-overview" hidden={activeTab !== 'overview'}>
|
||||
<div className="account-section-intro"><h2>Contact email</h2><p>For password recovery and updates on your reported issues.</p></div>
|
||||
<form className="account-form" onSubmit={saveEmail}>
|
||||
<label htmlFor="profile-email">Email address</label>
|
||||
<input id="profile-email" name="email" type="email" autoComplete="email" placeholder="you@example.com" value={email} disabled={emailSaving}
|
||||
onChange={(event) => { setEmail(event.target.value); setEmailNotice(null) }} />
|
||||
{!user.email && <p className="account-hint">Add an email so we can let you know when a fix is ready.</p>}
|
||||
{user.email && !email.trim() && <p className="account-hint">Saving without an email stops account and issue emails.</p>}
|
||||
{notice(emailNotice)}
|
||||
<div className="account-form-actions">
|
||||
<button type="submit" className="account-primary" disabled={emailSaving || !emailChanged}>{emailSaving ? 'Saving…' : 'Save email'}</button>
|
||||
{emailChanged && <button type="button" className="account-secondary" disabled={emailSaving} onClick={() => { setEmail(user.email ?? ''); setEmailNotice(null) }}>Discard</button>}
|
||||
</div>
|
||||
<form className="profile-contact-form" onSubmit={saveEmail}>
|
||||
<label>
|
||||
<span>Email address</span>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
placeholder="you@example.com"
|
||||
autoComplete="email"
|
||||
/>
|
||||
</label>
|
||||
{emailStatus ? (
|
||||
<div className={emailStatus.tone === 'error' ? 'error-banner' : 'status-banner'}>
|
||||
{emailStatus.message}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="admin-inline-actions">
|
||||
<button type="submit" disabled={emailSaving || Boolean(email.trim() && !isValidEmail(email))}>
|
||||
{emailSaving ? 'Saving…' : 'Save email'}
|
||||
</button>
|
||||
{profile?.email ? (
|
||||
<button type="button" className="ghost-button" onClick={() => setEmail('')}>
|
||||
Clear field
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{canManageInvites ? (
|
||||
<div className="profile-quick-link-card">
|
||||
<div>
|
||||
<h2>Invite tools</h2>
|
||||
<p className="lede">
|
||||
Create invite links, send them by email, and track who you have invited from a dedicated page.
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-inline-actions">
|
||||
<button type="button" onClick={() => router.push(inviteLink)}>
|
||||
Go to invites
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{canChangePassword ? (
|
||||
<div className="profile-quick-link-card">
|
||||
<div>
|
||||
<h2>{passwordProvider === 'jellyfin' ? 'Jellyfin password' : 'Password'}</h2>
|
||||
<p className="lede">
|
||||
{passwordProvider === 'jellyfin'
|
||||
? 'Update your shared Jellyfin, Seerr, and Magent password without leaving Magent.'
|
||||
: 'Update your Magent account password.'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-inline-actions">
|
||||
<button type="button" onClick={() => selectTab('security')}>
|
||||
{passwordProvider === 'jellyfin' ? 'Reset Jellyfin password' : 'Change password'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<h2>Account stats</h2>
|
||||
<div className="stat-grid">
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Requests submitted</div>
|
||||
<div className="stat-value">{stats?.total ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Ready to watch</div>
|
||||
<div className="stat-value">{stats?.ready ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">In progress</div>
|
||||
<div className="stat-value">{stats?.in_progress ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Pending approval</div>
|
||||
<div className="stat-value">{stats?.pending ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Declined</div>
|
||||
<div className="stat-value">{stats?.declined ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Working</div>
|
||||
<div className="stat-value">{stats?.working ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Partial</div>
|
||||
<div className="stat-value">{stats?.partial ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Approved</div>
|
||||
<div className="stat-value">{stats?.approved ?? 0}</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Last request</div>
|
||||
<div className="stat-value stat-value--small">
|
||||
{formatDate(stats?.last_request_at)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Share of all requests</div>
|
||||
<div className="stat-value">
|
||||
{stats?.global_total ? `${Math.round((stats.share || 0) * 1000) / 10}%` : '0%'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Total requests (global)</div>
|
||||
<div className="stat-value">{stats?.global_total ?? 0}</div>
|
||||
</div>
|
||||
{profile?.role === 'admin' ? (
|
||||
<div className="stat-card">
|
||||
<div className="stat-label">Most active user</div>
|
||||
<div className="stat-value stat-value--small">
|
||||
{stats?.most_active_user
|
||||
? `${stats.most_active_user.username} (${stats.most_active_user.total})`
|
||||
: 'N/A'}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</form>
|
||||
<div className="account-connected"><span className="account-connection-dot" aria-hidden="true" /><span>{user.auth_provider === 'jellyfin' ? 'Connected with your Grizzlyflix account' : user.auth_provider === 'local' ? 'Signed in with a Magent account' : 'Signed in with your media account'}</span></div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{activeTab === 'activity' && (
|
||||
<section className="profile-section profile-tab-panel">
|
||||
<h2>Connection history</h2>
|
||||
<div className="status-banner">
|
||||
Last seen {formatDate(activity?.last_seen_at)} from {activity?.last_ip ?? 'Unknown'}.
|
||||
</div>
|
||||
<div className="connection-list">
|
||||
{(activity?.recent ?? []).map((entry, index) => (
|
||||
<div key={`${entry.ip}-${entry.last_seen_at}-${index}`} className="connection-item">
|
||||
<div>
|
||||
<div className="connection-label">{parseBrowser(entry.user_agent)}</div>
|
||||
<div className="meta">IP: {entry.ip}</div>
|
||||
<div className="meta">First seen: {formatDate(entry.first_seen_at)}</div>
|
||||
<div className="meta">Last seen: {formatDate(entry.last_seen_at)}</div>
|
||||
</div>
|
||||
<div className="connection-count">{entry.hit_count} visits</div>
|
||||
</div>
|
||||
))}
|
||||
{activity && activity.recent.length === 0 ? (
|
||||
<div className="status-banner">No connection history yet.</div>
|
||||
) : null}
|
||||
</div>
|
||||
<section className="account-panel" id="profile-panel-security" role="tabpanel" aria-labelledby="profile-tab-security" hidden={activeTab !== 'security'}>
|
||||
<div className="account-section-intro"><h2>Change password</h2><p>{passwordProvider === 'jellyfin' ? 'One password for Grizzlyflix, Seerr and Magent.' : 'Keep your Magent account secure.'}</p></div>
|
||||
{canChangePassword ? <form className="account-form" onSubmit={savePassword}>
|
||||
<fieldset disabled={passwordSaving}>
|
||||
<label htmlFor="profile-current-password">Current password</label>
|
||||
<input id="profile-current-password" type="password" autoComplete="current-password" value={currentPassword} onChange={(event) => setCurrentPassword(event.target.value)} required />
|
||||
<label htmlFor="profile-new-password">New password</label>
|
||||
<input id="profile-new-password" type="password" autoComplete="new-password" aria-describedby="password-length" value={newPassword} onChange={(event) => setNewPassword(event.target.value)} minLength={8} required />
|
||||
<p id="password-length" className="account-hint">At least 8 characters.</p>
|
||||
<label htmlFor="profile-confirm-password">Confirm new password</label>
|
||||
<input id="profile-confirm-password" type="password" autoComplete="new-password" value={confirmPassword} onChange={(event) => setConfirmPassword(event.target.value)} minLength={8} required />
|
||||
</fieldset>
|
||||
{notice(passwordNotice)}
|
||||
<div className="account-form-actions"><button type="submit" className="account-primary" disabled={passwordSaving}>{passwordSaving ? 'Updating…' : 'Update password'}</button></div>
|
||||
</form> : <p className="account-empty">Password changes are managed by your sign-in provider. Contact an administrator for help.</p>}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{activeTab === 'security' && (
|
||||
<section className="profile-section profile-tab-panel">
|
||||
<h2>{passwordProvider === 'jellyfin' ? 'Jellyfin password reset' : 'Password'}</h2>
|
||||
<div className="status-banner">{securityHelpText}</div>
|
||||
{canChangePassword ? (
|
||||
<form onSubmit={submit} className="auth-form profile-security-form">
|
||||
<label>
|
||||
{passwordProvider === 'jellyfin' ? 'Current Jellyfin password' : 'Current password'}
|
||||
<input
|
||||
type="password"
|
||||
value={currentPassword}
|
||||
onChange={(event) => setCurrentPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{passwordProvider === 'jellyfin' ? 'New Jellyfin password' : 'New password'}
|
||||
<input
|
||||
type="password"
|
||||
value={newPassword}
|
||||
onChange={(event) => setNewPassword(event.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Confirm new password
|
||||
<input
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(event) => setConfirmPassword(event.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</label>
|
||||
{status ? (
|
||||
<div className={status.tone === 'error' ? 'error-banner' : 'status-banner'}>
|
||||
{status.message}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="auth-actions">
|
||||
<button type="submit">
|
||||
{passwordProvider === 'jellyfin' ? 'Reset Jellyfin password' : 'Update password'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<div className="status-banner">
|
||||
Password changes are not available for {authProvider} sign-in accounts from Magent.
|
||||
</div>
|
||||
)}
|
||||
<section className="account-panel" id="profile-panel-activity" role="tabpanel" aria-labelledby="profile-tab-activity" hidden={activeTab !== 'activity'}>
|
||||
<div className="account-section-intro"><h2>Your activity</h2><p>Your requests and recent account access.</p></div>
|
||||
{data?.stats && <div className="account-request-summary"><div><strong>{data.stats.total}</strong><span>Requests</span></div><div><strong>{data.stats.ready}</strong><span>Ready to watch</span></div><a href="/">View my requests <span aria-hidden="true">↗</span></a></div>}
|
||||
<h3 className="account-list-heading">Recent account access</h3>
|
||||
{recent.length ? <ul className="account-access-list">
|
||||
{(showAllActivity ? recent : recent.slice(0, 5)).map((entry, index) => <li key={`${entry.ip}-${entry.last_seen_at}-${index}`}>
|
||||
<div className="account-access-summary"><strong>{deviceName(entry.user_agent)}</strong><time dateTime={entry.last_seen_at}>{formatDate(entry.last_seen_at)}</time></div>
|
||||
<details><summary>Connection details</summary><dl><div><dt>IP address</dt><dd>{entry.ip || 'Not recorded'}</dd></div><div><dt>First seen</dt><dd>{formatDate(entry.first_seen_at)}</dd></div></dl></details>
|
||||
</li>)}
|
||||
</ul> : <p className="account-empty">No recent activity yet.</p>}
|
||||
{recent.length > 5 && <button className="account-secondary" type="button" onClick={() => setShowAllActivity(!showAllActivity)}>{showAllActivity ? 'Show less' : 'Show all activity'}</button>}
|
||||
</section>
|
||||
)}
|
||||
</>}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user