'use client' import { useState, useEffect } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' 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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { toast } from 'sonner' import { Loader2, CheckCircle, Crown, Award, Star } from 'lucide-react' import { signIn } from 'next-auth/react' interface PartnershipApplicationFormProps { isOpen: boolean onClose: () => void selectedTier?: string } export default function PartnershipApplicationForm({ isOpen, onClose, selectedTier = 'Silver' }: PartnershipApplicationFormProps) { const [formData, setFormData] = useState({ firstName: '', lastName: '', email: '', phone: '', businessName: '', businessType: '', experience: '', partnershipTier: selectedTier, expectedCustomers: '', address: '', city: '', state: '', zipCode: '', motivation: '', marketingPlan: '' }) const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) // Update form data when selectedTier prop changes useEffect(() => { setFormData(prev => ({ ...prev, partnershipTier: selectedTier })) }, [selectedTier]) // Reset form when modal opens useEffect(() => { if (isOpen) { setFormData({ firstName: '', lastName: '', email: '', phone: '', businessName: '', businessType: '', experience: '', partnershipTier: selectedTier, expectedCustomers: '', address: '', city: '', state: '', zipCode: '', motivation: '', marketingPlan: '' }) setIsSuccess(false) setIsSubmitting(false) } }, [isOpen, selectedTier]) const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsSubmitting(true) try { const response = await fetch('/api/partnership/apply', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ ...formData, expectedCustomers: parseInt(formData.expectedCustomers) || 0 }), }) const result = await response.json() if (result.success) { setIsSuccess(true) toast.success('Application submitted successfully! Check your email for login details.') // Auto-login the user after successful registration setTimeout(async () => { try { await signIn('credentials', { email: formData.email, redirect: false }) window.location.href = '/dashboard' } catch (error) { console.error('Auto-login failed:', error) } }, 2000) } else { toast.error(result.message || 'Application failed. Please try again.') } } catch (error) { console.error('Application error:', error) toast.error('Something went wrong. Please try again.') } finally { setIsSubmitting(false) } } const getTierIcon = (tier: string) => { switch (tier) { case 'Diamond': return Crown case 'Gold': return Award case 'Silver': return Star default: return Star } } const getTierColor = (tier: string) => { switch (tier) { case 'Diamond': return '#3B82F6' case 'Gold': return '#F59E0B' case 'Silver': return '#8B5CF6' default: return '#8B5CF6' } } const getTierMaxCustomers = (tier: string) => { switch (tier) { case 'Diamond': return 3000 case 'Gold': return 1500 case 'Silver': return 500 default: return 500 } } if (isSuccess) { return ( Application Submitted! Welcome to Padmaaja Rasooi! Check your email for login details. You'll be automatically logged in and redirected to your dashboard. Close ) } return ( Partnership Application {/* Selected Tier Display */} {(() => { const TierIcon = getTierIcon(formData.partnershipTier) return ( ) })()} {formData.partnershipTier} Partner Max {getTierMaxCustomers(formData.partnershipTier).toLocaleString()} customers {/* Personal Information */} Personal Information First Name * handleInputChange('firstName', e.target.value)} required /> Last Name * handleInputChange('lastName', e.target.value)} required /> Email Address * handleInputChange('email', e.target.value)} required /> Phone Number * handleInputChange('phone', e.target.value)} required /> {/* Business Information */} Business Information Business Name (Optional) handleInputChange('businessName', e.target.value)} /> Business Type * handleInputChange('businessType', value)}> Individual Retail Store Restaurant/Hotel Distributor Online Business Other Experience in Food/Retail Business * handleInputChange('experience', value)}> Beginner (0-1 years) Intermediate (2-5 years) Experienced (5+ years) {/* Partnership Details */} Partnership Details Partnership Tier * handleInputChange('partnershipTier', value)}> Silver (500 customers) Gold (1,500 customers) Diamond (3,000 customers) Expected Customers in First Year handleInputChange('expectedCustomers', e.target.value)} max={getTierMaxCustomers(formData.partnershipTier)} /> {/* Address Information */} Address Information Street Address * handleInputChange('address', e.target.value)} required /> City * handleInputChange('city', e.target.value)} required /> State * handleInputChange('state', e.target.value)} required /> ZIP Code * handleInputChange('zipCode', e.target.value)} required /> {/* Additional Information */} Additional Information Why do you want to become a partner? * handleInputChange('motivation', e.target.value)} required rows={3} /> How do you plan to market our products? * handleInputChange('marketingPlan', e.target.value)} required rows={3} /> {/* Submit Button */} Cancel {isSubmitting ? ( <> Submitting... > ) : ( 'Submit Application' )} ) }
Welcome to Padmaaja Rasooi! Check your email for login details.
You'll be automatically logged in and redirected to your dashboard.
Max {getTierMaxCustomers(formData.partnershipTier).toLocaleString()} customers