Initial commit: Luminary photo catalog and RAW editor
Browser-based photo catalog with an optional team server (SQLite + LibRaw). Local database, uploaded photos, build output and dependencies are gitignored. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ApiError, loadInvite, register } from '../lib/api';
|
||||
import type { InviteInfo } from '../lib/api';
|
||||
|
||||
interface Props {
|
||||
token: string;
|
||||
}
|
||||
|
||||
const fmtDate = (ms: number | null) =>
|
||||
ms ? new Date(ms).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : '';
|
||||
|
||||
const STATUS_COPY: Record<string, { title: string; body: string }> = {
|
||||
accepted: {
|
||||
title: 'This invite has already been used',
|
||||
body: 'Each invite link works once. Sign in if the account is yours, or ask an admin for a fresh link.',
|
||||
},
|
||||
expired: {
|
||||
title: 'This invite has expired',
|
||||
body: 'Invite links are time-limited. Ask an admin to send you a new one.',
|
||||
},
|
||||
revoked: {
|
||||
title: 'This invite was turned off',
|
||||
body: 'An admin revoked this link. Ask them for a new invite if you still need access.',
|
||||
},
|
||||
};
|
||||
|
||||
/** Public signup screen reached from an admin's single-use invite link. */
|
||||
export default function JoinPage({ token }: Props) {
|
||||
const [invite, setInvite] = useState<InviteInfo | null>(null);
|
||||
const [missing, setMissing] = useState(false);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [email, setEmail] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
loadInvite(token)
|
||||
.then((next) => {
|
||||
if (!alive) return;
|
||||
setInvite(next);
|
||||
setEmail(next.email);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!alive) return;
|
||||
if (err instanceof ApiError && err.status === 404) setMissing(true);
|
||||
else setLoadError(err instanceof Error ? err.message : 'Could not check this invite');
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [token]);
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!invite || invite.status !== 'pending' || busy) return;
|
||||
if (password.length < 8) {
|
||||
setError('Use at least 8 characters for the password');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await register({
|
||||
email: email.trim(),
|
||||
password,
|
||||
name: name.trim(),
|
||||
inviteToken: token,
|
||||
});
|
||||
window.location.assign('/');
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Could not create the account');
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const state = missing ? 'missing' : invite?.status;
|
||||
const lockedEmail = Boolean(invite?.email);
|
||||
const copy =
|
||||
state === 'missing'
|
||||
? {
|
||||
title: 'This invite link is not valid',
|
||||
body: 'Check the link you were sent, or ask an admin for a new invite.',
|
||||
}
|
||||
: state && STATUS_COPY[state]
|
||||
? STATUS_COPY[state]
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div className="join-page">
|
||||
<div className="join-brand">
|
||||
<span className="brand-dot" />
|
||||
LUMINARY
|
||||
</div>
|
||||
|
||||
<main className="join-card">
|
||||
{!invite && !missing && !loadError && <p className="muted small">Checking your invite…</p>}
|
||||
|
||||
{loadError && (
|
||||
<>
|
||||
<span className="join-eyebrow">Invite</span>
|
||||
<h1>Can’t reach the server</h1>
|
||||
<p className="muted">{loadError}</p>
|
||||
<a className="btn ghost wide" href="/">
|
||||
Go to Luminary
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
|
||||
{copy && (
|
||||
<>
|
||||
<span className="join-eyebrow">Invite</span>
|
||||
<h1>{copy.title}</h1>
|
||||
<p className="muted">{copy.body}</p>
|
||||
<a className="btn primary wide" href="/">
|
||||
Go to sign in
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
|
||||
{invite?.status === 'pending' && (
|
||||
<>
|
||||
<span className="join-eyebrow">You’re invited</span>
|
||||
<h1>Join the studio</h1>
|
||||
<p className="muted join-lead">
|
||||
{lockedEmail
|
||||
? `Create your account for ${invite.email}. This link works once.`
|
||||
: 'Create your account to start editing, proofing and sharing photos. This link works once.'}
|
||||
</p>
|
||||
|
||||
<form className="join-form" onSubmit={submit}>
|
||||
<label className="field">
|
||||
<span>Email</span>
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
autoComplete="username"
|
||||
autoFocus={!lockedEmail}
|
||||
readOnly={lockedEmail}
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="you@studio.com"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="field">
|
||||
<span>Display name</span>
|
||||
<input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="Optional"
|
||||
autoComplete="name"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="field">
|
||||
<span>Password</span>
|
||||
<input
|
||||
type="password"
|
||||
required
|
||||
autoComplete="new-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="At least 8 characters"
|
||||
/>
|
||||
</label>
|
||||
|
||||
{error && <div className="banner error">{error}</div>}
|
||||
|
||||
<button
|
||||
className="btn primary wide"
|
||||
type="submit"
|
||||
disabled={busy || !email.trim() || password.length < 8}
|
||||
>
|
||||
{busy ? 'Creating account…' : 'Create account'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p className="join-meta">
|
||||
You’ll join as a {invite.role === 'admin' ? 'administrator' : 'member'}
|
||||
{invite.expiresAt ? ` · link expires ${fmtDate(invite.expiresAt)}` : ''}
|
||||
</p>
|
||||
<p className="join-foot">
|
||||
Already have an account? <a href="/">Sign in</a>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user