Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 3x | import React, { useState } from "react";
import { BrainCog, User, ArrowRight, Loader2 } from "lucide-react";
import { CoreUser } from "@/objects/CoreUser";
interface OnboardingProps {
/** Auth0 user display name pre-filled from the session */
defaultName: string;
/** Called with the provisioned CoreUser after successful form submission */
onComplete: (user: CoreUser) => void;
/** Called to provision the user via the API */
onProvision: (name: string) => Promise<CoreUser | null>;
}
const Onboarding: React.FC<OnboardingProps> = ({
defaultName,
onComplete,
onProvision,
}) => {
const [name, setName] = useState(defaultName);
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name.trim()) return;
setSubmitting(true);
setError(null);
try {
const user = await onProvision(name.trim());
if (!user) {
setError("Something went wrong. Please try again.");
return;
}
onComplete(user);
} catch {
setError("Something went wrong. Please try again.");
} finally {
setSubmitting(false);
}
};
return (
<div className="min-h-screen bg-gray-50 dark:bg-gray-950 flex items-center justify-center p-4">
<div className="w-full max-w-md">
{/* Logo / brand */}
<div className="flex justify-center mb-8">
<div className="flex items-center gap-2">
<BrainCog className="size-8 text-gray-800 dark:text-gray-100" />
<span className="text-xl font-bold text-gray-900 dark:text-white tracking-tight">
CHAIN-R
</span>
</div>
</div>
{/* Card */}
<div className="bg-white dark:bg-gray-900 rounded-2xl border border-gray-200 dark:border-gray-800 shadow-sm p-8">
<div className="mb-6 text-center">
<div className="inline-flex items-center justify-center size-12 rounded-full bg-gray-100 dark:bg-gray-800 mb-4">
<User className="size-6 text-gray-600 dark:text-gray-300" />
</div>
<h1 className="text-xl font-semibold text-gray-900 dark:text-white">
Complete your profile
</h1>
<p className="text-sm text-gray-500 dark:text-gray-400 mt-1">
Just one more step before you get started.
</p>
</div>
<form onSubmit={(e) => void handleSubmit(e)} className="space-y-5">
<div>
<label
htmlFor="name"
className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5"
>
Display name
</label>
<input
id="name"
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
required
placeholder="Your name"
className="w-full px-3.5 py-2.5 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-400 dark:focus:ring-gray-500 focus:border-transparent transition"
/>
</div>
{error && (
<p className="text-sm text-red-600 dark:text-red-400">{error}</p>
)}
<button
type="submit"
disabled={submitting || !name.trim()}
className="w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-sm font-medium hover:opacity-80 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed"
>
{submitting ? (
<Loader2 className="size-4 animate-spin" />
) : (
<>
Get started
<ArrowRight className="size-4" />
</>
)}
</button>
</form>
</div>
<p className="text-center text-xs text-gray-400 dark:text-gray-600 mt-6">
By continuing you agree to our{" "}
<a
href="/legal/terms-of-service"
className="underline hover:text-gray-600 dark:hover:text-gray-400"
>
Terms of Service
</a>{" "}
and{" "}
<a
href="/legal/privacy-policy"
className="underline hover:text-gray-600 dark:hover:text-gray-400"
>
Privacy Policy
</a>
.
</p>
</div>
</div>
);
};
export default Onboarding;
|