AWS SES preview
This commit is contained in:
118
components/Onboarding.tsx
Normal file
118
components/Onboarding.tsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import { useState } from 'react';
|
||||
import { Button } from './ui/button';
|
||||
import { Card, CardContent } from './ui/card';
|
||||
import { Input } from './ui/input';
|
||||
import { Label } from './ui/label';
|
||||
import { useSession } from '../lib/auth-client';
|
||||
|
||||
const logo = '/logo.png';
|
||||
|
||||
interface Props {
|
||||
onComplete: () => void;
|
||||
}
|
||||
|
||||
export function Onboarding({ onComplete }: Props) {
|
||||
const { data: session } = useSession();
|
||||
const [piFirstName, setPiFirstName] = useState('');
|
||||
const [bldgCode, setBldgCode] = useState('');
|
||||
const [lab, setLab] = useState('');
|
||||
const [contact, setContact] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
const res = await fetch('/api/profile', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
pi_first_name: piFirstName,
|
||||
bldg_code: bldgCode,
|
||||
lab,
|
||||
contact: contact || undefined,
|
||||
}),
|
||||
});
|
||||
setLoading(false);
|
||||
if (res.ok) {
|
||||
onComplete();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
setError(data.error || 'Failed to save profile');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen items-center justify-center bg-secondary">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardContent className="p-8 space-y-6">
|
||||
<div className="flex justify-center">
|
||||
<img src={logo} alt="LabWise" className="h-12" />
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<h2 className="font-semibold text-lg">
|
||||
Welcome{session?.user.name ? `, ${session.user.name.split(' ')[0]}` : ''}!
|
||||
</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Set up your lab details. These will be used as defaults when adding inventory.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="pi">PI first name</Label>
|
||||
<Input
|
||||
id="pi"
|
||||
type="text"
|
||||
value={piFirstName}
|
||||
onChange={e => setPiFirstName(e.target.value)}
|
||||
required
|
||||
placeholder="e.g. Smith"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="bldg">Building code</Label>
|
||||
<Input
|
||||
id="bldg"
|
||||
type="text"
|
||||
value={bldgCode}
|
||||
onChange={e => setBldgCode(e.target.value)}
|
||||
required
|
||||
placeholder="e.g. EER"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="lab">Lab</Label>
|
||||
<Input
|
||||
id="lab"
|
||||
type="text"
|
||||
value={lab}
|
||||
onChange={e => setLab(e.target.value)}
|
||||
required
|
||||
placeholder="e.g. 3.822"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="contact">
|
||||
Contact <span className="text-muted-foreground font-normal">(optional)</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="contact"
|
||||
type="text"
|
||||
value={contact}
|
||||
onChange={e => setContact(e.target.value)}
|
||||
placeholder="Phone or email"
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? 'Saving…' : 'Get started'}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user