'use client'; import { useState } from 'react'; import Image from 'next/image'; import { useRouter } from 'next/navigation'; import styles from "./page.module.css"; import { indianLocations } from "@/data/indianLocations"; import { businessTypes } from "@/data/businessTypes"; type NotificationType = 'success' | 'error' | 'info'; interface Notification { id: number; message: string; type: NotificationType; } export default function Onboarding() { const router = useRouter(); const [view, setView] = useState<'selection' | 'create' | 'join'>('selection'); // Create Company State const [companyName, setCompanyName] = useState(""); const [businessType, setBusinessType] = useState(""); const [industry, setIndustry] = useState(""); const [size, setSize] = useState(""); const [city, setCity] = useState(""); const [state, setState] = useState(""); // Compliance State const [complianceType, setComplianceType] = useState(""); const [complianceId, setComplianceId] = useState(""); // Derived Data // Filter cities based on selected state if available, else show all or empty // const availableCities = indianLocations.find(s => s.name === state)?.cities || []; // Join Company State const [inviteCode, setInviteCode] = useState(""); // Notifications const [notifications, setNotifications] = useState([]); const showNotification = (message: string, type: NotificationType = 'info') => { const id = Date.now(); setNotifications(prev => [...prev, { id, message, type }]); setTimeout(() => { setNotifications(prev => prev.filter(n => n.id !== id)); }, 4000); }; const handleCreateSubmit = (e: React.FormEvent) => { e.preventDefault(); // Simulate API call if (!companyName || !businessType || !industry || !size || !state || !city) { showNotification("Please fill in all required fields.", 'error'); return; } showNotification("Creating your workspace...", 'success'); // Mock success redirect setTimeout(() => { // Ideally redirect to dashboard, for now just show success console.log("Company Created:", { companyName, businessType, industry, size, city, state, compliance: complianceType ? { type: complianceType, id: complianceId } : null, country: "India", currency: "INR" }); // Redirect to dashboard router.push('/dashboard'); }, 1500); }; const handleJoinSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!inviteCode) { showNotification("Please enter an invite code.", 'error'); return; } showNotification("Verifying invitation...", 'info'); setTimeout(() => { showNotification("Successfully joined company!", 'success'); }, 1500); }; return (
{/* Notification Toast (Reused logic) */}
{notifications.map(n => (
{n.message}
))}
{/* Header with Logo */}
Pennyzo

{view === 'selection' && "Welcome, Founder"} {view === 'create' && "Establish Entity"} {view === 'join' && "Join Structure"}

{view === 'selection' && "Choose your path to begin using the Business 360 Platform."} {view === 'create' && "Register a new business entity to manage operations, finance, and teams."} {view === 'join' && "Enter your invitation code provided by your organization administrator."}

{/* VIEW 1: SELECTION */} {view === 'selection' && (
{/* Option: Create Company */}
setView('create')}>
+

Create Company

Register a new business organization. You will be assigned the Founder role with full administrative controls.

{/* Option: Join Company */}
setView('join')}>
→

Join Existing

Join a team using an invitation code or request access. You will be assigned a role based on the invite.

)} {/* VIEW 2: CREATE COMPANY FORM */} {view === 'create' && (
{/* Company Name */}
setCompanyName(e.target.value)} required />
{/* Business Type */}
{/* Industry */}
{/* Company Size */}
{/* State Selection */}
{/* City Selection (Dependent) */}
{/* Country (Locked) */}
{/* Compliance Section (Optional) */}
setComplianceId(e.target.value)} disabled={!complianceType} style={{ opacity: !complianceType ? 0.5 : 1, cursor: !complianceType ? 'not-allowed' : 'text' }} />
)} {/* VIEW 3: JOIN COMPANY */} {view === 'join' && (
setInviteCode(e.target.value)} style={{ letterSpacing: '2px', textAlign: 'center', fontSize: '1.2rem' }} required />
)}
); }