import React, { useState, useEffect, useMemo, useCallback } from 'react'; import { useSource, useAppState, useAction } from './sdk'; import { Badge, Metric, Glass, Icon } from './components'; import { BarChart, Bar, LineChart, Line, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts'; import { TrendingUp, Users, CheckCircle, Clock, AlertCircle, FileText, Mail, Calendar, UserCheck, Search, Filter, Plus, ChevronRight, Upload, Download, Bell, Shield, Award, Target, Activity } from 'lucide-react'; // Mock data for onboarding workflows const MOCK_HIRES = [ { id: '1', name: 'Marcus Chen', role: 'Software Engineer', department: 'Engineering', startDate: '2026-01-15', buddy: 'Sarah Kim', status: 'in-progress', progress: 65, phase: 'Week 1', avatar: 'MC', email: 'marcus.chen@company.com', manager: 'David Park' }, { id: '2', name: 'Emily Rodriguez', role: 'Product Manager', department: 'Product', startDate: '2026-01-20', buddy: 'James Wilson', status: 'in-progress', progress: 45, phase: 'Day 1', avatar: 'ER', email: 'emily.r@company.com', manager: 'Lisa Chang' }, { id: '3', name: 'Alex Thompson', role: 'UX Designer', department: 'Design', startDate: '2026-01-08', buddy: 'Maya Patel', status: 'in-progress', progress: 85, phase: 'Month 1', avatar: 'AT', email: 'alex.t@company.com', manager: 'Chris Lee' }, { id: '4', name: 'Jordan Williams', role: 'Sales Rep', department: 'Sales', startDate: '2026-02-01', buddy: 'TBD', status: 'pending', progress: 15, phase: 'Pre-boarding', avatar: 'JW', email: 'jordan.w@company.com', manager: 'Mike Johnson' }, { id: '5', name: 'Priya Sharma', role: 'Data Analyst', department: 'Analytics', startDate: '2025-12-01', buddy: 'Tom Brown', status: 'complete', progress: 100, phase: '90-day', avatar: 'PS', email: 'priya.s@company.com', manager: 'Anna Davis' }, ]; const MOCK_TASKS = [ { id: 't1', hireId: '1', title: 'Complete I-9 Form', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-14', assignee: 'Marcus Chen', category: 'compliance', priority: 'high' }, { id: 't2', hireId: '1', title: 'Sign Employment Contract', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-14', assignee: 'Marcus Chen', category: 'documents', priority: 'high' }, { id: 't3', hireId: '1', title: 'Submit Tax Documents (W-4)', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-14', assignee: 'Marcus Chen', category: 'documents', priority: 'high' }, { id: 't4', hireId: '1', title: 'Review Employee Handbook', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-14', assignee: 'Marcus Chen', category: 'reading', priority: 'medium' }, { id: 't5', hireId: '1', title: 'Setup Email & Slack', phase: 'Day 1', status: 'done', dueDate: '2026-01-15', assignee: 'IT Admin', category: 'it', priority: 'high' }, { id: 't6', hireId: '1', title: 'Laptop & Equipment Setup', phase: 'Day 1', status: 'done', dueDate: '2026-01-15', assignee: 'IT Admin', category: 'it', priority: 'high' }, { id: 't7', hireId: '1', title: 'Team Introduction Meeting', phase: 'Day 1', status: 'done', dueDate: '2026-01-15', assignee: 'David Park', category: 'meetings', priority: 'medium' }, { id: 't8', hireId: '1', title: 'Buddy Lunch', phase: 'Day 1', status: 'done', dueDate: '2026-01-15', assignee: 'Sarah Kim', category: 'social', priority: 'low' }, { id: 't9', hireId: '1', title: 'Complete Security Training', phase: 'Week 1', status: 'in-progress', dueDate: '2026-01-22', assignee: 'Marcus Chen', category: 'training', priority: 'high' }, { id: 't10', hireId: '1', title: 'Setup Development Environment', phase: 'Week 1', status: 'in-progress', dueDate: '2026-01-22', assignee: 'Marcus Chen', category: 'it', priority: 'high' }, { id: 't11', hireId: '1', title: '1:1 with Manager', phase: 'Week 1', status: 'pending', dueDate: '2026-01-22', assignee: 'David Park', category: 'meetings', priority: 'medium' }, { id: 't12', hireId: '1', title: 'Review Team OKRs', phase: 'Week 1', status: 'pending', dueDate: '2026-01-22', assignee: 'Marcus Chen', category: 'reading', priority: 'medium' }, { id: 't13', hireId: '2', title: 'Complete I-9 Form', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-19', assignee: 'Emily Rodriguez', category: 'compliance', priority: 'high' }, { id: 't14', hireId: '2', title: 'Sign Employment Contract', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-19', assignee: 'Emily Rodriguez', category: 'documents', priority: 'high' }, { id: 't15', hireId: '2', title: 'Submit Tax Documents (W-4)', phase: 'Pre-boarding', status: 'pending', dueDate: '2026-01-19', assignee: 'Emily Rodriguez', category: 'documents', priority: 'high' }, { id: 't16', hireId: '2', title: 'Review Employee Handbook', phase: 'Pre-boarding', status: 'in-progress', dueDate: '2026-01-19', assignee: 'Emily Rodriguez', category: 'reading', priority: 'medium' }, { id: 't17', hireId: '2', title: 'Setup Email & Slack', phase: 'Day 1', status: 'pending', dueDate: '2026-01-20', assignee: 'IT Admin', category: 'it', priority: 'high' }, { id: 't18', hireId: '2', title: 'Product Roadmap Review', phase: 'Day 1', status: 'pending', dueDate: '2026-01-20', assignee: 'Lisa Chang', category: 'meetings', priority: 'high' }, { id: 't19', hireId: '3', title: 'Complete I-9 Form', phase: 'Pre-boarding', status: 'done', dueDate: '2026-01-07', assignee: 'Alex Thompson', category: 'compliance', priority: 'high' }, { id: 't20', hireId: '3', title: 'Design System Training', phase: 'Month 1', status: 'in-progress', dueDate: '2026-02-08', assignee: 'Alex Thompson', category: 'training', priority: 'medium' }, ]; const MOCK_DOCUMENTS = [ { id: 'd1', hireId: '1', name: 'I-9 Form', type: 'pdf', status: 'signed', uploadedAt: '2026-01-14', expiresAt: null }, { id: 'd2', hireId: '1', name: 'Employment Contract', type: 'pdf', status: 'signed', uploadedAt: '2026-01-14', expiresAt: null }, { id: 'd3', hireId: '1', name: 'W-4 Tax Form', type: 'pdf', status: 'signed', uploadedAt: '2026-01-14', expiresAt: null }, { id: 'd4', hireId: '1', name: 'Direct Deposit Form', type: 'pdf', status: 'pending', uploadedAt: null, expiresAt: null }, { id: 'd5', hireId: '2', name: 'I-9 Form', type: 'pdf', status: 'signed', uploadedAt: '2026-01-19', expiresAt: null }, { id: 'd6', hireId: '2', name: 'Employment Contract', type: 'pdf', status: 'signed', uploadedAt: '2026-01-19', expiresAt: null }, { id: 'd7', hireId: '2', name: 'W-4 Tax Form', type: 'pdf', status: 'pending', uploadedAt: null, expiresAt: null }, { id: 'd8', hireId: '3', name: 'I-9 Form', type: 'pdf', status: 'signed', uploadedAt: '2026-01-07', expiresAt: '2029-01-07' }, { id: 'd9', hireId: '3', name: 'NDA Agreement', type: 'pdf', status: 'signed', uploadedAt: '2026-01-07', expiresAt: null }, ]; const PHASES = ['Pre-boarding', 'Day 1', 'Week 1', 'Month 1', 'Month 2', 'Month 3', '90-day']; const CATEGORIES = [ { id: 'compliance', label: 'Compliance', color: '#ef4444', icon: 'shield' }, { id: 'documents', label: 'Documents', color: '#f59e0b', icon: 'file-text' }, { id: 'it', label: 'IT Setup', color: '#8b5cf6', icon: 'activity' }, { id: 'training', label: 'Training', color: '#06b6d4', icon: 'award' }, { id: 'meetings', label: 'Meetings', color: '#10b981', icon: 'users' }, { id: 'social', label: 'Social', color: '#ec4899', icon: 'user-check' }, { id: 'reading', label: 'Reading', color: '#64748b', icon: 'file-text' }, ]; const STATUS_COLORS = { pending: 'bg-slate-500', 'in-progress': 'bg-blue-500', done: 'bg-emerald-500', complete: 'bg-emerald-500', overdue: 'bg-red-500', }; export default function App() { const [activeTab, setActiveTab] = useState('dashboard'); const [selectedHire, setSelectedHire] = useState(null); const [searchQuery, setSearchQuery] = useState(''); const [phaseFilter, setPhaseFilter] = useState('all'); const [statusFilter, setStatusFilter] = useState('all'); const [showUploadModal, setShowUploadModal] = useState(false); const [showTaskModal, setShowTaskModal] = useState(false); const [selectedTask, setSelectedTask] = useState(null); const [userRole, setUserRole] = useState<'hr-admin' | 'manager' | 'new-hire'>('hr-admin'); const { data, loading, error, refetch } = useSource('/api/framework/connections/app/employee-onboarding/data', 30000); const dispatch = useAction(); const [notifications, setNotifications] = useAppState('notifications', []); // Use mock data since no providers connected yet const hires = useMemo(() => MOCK_HIRES, []); const tasks = useMemo(() => MOCK_TASKS, []); const documents = useMemo(() => MOCK_DOCUMENTS, []); // Filter hires based on search and filters const filteredHires = useMemo(() => { return hires.filter(hire => { const matchesSearch = hire.name.toLowerCase().includes(searchQuery.toLowerCase()) || hire.role.toLowerCase().includes(searchQuery.toLowerCase()) || hire.department.toLowerCase().includes(searchQuery.toLowerCase()); const matchesPhase = phaseFilter === 'all' || hire.phase === phaseFilter; const matchesStatus = statusFilter === 'all' || hire.status === statusFilter; return matchesSearch && matchesPhase && matchesStatus; }); }, [hires, searchQuery, phaseFilter, statusFilter]); // Calculate statistics const stats = useMemo(() => { const totalHires = hires.length; const activeHires = hires.filter(h => h.status === 'in-progress').length; const completedHires = hires.filter(h => h.status === 'complete').length; const avgProgress = Math.round(hires.reduce((sum, h) => sum + h.progress, 0) / totalHires); const overdueTasks = tasks.filter(t => t.status !== 'done' && new Date(t.dueDate) < new Date()).length; const pendingDocs = documents.filter(d => d.status === 'pending').length; return { totalHires, activeHires, completedHires, avgProgress, overdueTasks, pendingDocs }; }, [hires, tasks, documents]); // Progress chart data const progressData = useMemo(() => { return PHASES.slice(0, 5).map(phase => ({ name: phase, completed: hires.filter(h => h.phase === phase && h.status === 'complete').length, inProgress: hires.filter(h => h.phase === phase && h.status === 'in-progress').length, })); }, [hires]); // Category distribution const categoryData = useMemo(() => { return CATEGORIES.map(cat => ({ name: cat.label, value: tasks.filter(t => t.category === cat.id).length, color: cat.color, })); }, [tasks]); const handleTaskComplete = useCallback((taskId: string) => { dispatch('toast', { message: 'Task marked complete!', type: 'success' }); refetch(); }, [dispatch, refetch]); const handleSendReminder = useCallback((hireId: string, hireName: string) => { dispatch('toast', { message: `Reminder sent to ${hireName}`, type: 'success' }); dispatch('enqueue', { action_type: 'send_email', data: { to: hires.find(h => h.id === hireId)?.email, subject: 'Onboarding Reminder', body: 'You have pending onboarding tasks.' } }); }, [dispatch, hires]); const handleFileUpload = useCallback((files: FileList) => { dispatch('toast', { message: `${files.length} file(s) uploaded`, type: 'success' }); setShowUploadModal(false); }, [dispatch]); // Render loading state if (loading) { return (
); } return (
{/* Header */}

Employee Onboarding

Workflow Tracker

{/* Role Selector */}
{/* Tabs */}
{[ { id: 'dashboard', label: 'Dashboard', icon: 'activity' }, { id: 'hires', label: 'New Hires', icon: 'users' }, { id: 'tasks', label: 'Tasks', icon: 'check-circle' }, { id: 'documents', label: 'Documents', icon: 'file-text' }, { id: 'analytics', label: 'Analytics', icon: 'trending-up' }, ].map(tab => ( ))}
{/* Error Banner */} {error && (
Connection issue: {error.message}. Showing cached data.
)}
{/* Dashboard Tab */} {activeTab === 'dashboard' && ( <> {/* KPI Cards */}

Active Hires

{stats.activeHires}

Avg Progress

{stats.avgProgress}%

Overdue Tasks

{stats.overdueTasks}

{stats.overdueTasks > 0 && ( )}

Pending Docs

{stats.pendingDocs}

{/* Charts Row */}

Progress by Phase

Task Distribution

{categoryData.map((entry, index) => ( ))}
{/* Active Hires Table */}

Active Onboarding

{hires.filter(h => h.status !== 'complete').map(hire => ( { setSelectedHire(hire.id); setActiveTab('hires'); }} > ))}
New Hire Role Phase Progress Buddy Actions
{hire.avatar}

{hire.name}

{hire.email}

{hire.role}

{hire.department}

50 ? 'bg-blue-500' : 'bg-amber-500'}`} style={{ width: `${hire.progress}%` }} />
{hire.progress}%
{hire.buddy !== 'TBD' ? (
{hire.buddy}
) : ( )}
)} {/* New Hires Tab */} {activeTab === 'hires' && ( <> {/* Filters */}
setSearchQuery(e.target.value)} className="w-full bg-white/[0.05] border border-white/[0.08] rounded-lg pl-10 pr-4 py-2 text-sm focus:outline-none focus:border-violet-500/50" />
{/* Hire Cards */}
{filteredHires.map(hire => ( setSelectedHire(hire.id)} >
{hire.avatar}

{hire.name}

{hire.role}

Department {hire.department}
Start Date {hire.startDate}
Manager {hire.manager}
Buddy {hire.buddy !== 'TBD' ? hire.buddy : 'Not assigned'}
Progress {hire.progress}%
50 ? 'bg-blue-500' : 'bg-amber-500'}`} style={{ width: `${hire.progress}%` }} />
))}
)} {/* Tasks Tab */} {activeTab === 'tasks' && (

All Tasks

{tasks.filter(t => t.status === 'done').length}/{tasks.length} completed
{PHASES.slice(0, 5).map(phase => { const phaseTasks = tasks.filter(t => t.phase === phase); if (phaseTasks.length === 0) return null; return (

{phase}

{phaseTasks.map(task => (
setSelectedTask(task)} >

{task.title}

{task.assignee} Due: {task.dueDate}
c.id === task.category)?.label || task.category} variant="neutral" /> {new Date(task.dueDate) < new Date() && task.status !== 'done' && ( )}
))}
); })}
)} {/* Documents Tab */} {activeTab === 'documents' && (

Document Collection

{documents.map(doc => { const hire = hires.find(h => h.id === doc.hireId); return ( ); })}
Document New Hire Status Uploaded Expires Actions
{doc.name}
{hire?.name || 'Unknown'} {doc.uploadedAt || '-'} {doc.expiresAt ? ( {doc.expiresAt} ) : '-'}
{doc.status === 'pending' && ( )}
)} {/* Analytics Tab */} {activeTab === 'analytics' && (

Completion Trends

Compliance Status

{[ { name: 'I-9 Forms', completed: 5, total: 5, color: 'emerald' }, { name: 'Tax Documents', completed: 3, total: 5, color: 'amber' }, { name: 'Employment Contracts', completed: 5, total: 5, color: 'emerald' }, { name: 'NDAs', completed: 4, total: 5, color: 'blue' }, { name: 'Handbook Acknowledgments', completed: 4, total: 5, color: 'blue' }, ].map(item => (
{item.name} {item.completed}/{item.total}
))}

90-Day Milestone Tracker

{[ { milestone: '30-Day Check-in', hires: 3, color: 'blue' }, { milestone: '60-Day Check-in', hires: 2, color: 'violet' }, { milestone: '90-Day Review', hires: 1, color: 'emerald' }, ].map(item => (

{item.milestone}

{item.hires} hires

))}
)}
{/* Hire Detail Modal */} {selectedHire && (
setSelectedHire(null)} > e.stopPropagation()} > {(() => { const hire = hires.find(h => h.id === selectedHire); if (!hire) return null; const hireTasks = tasks.filter(t => t.hireId === hire.id); const hireDocs = documents.filter(d => d.hireId === hire.id); return ( <>
{hire.avatar}

{hire.name}

{hire.role} • {hire.department}

{hire.email}

Start Date

{hire.startDate}

Manager

{hire.manager}

Buddy

{hire.buddy !== 'TBD' ? hire.buddy : 'Not assigned'}

Current Phase

Overall Progress

{hire.progress}%

Tasks ({hireTasks.filter(t => t.status === 'done').length}/{hireTasks.length})

{hireTasks.map(task => (
{task.status === 'done' && }
{task.title}
))}

Documents ({hireDocs.filter(d => d.status === 'signed').length}/{hireDocs.length})

{hireDocs.map(doc => (
{doc.name}
))}
); })()}
)} {/* Task Detail Modal */} {selectedTask && (
setSelectedTask(null)} > e.stopPropagation()} >

{selectedTask.title}

Phase

Category

c.id === selectedTask.category)?.label || selectedTask.category} variant="neutral" />

Assignee

{selectedTask.assignee}

Due Date

{selectedTask.dueDate}

Status

{['pending', 'in-progress', 'done'].map(status => ( ))}
)} {/* Upload Modal */} {showUploadModal && (
setShowUploadModal(false)} > e.stopPropagation()} >

Upload Document

Drag and drop files here, or click to browse

PDF, PNG, JPG up to 10MB

e.target.files && handleFileUpload(e.target.files)} className="hidden" id="file-upload" />
)} {/* Add Task Modal */} {showTaskModal && (
setShowTaskModal(false)} > e.stopPropagation()} >

Add New Task

)}
); }