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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 102x 102x 102x 102x 102x 102x 2x 2x 2x 100x 100x 100x 100x 100x 102x 2x 2x 2x 98x 98x 98x 98x 98x 102x 2x 2x 2x 96x 102x 102x 160x 160x 10x 10x 10x 10x 10x 10x 160x 160x 10x 10x 10x 10x 10x 10x 160x 160x 163x 163x 123x 163x 24x 163x 16x 163x 163x 163x 163x 160x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 160x 19x 19x 19x 19x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 640x 640x 640x 640x 90x 550x 160x 390x 640x 640x 90x 550x 640x 640x 640x 640x 640x 640x 640x 640x 480x 480x 480x 480x 480x 640x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 114x 114x 114x 114x 114x 114x 114x 1710x 1710x 1710x 1710x 1710x 1710x 1710x 40x 1710x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 912x 912x 912x 912x 20x 892x 912x 912x 912x 912x 912x 114x 114x 114x 114x 114x 160x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 54x 54x 54x 54x 18x 36x 54x 54x 54x 54x 54x 54x 54x 54x 18x 18x 18x 18x 18x 18x 160x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 160x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 160x 160x 160x 160x 160x 160x 160x 144x 144x 144x 16x 16x 2x 2x 2x 14x 14x 14x 16x 160x 160x 160x 160x 160x | 'use client';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { motion, AnimatePresence } from 'framer-motion';
import {
GraduationCap,
BookOpen,
Clock,
IndianRupee,
ChevronLeft,
ChevronRight,
Check,
Loader2,
Plus,
X,
} from 'lucide-react';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Badge } from '@/components/ui/badge';
import { Switch } from '@/components/ui/switch';
import { Checkbox } from '@/components/ui/checkbox';
import { createClient } from '@/lib/supabase/client';
import { toast } from '@/hooks/use-toast';
const STEPS = [
{ id: 'subjects', title: 'Subjects', icon: BookOpen },
{ id: 'experience', title: 'Experience', icon: GraduationCap },
{ id: 'pricing', title: 'Pricing', icon: IndianRupee },
{ id: 'settings', title: 'Settings', icon: Clock },
];
const COMMON_SUBJECTS = [
'Mathematics',
'Physics',
'Chemistry',
'Biology',
'English',
'Hindi',
'Computer Science',
'Economics',
'Accounting',
'Business Studies',
'History',
'Geography',
'Political Science',
'Psychology',
'Sociology',
];
const GRADE_LEVELS = [
'Primary (1-5)',
'Middle School (6-8)',
'High School (9-10)',
'Senior Secondary (11-12)',
'Undergraduate',
'Postgraduate',
'Competitive Exams',
'Professional Certification',
];
const TEACHING_MODES = [
{ id: 'online', label: 'Online', description: 'Video calls via Zoom, Google Meet, etc.' },
{ id: 'in_person', label: 'In Person', description: 'Face-to-face at a location' },
{ id: 'hybrid', label: 'Hybrid', description: 'Both online and in-person' },
];
const tutorSetupSchema = z.object({
subjects: z.array(z.string()).min(1, 'Select at least one subject'),
gradeLevels: z.array(z.string()).min(1, 'Select at least one grade level'),
teachingModes: z.array(z.string()).min(1, 'Select at least one teaching mode'),
yearsExperience: z.number().min(0).max(50),
education: z.string().optional(),
qualifications: z.array(z.string()).optional(),
hourlyRate: z.number().min(100, 'Minimum rate is ₹100/hr'),
trialSessionPrice: z.number().min(0),
trialDurationMinutes: z.number().min(15).max(60),
teachingLanguages: z.array(z.string()).min(1),
instantBooking: z.boolean(),
requireApproval: z.boolean(),
maxStudents: z.number().min(1).max(100),
isAcceptingStudents: z.boolean(),
});
type TutorSetupForm = z.infer<typeof tutorSetupSchema>;
export default function TutorSetupPage() {
const [currentStep, setCurrentStep] = useState(0);
const [loading, setLoading] = useState(false);
const [profileId, setProfileId] = useState<string | null>(null);
const [customSubject, setCustomSubject] = useState('');
const router = useRouter();
const form = useForm<TutorSetupForm>({
resolver: zodResolver(tutorSetupSchema),
defaultValues: {
subjects: [],
gradeLevels: [],
teachingModes: ['online'],
yearsExperience: 0,
education: '',
qualifications: [],
hourlyRate: 500,
trialSessionPrice: 0,
trialDurationMinutes: 30,
teachingLanguages: ['English', 'Hindi'],
instantBooking: false,
requireApproval: true,
maxStudents: 10,
isAcceptingStudents: true,
},
});
const {
watch,
setValue,
handleSubmit,
formState: { errors },
} = form;
const formValues = watch();
useEffect(() => {
const supabase = createClient();
async function checkProfile() {
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
router.push('/login');
return;
}
const { data: profile } = await supabase
.from('profiles')
.select('id')
.eq('user_id', user.id)
.single();
if (!profile) {
router.push('/profile');
return;
}
// Check if tutor profile already exists
const { data: existingTutor } = await supabase
.from('tutor_profiles')
.select('id')
.eq('profile_id', profile.id)
.single();
if (existingTutor) {
router.push('/tutor');
return;
}
setProfileId(profile.id);
}
checkProfile();
}, [router]);
const toggleSubject = (subject: string) => {
const current = formValues.subjects;
if (current.includes(subject)) {
setValue(
'subjects',
current.filter((s) => s !== subject)
);
} else {
setValue('subjects', [...current, subject]);
}
};
const addCustomSubject = () => {
if (customSubject.trim() && !formValues.subjects.includes(customSubject.trim())) {
setValue('subjects', [...formValues.subjects, customSubject.trim()]);
setCustomSubject('');
}
};
const toggleGradeLevel = (level: string) => {
const current = formValues.gradeLevels;
if (current.includes(level)) {
setValue(
'gradeLevels',
current.filter((l) => l !== level)
);
} else {
setValue('gradeLevels', [...current, level]);
}
};
const toggleTeachingMode = (mode: string) => {
const current = formValues.teachingModes;
if (current.includes(mode)) {
if (current.length > 1) {
setValue(
'teachingModes',
current.filter((m) => m !== mode)
);
}
} else {
setValue('teachingModes', [...current, mode]);
}
};
const canProceed = () => {
switch (currentStep) {
case 0:
return formValues.subjects.length > 0 && formValues.gradeLevels.length > 0;
case 1:
return true;
case 2:
return formValues.hourlyRate >= 100;
case 3:
return true;
default:
return false;
}
};
const onSubmit = async (data: TutorSetupForm) => {
if (!profileId) return;
setLoading(true);
const supabase = createClient();
try {
const { error } = await supabase.from('tutor_profiles').insert({
profile_id: profileId,
subjects: data.subjects,
grade_levels: data.gradeLevels,
teaching_modes: data.teachingModes,
years_experience: data.yearsExperience,
education: data.education || null,
qualifications: data.qualifications || [],
hourly_rate_inr: data.hourlyRate * 100, // Convert to paise
trial_session_price: data.trialSessionPrice * 100,
trial_duration_minutes: data.trialDurationMinutes,
teaching_languages: data.teachingLanguages,
instant_booking: data.instantBooking,
require_approval: data.requireApproval,
max_students: data.maxStudents,
is_accepting_students: data.isAcceptingStudents,
});
if (error) throw error;
// Update profile type
await supabase.from('profiles').update({ profile_type: 'tutor' }).eq('id', profileId);
toast({ title: 'Success', description: 'Tutor profile created successfully!' });
router.refresh(); // Refresh to update navigation and sidebar state
router.push('/tutor');
} catch (error) {
console.error('Error creating tutor profile:', error);
toast({
title: 'Error',
description: 'Failed to create tutor profile',
variant: 'destructive',
});
} finally {
setLoading(false);
}
};
const nextStep = () => {
if (currentStep < STEPS.length - 1 && canProceed()) {
setCurrentStep(currentStep + 1);
}
};
const prevStep = () => {
if (currentStep > 0) {
setCurrentStep(currentStep - 1);
}
};
return (
<div className="mx-auto max-w-3xl space-y-8">
{/* Header */}
<div>
<h1 className="text-3xl font-bold">Set Up Your Tutor Profile</h1>
<p className="text-muted-foreground">
Complete these steps to start accepting tutoring sessions
</p>
</div>
{/* Progress Steps */}
<div className="flex items-center justify-between">
{STEPS.map((step, index) => (
<div key={step.id} className="flex items-center">
<div
className={`flex h-10 w-10 items-center justify-center rounded-full border-2 transition-colors ${
index < currentStep
? 'border-primary bg-primary text-primary-foreground'
: index === currentStep
? 'border-primary text-primary'
: 'border-muted text-muted-foreground'
}`}
>
{index < currentStep ? (
<Check className="h-5 w-5" />
) : (
<step.icon className="h-5 w-5" />
)}
</div>
<span
className={`ml-2 hidden text-sm font-medium sm:block ${
index <= currentStep ? 'text-foreground' : 'text-muted-foreground'
}`}
>
{step.title}
</span>
{index < STEPS.length - 1 && (
<div
className={`mx-2 h-0.5 w-12 sm:mx-4 sm:w-24 ${
index < currentStep ? 'bg-primary' : 'bg-muted'
}`}
/>
)}
</div>
))}
</div>
{/* Step Content */}
<Card>
<CardContent className="pt-6">
<AnimatePresence mode="wait">
<motion.div
key={currentStep}
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -20 }}
transition={{ duration: 0.2 }}
>
{currentStep === 0 && (
<div className="space-y-6">
<div>
<h2 className="mb-2 text-xl font-semibold">What subjects do you teach?</h2>
<p className="mb-4 text-sm text-muted-foreground">
Select all that apply or add custom subjects
</p>
<div className="mb-4 flex flex-wrap gap-2">
{COMMON_SUBJECTS.map((subject) => (
<Badge
key={subject}
variant={formValues.subjects.includes(subject) ? 'default' : 'outline'}
className="cursor-pointer transition-colors hover:bg-primary/90"
onClick={() => toggleSubject(subject)}
>
{subject}
{formValues.subjects.includes(subject) && (
<Check className="ml-1 h-3 w-3" />
)}
</Badge>
))}
</div>
<div className="flex gap-2">
<Input
placeholder="Add custom subject..."
value={customSubject}
onChange={(e) => setCustomSubject(e.target.value)}
onKeyDown={(e) =>
e.key === 'Enter' && (e.preventDefault(), addCustomSubject())
}
/>
<Button variant="outline" onClick={addCustomSubject}>
<Plus className="h-4 w-4" />
</Button>
</div>
{formValues.subjects.filter((s) => !COMMON_SUBJECTS.includes(s)).length > 0 && (
<div className="mt-3 flex flex-wrap gap-2">
{formValues.subjects
.filter((s) => !COMMON_SUBJECTS.includes(s))
.map((subject) => (
<Badge key={subject} variant="secondary">
{subject}
<button className="ml-1" onClick={() => toggleSubject(subject)}>
<X className="h-3 w-3" />
</button>
</Badge>
))}
</div>
)}
{errors.subjects && (
<p className="mt-2 text-sm text-destructive">{errors.subjects.message}</p>
)}
</div>
<div>
<h2 className="mb-2 text-xl font-semibold">What grade levels do you teach?</h2>
<div className="grid grid-cols-2 gap-2">
{GRADE_LEVELS.map((level) => (
<div
key={level}
className={`flex cursor-pointer items-center gap-2 rounded-lg border p-3 transition-colors ${
formValues.gradeLevels.includes(level)
? 'border-primary bg-primary/5'
: 'hover:bg-muted'
}`}
onClick={() => toggleGradeLevel(level)}
>
<Checkbox checked={formValues.gradeLevels.includes(level)} />
<span className="text-sm">{level}</span>
</div>
))}
</div>
{errors.gradeLevels && (
<p className="mt-2 text-sm text-destructive">{errors.gradeLevels.message}</p>
)}
</div>
</div>
)}
{currentStep === 1 && (
<div className="space-y-6">
<div>
<h2 className="mb-4 text-xl font-semibold">Your Teaching Experience</h2>
<div className="space-y-4">
<div>
<Label htmlFor="yearsExperience">Years of Teaching Experience</Label>
<Input
id="yearsExperience"
type="number"
min={0}
max={50}
value={formValues.yearsExperience}
onChange={(e) =>
setValue('yearsExperience', parseInt(e.target.value) || 0)
}
className="mt-1"
/>
</div>
<div>
<Label htmlFor="education">Education / Degrees</Label>
<Textarea
id="education"
placeholder="e.g., B.Tech in Computer Science from IIT Delhi"
value={formValues.education}
onChange={(e) => setValue('education', e.target.value)}
className="mt-1"
/>
</div>
<div>
<Label>Teaching Mode Preference</Label>
<div className="mt-2 grid gap-3">
{TEACHING_MODES.map((mode) => (
<div
key={mode.id}
className={`flex cursor-pointer items-center justify-between rounded-lg border p-4 transition-colors ${
formValues.teachingModes.includes(mode.id)
? 'border-primary bg-primary/5'
: 'hover:bg-muted'
}`}
onClick={() => toggleTeachingMode(mode.id)}
>
<div>
<p className="font-medium">{mode.label}</p>
<p className="text-sm text-muted-foreground">{mode.description}</p>
</div>
<Switch checked={formValues.teachingModes.includes(mode.id)} />
</div>
))}
</div>
</div>
</div>
</div>
</div>
)}
{currentStep === 2 && (
<div className="space-y-6">
<div>
<h2 className="mb-4 text-xl font-semibold">Set Your Pricing</h2>
<div className="space-y-6">
<div>
<Label htmlFor="hourlyRate">Hourly Rate (INR)</Label>
<div className="relative mt-1">
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground">
₹
</span>
<Input
id="hourlyRate"
type="number"
min={100}
value={formValues.hourlyRate}
onChange={(e) => setValue('hourlyRate', parseInt(e.target.value) || 0)}
className="pl-8"
/>
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground">
/hour
</span>
</div>
<p className="mt-1 text-sm text-muted-foreground">
This is your standard hourly rate for sessions
</p>
{errors.hourlyRate && (
<p className="mt-1 text-sm text-destructive">
{errors.hourlyRate.message}
</p>
)}
</div>
<div className="border-t pt-6">
<h3 className="mb-4 font-medium">Trial Session (Optional)</h3>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label htmlFor="trialPrice">Trial Session Price</Label>
<div className="relative mt-1">
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground">
₹
</span>
<Input
id="trialPrice"
type="number"
min={0}
value={formValues.trialSessionPrice}
onChange={(e) =>
setValue('trialSessionPrice', parseInt(e.target.value) || 0)
}
className="pl-8"
/>
</div>
<p className="mt-1 text-xs text-muted-foreground">
Set to 0 for free trial sessions
</p>
</div>
<div>
<Label htmlFor="trialDuration">Trial Duration</Label>
<div className="relative mt-1">
<Input
id="trialDuration"
type="number"
min={15}
max={60}
step={5}
value={formValues.trialDurationMinutes}
onChange={(e) =>
setValue('trialDurationMinutes', parseInt(e.target.value) || 30)
}
/>
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground">
min
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
)}
{currentStep === 3 && (
<div className="space-y-6">
<div>
<h2 className="mb-4 text-xl font-semibold">Booking Settings</h2>
<div className="space-y-4">
<div className="flex items-center justify-between rounded-lg border p-4">
<div>
<p className="font-medium">Accepting New Students</p>
<p className="text-sm text-muted-foreground">
Toggle off to pause new bookings
</p>
</div>
<Switch
checked={formValues.isAcceptingStudents}
onCheckedChange={(checked) => setValue('isAcceptingStudents', checked)}
/>
</div>
<div className="flex items-center justify-between rounded-lg border p-4">
<div>
<p className="font-medium">Instant Booking</p>
<p className="text-sm text-muted-foreground">
Allow students to book without approval
</p>
</div>
<Switch
checked={formValues.instantBooking}
onCheckedChange={(checked) => {
setValue('instantBooking', checked);
if (checked) setValue('requireApproval', false);
}}
/>
</div>
{!formValues.instantBooking && (
<div className="flex items-center justify-between rounded-lg border p-4">
<div>
<p className="font-medium">Require Approval</p>
<p className="text-sm text-muted-foreground">
Review and approve each booking request
</p>
</div>
<Switch
checked={formValues.requireApproval}
onCheckedChange={(checked) => setValue('requireApproval', checked)}
/>
</div>
)}
<div>
<Label htmlFor="maxStudents">Maximum Active Students</Label>
<Input
id="maxStudents"
type="number"
min={1}
max={100}
value={formValues.maxStudents}
onChange={(e) => setValue('maxStudents', parseInt(e.target.value) || 10)}
className="mt-1"
/>
<p className="mt-1 text-sm text-muted-foreground">
Limit the number of students you work with simultaneously
</p>
</div>
</div>
</div>
</div>
)}
</motion.div>
</AnimatePresence>
{/* Navigation Buttons */}
<div className="mt-8 flex justify-between border-t pt-6">
<Button variant="outline" onClick={prevStep} disabled={currentStep === 0}>
<ChevronLeft className="mr-2 h-4 w-4" />
Back
</Button>
{currentStep < STEPS.length - 1 ? (
<Button onClick={nextStep} disabled={!canProceed()}>
Next
<ChevronRight className="ml-2 h-4 w-4" />
</Button>
) : (
<Button onClick={handleSubmit(onSubmit)} disabled={loading}>
{loading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Creating...
</>
) : (
<>
<Check className="mr-2 h-4 w-4" />
Create Tutor Profile
</>
)}
</Button>
)}
</div>
</CardContent>
</Card>
</div>
);
}
|