File size: 3,696 Bytes
ea9ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59f9574
ea9ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59f9574
ea9ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState } from 'react';

// --- Imports ---
import LoginPage from './pages/LoginPage';
import AdminLogin from './pages/AdminLogin';
import AppliLogin from './pages/AppliLogin';
import ClientDash from './pages/clientdash';
import Admindash from './pages/Admindashboard';

// --- Applicant Pages ---
import ApplicantJobPage from './pages/ApplicantJobPage';
import ApplicantProfile from './pages/ApplicantProfile';    // Make sure this file exists
import ApplicantATS from './pages/ApplicantATS';            // Make sure this file exists
import ApplicantInterviews from './pages/ApplicantInterviews'; // Make sure this file exists
import ApplicantMessages from './pages/ApplicantMessages';    // Make sure this file exists
import ResetPassword from './pages/ResetPassword';

import { supabase } from './supabaseClient'; // Import at top

export default function App() {
  // Initialize state from localStorage if available, else login
  const [currentPage, setCurrentPage] = useState('login');
  const [loading, setLoading] = useState(true); // START LOADING

  // --- PERSISTENCE LOGIC ---
  React.useEffect(() => {
    const checkSession = async () => {
      // 1. Check if user is logged in
      const { data: { session } } = await supabase.auth.getSession();

      if (session) {
        // 2. If logged in, recover last page or default to 'applicant-jobs'
        const lastPage = localStorage.getItem('last_iris_page');
        if (lastPage && lastPage !== 'login') {
          setCurrentPage(lastPage);
        } else {
          setCurrentPage('applicant-jobs');
        }
      }
      setLoading(false); // STOP LOADING
    };
    checkSession();
  }, []);

  const handleNavigate = (page) => {
    setCurrentPage(page);
    // Persist navigation
    if (page !== 'login' && page !== 'applicant' && page !== 'admin') {
      localStorage.setItem('last_iris_page', page);
    }
  };

  const renderPage = () => {
    if (loading) {
      // Simple Full-Screen Loader
      return (
        <div style={{
          display: 'flex', justifyContent: 'center', alignItems: 'center',
          height: '100vh', backgroundColor: '#0f172a', color: '#fff'
        }}>
          <h2>Restoring Session...</h2>
        </div>
      );
    }

    switch (currentPage) {
      // --- AUTH ---
      case 'login': return <LoginPage onNavigate={handleNavigate} />;
      case 'admin': return <AdminLogin onNavigate={handleNavigate} />;
      case 'applicant': return <AppliLogin onNavigate={handleNavigate} />;
      case 'reset-password': return <ResetPassword onNavigate={handleNavigate} />;
      // --- APPLICANT ROUTES ---
      case 'applicant-jobs':
        return <ApplicantJobPage onNavigate={handleNavigate} />;

      case 'applicant-profile':
        return <ApplicantProfile onNavigate={handleNavigate} />;

      case 'applicant-interviews':
        return <ApplicantInterviews onNavigate={handleNavigate} />;

      case 'applicant-ats':
        return <ApplicantATS onNavigate={handleNavigate} />;

      case 'applicant-messages':
        return <ApplicantMessages onNavigate={handleNavigate} />;

      // --- ADMIN / RECRUITER ---
      case 'dashboard': return <ClientDash onNavigate={handleNavigate} />;
      case 'admin-dashboard': return <Admindash onNavigate={handleNavigate} />;

      // --- DEFAULT ---
      default: return <LoginPage onNavigate={handleNavigate} />;
    }
  };

  return (
    <div>
      <style>{`
        *, *::before, *::after { box-sizing: border-box; }
        html, body, #root { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; background-color: #0f172a; }
      `}</style>

      {renderPage()}
    </div>
  );
}