fis
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,7 +31,6 @@ dist-ssr
|
||||
/figma/
|
||||
/figma-code/
|
||||
/server-minimal.js
|
||||
/employeeQuestions.ts
|
||||
/README.md
|
||||
/metadata.json
|
||||
**/Demo.tsx
|
||||
|
||||
@@ -13,7 +13,6 @@ interface AuthContextType {
|
||||
signUpWithEmail: (email: string, password: string, displayName?: string) => Promise<void>;
|
||||
sendOTP: (email: string, inviteCode?: string) => Promise<any>;
|
||||
verifyOTP: (email: string, otp: string, inviteCode?: string) => Promise<void>;
|
||||
signInWithOTP: (token: string, userData: any) => Promise<void>;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
@@ -238,18 +237,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
return data;
|
||||
};
|
||||
|
||||
const signInWithOTP = async (token: string, userData: any) => {
|
||||
const mockUser = {
|
||||
uid: userData.uid,
|
||||
email: userData.email,
|
||||
displayName: userData.displayName,
|
||||
emailVerified: true
|
||||
} as unknown as User;
|
||||
|
||||
setUser(mockUser);
|
||||
localStorage.setItem('auditly_demo_session', JSON.stringify(mockUser));
|
||||
localStorage.setItem('auditly_auth_token', token);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{
|
||||
@@ -261,7 +248,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
signUpWithEmail,
|
||||
sendOTP,
|
||||
verifyOTP,
|
||||
signInWithOTP
|
||||
}}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
|
||||
324
employeeQuestions.ts
Normal file
324
employeeQuestions.ts
Normal file
@@ -0,0 +1,324 @@
|
||||
// Static list of employee submission questions (distinct from company onboarding)
|
||||
// Each question can map to analysis dimensions for report generation.
|
||||
export interface EmployeeQuestion {
|
||||
id: string;
|
||||
prompt: string;
|
||||
category: 'role' | 'performance' | 'growth' | 'culture' | 'risk' | 'values' | 'personal' | 'collaboration' | 'feedback';
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
weight?: number; // relative weighting for scoring
|
||||
type?: 'text' | 'textarea' | 'scale' | 'select' | 'yesno';
|
||||
options?: string[];
|
||||
scaleMin?: number;
|
||||
scaleMax?: number;
|
||||
scaleLabels?: { min: string; max: string };
|
||||
followupTo?: string; // ID of question this follows up on
|
||||
}
|
||||
|
||||
export const EMPLOYEE_QUESTIONS: EmployeeQuestion[] = [
|
||||
{
|
||||
id: 'email',
|
||||
prompt: 'Email',
|
||||
category: 'personal',
|
||||
required: true,
|
||||
type: 'text',
|
||||
placeholder: 'your.email@company.com',
|
||||
weight: 0
|
||||
},
|
||||
{
|
||||
id: 'full_name',
|
||||
prompt: 'First and Last name',
|
||||
category: 'personal',
|
||||
required: true,
|
||||
type: 'text',
|
||||
placeholder: 'John Doe',
|
||||
weight: 0
|
||||
},
|
||||
{
|
||||
id: 'company_department',
|
||||
prompt: 'What is the name of your Company and department?',
|
||||
category: 'role',
|
||||
required: false,
|
||||
type: 'text',
|
||||
placeholder: 'Acme Corp - Marketing Department',
|
||||
weight: 0.5
|
||||
},
|
||||
{
|
||||
id: 'title_department',
|
||||
prompt: 'What is your current title and department',
|
||||
category: 'role',
|
||||
required: true,
|
||||
type: 'text',
|
||||
placeholder: 'Marketing Manager - Marketing Department',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'role_clarity',
|
||||
prompt: 'How clearly do you understand your role and responsibilities?',
|
||||
category: 'role',
|
||||
required: true,
|
||||
type: 'scale',
|
||||
scaleMin: 1,
|
||||
scaleMax: 10,
|
||||
scaleLabels: { min: 'Not so much', max: 'Very clearly' },
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'core_responsibilities',
|
||||
prompt: 'Describe your core daily responsibilities',
|
||||
category: 'role',
|
||||
required: true,
|
||||
type: 'textarea',
|
||||
placeholder: 'List your main daily tasks and responsibilities...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'outside_responsibilities',
|
||||
prompt: 'Do you handle any responsibilities outside of your official role? If yes, explain',
|
||||
category: 'role',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe any additional responsibilities you handle...',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'role_alignment',
|
||||
prompt: 'Do you feel your role aligns with your strengths? Why or why not?',
|
||||
category: 'role',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Explain how your role matches or doesn\'t match your strengths...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'weekly_output',
|
||||
prompt: 'How would you rate your weekly output (volume and quality)?',
|
||||
category: 'performance',
|
||||
required: true,
|
||||
type: 'scale',
|
||||
scaleMin: 1,
|
||||
scaleMax: 10,
|
||||
scaleLabels: { min: 'Very little', max: 'Very highly' },
|
||||
weight: 1.3
|
||||
},
|
||||
{
|
||||
id: 'recurring_deliverables',
|
||||
prompt: 'What are your top 2-3 recurring deliverables?',
|
||||
category: 'performance',
|
||||
required: true,
|
||||
type: 'textarea',
|
||||
placeholder: 'List your main recurring outputs or deliverables...',
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'measurable_results',
|
||||
prompt: 'List measurable results you have produced in the last 60 days.',
|
||||
category: 'performance',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe specific, measurable achievements from the past 60 days...',
|
||||
weight: 1.3
|
||||
},
|
||||
{
|
||||
id: 'has_kpis',
|
||||
prompt: 'Do you have weekly KPIs or goals?',
|
||||
category: 'performance',
|
||||
required: false,
|
||||
type: 'yesno',
|
||||
weight: 0.8
|
||||
},
|
||||
{
|
||||
id: 'kpis_details',
|
||||
prompt: 'If yes; What are they?',
|
||||
category: 'performance',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'List your KPIs or weekly goals...',
|
||||
followupTo: 'has_kpis',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'reports_to',
|
||||
prompt: 'Who do you report to?',
|
||||
category: 'collaboration',
|
||||
required: false,
|
||||
type: 'text',
|
||||
placeholder: 'Manager name and title',
|
||||
weight: 0.7
|
||||
},
|
||||
{
|
||||
id: 'meeting_frequency',
|
||||
prompt: 'How often do you meet/check-in?',
|
||||
category: 'collaboration',
|
||||
required: false,
|
||||
type: 'text',
|
||||
placeholder: 'e.g., Weekly, Daily, Bi-weekly',
|
||||
weight: 0.7
|
||||
},
|
||||
{
|
||||
id: 'close_collaboration',
|
||||
prompt: 'Who do you work most closely with?',
|
||||
category: 'collaboration',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'List team members or departments you collaborate with most...',
|
||||
weight: 0.9
|
||||
},
|
||||
{
|
||||
id: 'collaboration_effectiveness',
|
||||
prompt: 'How effective is collaboration in your department',
|
||||
category: 'collaboration',
|
||||
required: false,
|
||||
type: 'scale',
|
||||
scaleMin: 1,
|
||||
scaleMax: 10,
|
||||
scaleLabels: { min: 'Not effective', max: 'Very effectively' },
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'team_dynamics_issues',
|
||||
prompt: 'Are there any team dynamics that hinder your productivity?',
|
||||
category: 'risk',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe any team issues affecting your productivity...',
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'unclear_responsibilities',
|
||||
prompt: 'Are project responsibilities ever unclear?',
|
||||
category: 'risk',
|
||||
required: false,
|
||||
type: 'yesno',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'unclear_example',
|
||||
prompt: 'If yes; Describe a recent example',
|
||||
category: 'risk',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Provide a specific example of unclear responsibilities...',
|
||||
followupTo: 'unclear_responsibilities',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'recognition_feeling',
|
||||
prompt: 'Do you feel your contributions are recognized by leadership/peers?',
|
||||
category: 'culture',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe how you feel about recognition of your work...',
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'recurring_issues',
|
||||
prompt: 'Are there recurring issues in task management or communication?',
|
||||
category: 'risk',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe any ongoing operational issues...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'improvement_suggestions',
|
||||
prompt: 'How can we better manage timelines, workload, or approvals?',
|
||||
category: 'feedback',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Suggest improvements to processes...',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'tool_recommendations',
|
||||
prompt: 'What system or tool would you recommend we add or improve?',
|
||||
category: 'feedback',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Suggest tools or systems that could help...',
|
||||
weight: 0.9
|
||||
},
|
||||
{
|
||||
id: 'job_enjoyment',
|
||||
prompt: 'What part of your job do you enjoy the most?',
|
||||
category: 'values',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe what you find most fulfilling...',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'job_frustrations',
|
||||
prompt: 'What part of your job frustrates you the most?',
|
||||
category: 'risk',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe your biggest frustrations...',
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'growth_goals',
|
||||
prompt: 'Where would you like to grow within the company over the next 6 months?',
|
||||
category: 'growth',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe your growth aspirations...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'role_shift_interest',
|
||||
prompt: 'Are you interested in shifting roles or departments?',
|
||||
category: 'growth',
|
||||
required: false,
|
||||
type: 'yesno',
|
||||
weight: 1
|
||||
},
|
||||
{
|
||||
id: 'role_shift_direction',
|
||||
prompt: 'If yes; What direction interests you the most?',
|
||||
category: 'growth',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe the direction you\'re interested in...',
|
||||
followupTo: 'role_shift_interest',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'skills_training',
|
||||
prompt: 'What skills or training would help you be more effective?',
|
||||
category: 'growth',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'List skills or training you need...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'magic_wand',
|
||||
prompt: 'If you had a magic wand, what would you change about how we operate?',
|
||||
category: 'feedback',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Describe ideal changes to company operations...',
|
||||
weight: 1.2
|
||||
},
|
||||
{
|
||||
id: 'staffing_opinion',
|
||||
prompt: 'Do you believe any roles or departments are overstaffed or underperforming?',
|
||||
category: 'feedback',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Share your thoughts on team structure and performance...',
|
||||
weight: 1.1
|
||||
},
|
||||
{
|
||||
id: 'additional_feedback',
|
||||
prompt: 'Any other feedback or suggestions?',
|
||||
category: 'feedback',
|
||||
required: false,
|
||||
type: 'textarea',
|
||||
placeholder: 'Share any additional thoughts...',
|
||||
weight: 0.8
|
||||
},
|
||||
];
|
||||
|
||||
export type EmployeeSubmissionAnswers = Record<string, string>;
|
||||
File diff suppressed because it is too large
Load Diff
673
pages/EmployeeQuestionnaireMerged.tsx
Normal file
673
pages/EmployeeQuestionnaireMerged.tsx
Normal file
@@ -0,0 +1,673 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate, useLocation, useParams } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useOrg } from '../contexts/OrgContext';
|
||||
import { EMPLOYEE_QUESTIONS, EmployeeSubmissionAnswers, EmployeeQuestion } from '../employeeQuestions';
|
||||
import { API_URL } from '../constants';
|
||||
|
||||
// Icon SVG Component
|
||||
const AuditlyIcon: React.FC = () => (
|
||||
<svg width="24" height="30" viewBox="0 0 24 30" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path opacity="0.5" fillRule="evenodd" clipRule="evenodd" d="M2.57408 17.8138C3.11835 18.3649 3.11834 19.2585 2.57406 19.8097L2.54619 19.8379C2.00191 20.389 1.11946 20.389 0.57519 19.8379C0.030919 19.2867 0.0309274 18.3931 0.575208 17.842L0.603083 17.8137C1.14736 17.2626 2.02981 17.2626 2.57408 17.8138Z" fill="url(#paint0_linear_981_10577)" />
|
||||
<path opacity="0.7" fillRule="evenodd" clipRule="evenodd" d="M9.12583 18.2374C9.66912 18.7896 9.66752 19.6832 9.12226 20.2333L5.2617 24.1286C4.71644 24.6787 3.83399 24.6771 3.2907 24.125C2.74741 23.5728 2.74901 22.6792 3.29427 22.1291L7.15483 18.2338C7.70009 17.6837 8.58254 17.6853 9.12583 18.2374Z" fill="url(#paint1_linear_981_10577)" />
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_981_10577" x1="1.57463" y1="17.4004" x2="1.57463" y2="20.2513" gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" stopOpacity="0.8" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
<linearGradient id="paint1_linear_981_10577" x1="6.20827" y1="17.8223" x2="6.20827" y2="24.5401" gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" stopOpacity="0.8" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Progress Bar Component for Section Headers
|
||||
const SectionProgressBar: React.FC<{ currentStep: number; totalSteps: number }> = ({ currentStep, totalSteps }) => {
|
||||
return (
|
||||
<div className="p-4 bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden">
|
||||
{Array.from({ length: Math.min(7, totalSteps) }, (_, index) => {
|
||||
const isActive = index < Math.ceil((currentStep / totalSteps) * 7);
|
||||
return (
|
||||
<div key={index}>
|
||||
{isActive ? (
|
||||
<div className="w-6 h-1 bg-Brand-Orange rounded-3xl" />
|
||||
) : (
|
||||
<svg width="4" height="4" viewBox="0 0 4 4" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="4" height="4" rx="2" fill="var(--Neutrals-NeutralSlate300, #D5D7DA)" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Question Input Component
|
||||
const QuestionInput: React.FC<{
|
||||
question: EmployeeQuestion;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}> = ({ question, value, onChange }) => {
|
||||
switch (question.type) {
|
||||
case 'scale':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch flex justify-between items-center gap-2">
|
||||
<span className="text-sm text-Neutrals-NeutralSlate500">{question.scaleLabels?.min}</span>
|
||||
<div className="flex gap-2">
|
||||
{Array.from({ length: question.scaleMax! - question.scaleMin! + 1 }, (_, index) => {
|
||||
const ratingValue = question.scaleMin! + index;
|
||||
const isSelected = parseInt(value) === ratingValue;
|
||||
return (
|
||||
<button
|
||||
key={ratingValue}
|
||||
onClick={() => onChange(ratingValue.toString())}
|
||||
className={`w-10 h-10 rounded-full flex items-center justify-center text-sm font-medium transition-colors ${
|
||||
isSelected
|
||||
? 'bg-Brand-Orange text-white'
|
||||
: 'bg-Neutrals-NeutralSlate100 text-Neutrals-NeutralSlate700 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
{ratingValue}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<span className="text-sm text-Neutrals-NeutralSlate500">{question.scaleLabels?.max}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'yesno':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch inline-flex justify-center items-center gap-3">
|
||||
<div
|
||||
onClick={() => onChange('No')}
|
||||
className={`w-20 h-20 relative rounded-[999px] overflow-hidden cursor-pointer transition-colors ${
|
||||
value === 'No'
|
||||
? 'bg-Neutrals-NeutralSlate800'
|
||||
: 'bg-Neutrals-NeutralSlate100 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
<div className={`absolute inset-0 flex items-center justify-center text-center text-base font-normal font-['Inter'] leading-normal ${
|
||||
value === 'No' ? 'text-Neutrals-NeutralSlate0' : 'text-Neutrals-NeutralSlate950'
|
||||
}`}>
|
||||
No
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
onClick={() => onChange('Yes')}
|
||||
className={`w-20 h-20 relative rounded-[999px] overflow-hidden cursor-pointer transition-colors ${
|
||||
value === 'Yes'
|
||||
? 'bg-Neutrals-NeutralSlate800'
|
||||
: 'bg-Neutrals-NeutralSlate100 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
<div className={`absolute inset-0 flex items-center justify-center text-center text-base font-normal font-['Inter'] leading-normal ${
|
||||
value === 'Yes' ? 'text-Neutrals-NeutralSlate0' : 'text-Neutrals-NeutralSlate950'
|
||||
}`}>
|
||||
Yes
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'textarea':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch min-h-40 p-5 relative bg-Neutrals-NeutralSlate100 rounded-xl inline-flex justify-start items-start gap-2.5">
|
||||
<textarea
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="flex-1 bg-transparent text-Neutrals-NeutralSlate950 text-base font-normal font-['Inter'] leading-normal placeholder:text-Neutrals-NeutralSlate500 outline-none resize-none"
|
||||
placeholder={question.placeholder || "Type your answer...."}
|
||||
rows={6}
|
||||
/>
|
||||
<div className="w-3 h-3 absolute right-5 bottom-5">
|
||||
<div className="w-2 h-2 absolute top-0.5 left-0.5 outline outline-1 outline-offset-[-0.50px] outline-Neutrals-NeutralSlate500" />
|
||||
<div className="w-1 h-1 absolute bottom-0 right-0 outline outline-1 outline-offset-[-0.50px] outline-Neutrals-NeutralSlate500" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
default: // text input
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch px-4 py-3.5 bg-Neutrals-NeutralSlate100 rounded-[999px] inline-flex justify-start items-center gap-2 overflow-hidden">
|
||||
<input
|
||||
type={question.id === 'email' ? 'email' : 'text'}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="flex-1 bg-transparent text-Neutrals-NeutralSlate950 text-sm font-normal font-['Inter'] leading-tight placeholder:text-Neutrals-NeutralSlate500 outline-none"
|
||||
placeholder={question.placeholder || "Enter your answer..."}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Navigation Buttons Component
|
||||
const NavigationButtons: React.FC<{
|
||||
onBack?: () => void;
|
||||
onNext: () => void;
|
||||
onSkip?: () => void;
|
||||
nextDisabled?: boolean;
|
||||
isSubmitting?: boolean;
|
||||
currentStep: number;
|
||||
totalSteps: number;
|
||||
isLastStep?: boolean;
|
||||
}> = ({ onBack, onNext, onSkip, nextDisabled, isSubmitting, currentStep, totalSteps, isLastStep }) => {
|
||||
return (
|
||||
<div className="self-stretch inline-flex justify-start items-start gap-2">
|
||||
{onBack && (
|
||||
<button
|
||||
onClick={onBack}
|
||||
className="h-12 px-8 py-3.5 bg-Neutrals-NeutralSlate100 rounded-[999px] flex justify-center items-center gap-1 overflow-hidden hover:bg-Neutrals-NeutralSlate200"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Neutrals-NeutralSlate950 text-sm font-medium font-['Inter'] leading-tight">Back</div>
|
||||
</div>
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={onNext}
|
||||
disabled={nextDisabled || isSubmitting}
|
||||
className="flex-1 h-12 px-4 py-3.5 bg-Brand-Orange rounded-[999px] outline outline-2 outline-offset-[-2px] outline-blue-400 flex justify-center items-center gap-1 overflow-hidden disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Other-White text-sm font-medium font-['Inter'] leading-tight">
|
||||
{isSubmitting ? 'Submitting...' : (isLastStep ? 'Submit' : 'Next')}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
{onSkip && (
|
||||
<div
|
||||
onClick={onSkip}
|
||||
className="px-3 py-1.5 absolute right-6 top-6 bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden cursor-pointer hover:bg-Neutrals-NeutralSlate200"
|
||||
>
|
||||
<div className="justify-start text-Neutrals-NeutralSlate500 text-sm font-medium font-['Inter'] leading-none">Skip</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Welcome Screen Component
|
||||
const WelcomeScreen: React.FC<{
|
||||
onStart: () => void;
|
||||
currentEmployee?: any;
|
||||
isInviteFlow: boolean;
|
||||
error?: string;
|
||||
}> = ({ onStart, currentEmployee, isInviteFlow, error }) => {
|
||||
return (
|
||||
<div className="w-full h-screen bg-white inline-flex justify-start items-center overflow-hidden">
|
||||
<div className="flex-1 h-full px-32 py-48 bg-Neutrals-NeutralSlate0 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 max-w-[464px] inline-flex flex-col justify-start items-start gap-12">
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-6">
|
||||
<div className="w-12 h-12 relative bg-Brand-Orange rounded-xl outline outline-2 outline-offset-[-2px] outline-blue-400 overflow-hidden">
|
||||
<div className="w-12 h-12 left-0 top-0 absolute bg-gradient-to-b from-white/0 to-white/10" />
|
||||
<div className="left-[12px] top-[9.33px] absolute">
|
||||
<AuditlyIcon />
|
||||
</div>
|
||||
</div>
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch justify-start text-Neutrals-NeutralSlate800 text-5xl font-medium font-['Neue_Montreal'] leading-[48px]">
|
||||
Welcome to Auditly!
|
||||
</div>
|
||||
<div className="self-stretch justify-center text-Neutrals-NeutralSlate500 text-base font-normal font-['Inter'] leading-normal">
|
||||
Please complete this questionnaire to help us understand your role and create personalized insights.
|
||||
</div>
|
||||
{currentEmployee && (
|
||||
<div className="inline-flex items-center px-4 py-2 bg-blue-100 dark:bg-blue-900 rounded-lg">
|
||||
<span className="text-sm text-blue-800 dark:text-blue-200">
|
||||
👋 Hello {currentEmployee.name}! {currentEmployee.role && `(${currentEmployee.role})`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className="inline-flex items-center px-4 py-2 bg-red-100 dark:bg-red-900 rounded-lg">
|
||||
<span className="text-sm text-red-800 dark:text-red-200">
|
||||
⚠️ {error}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={onStart}
|
||||
className="self-stretch px-4 py-3.5 bg-Brand-Orange rounded-[999px] outline outline-2 outline-offset-[-2px] outline-blue-400 inline-flex justify-center items-center gap-1 overflow-hidden"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Other-White text-sm font-medium font-['Inter'] leading-tight">Start Assessment</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 h-full px-20 py-16 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 self-stretch origin-top-left rotate-180 rounded-3xl inline-flex flex-col justify-center items-center gap-2.5 overflow-hidden">
|
||||
<img className="self-stretch flex-1" src="https://placehold.co/560x682" alt="Welcome" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Question Step Component
|
||||
const QuestionStep: React.FC<{
|
||||
question: EmployeeQuestion;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
onNext: () => void;
|
||||
onBack?: () => void;
|
||||
onSkip?: () => void;
|
||||
currentStep: number;
|
||||
totalSteps: number;
|
||||
isSubmitting?: boolean;
|
||||
isLastStep?: boolean;
|
||||
}> = ({ question, value, onChange, onNext, onBack, onSkip, currentStep, totalSteps, isSubmitting, isLastStep }) => {
|
||||
const isRequired = question.required;
|
||||
const isAnswered = value && value.trim().length > 0;
|
||||
const nextDisabled = isRequired ? !isAnswered : false;
|
||||
|
||||
return (
|
||||
<div className="w-full h-screen py-6 relative bg-Neutrals-NeutralSlate0 inline-flex flex-col justify-center items-center gap-9">
|
||||
<div className="w-full max-w-[464px] min-w-[464px] flex flex-col justify-start items-start gap-12">
|
||||
<QuestionInput question={question} value={value} onChange={onChange} />
|
||||
<NavigationButtons
|
||||
onBack={onBack}
|
||||
onNext={onNext}
|
||||
onSkip={onSkip}
|
||||
nextDisabled={nextDisabled}
|
||||
isSubmitting={isSubmitting}
|
||||
currentStep={currentStep}
|
||||
totalSteps={totalSteps}
|
||||
isLastStep={isLastStep}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Progress indicators */}
|
||||
<div className="px-3 py-1.5 left-[24px] top-[24px] absolute bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden">
|
||||
<div className="justify-start text-Neutrals-NeutralSlate500 text-sm font-medium font-['Inter'] uppercase leading-none">
|
||||
{currentStep} of {totalSteps}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="w-[464px] max-w-[464px] min-w-[464px] left-[488px] top-[24px] absolute flex flex-col justify-start items-center gap-4">
|
||||
<SectionProgressBar currentStep={currentStep} totalSteps={totalSteps} />
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate500 text-base font-medium font-['Neue_Montreal'] leading-normal">
|
||||
Employee Assessment
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Thank You Page Component
|
||||
const ThankYouPage: React.FC = () => {
|
||||
return (
|
||||
<div className="w-full h-screen bg-white inline-flex justify-start items-center overflow-hidden">
|
||||
<div className="flex-1 h-full px-32 py-48 bg-Neutrals-NeutralSlate0 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 max-w-[464px] inline-flex flex-col justify-start items-start gap-12">
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-6">
|
||||
<div className="w-12 h-12 relative bg-Brand-Orange rounded-xl outline outline-2 outline-offset-[-2px] outline-blue-400 overflow-hidden">
|
||||
<div className="w-12 h-12 left-0 top-0 absolute bg-gradient-to-b from-white/0 to-white/10" />
|
||||
<div className="left-[12px] top-[9.33px] absolute">
|
||||
<AuditlyIcon />
|
||||
</div>
|
||||
</div>
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch justify-start text-Neutrals-NeutralSlate800 text-5xl font-medium font-['Neue_Montreal'] leading-[48px]">
|
||||
Thank you! Your assessment has been submitted!
|
||||
</div>
|
||||
<div className="self-stretch justify-center text-Neutrals-NeutralSlate500 text-base font-normal font-['Inter'] leading-normal">
|
||||
Your responses have been recorded and your AI-powered performance report will be generated shortly.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 h-full px-20 py-16 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 self-stretch origin-top-left rotate-180 rounded-3xl inline-flex flex-col justify-center items-center gap-2.5 overflow-hidden">
|
||||
<img className="self-stretch flex-1" src="https://placehold.co/560x682" alt="Thank you" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Main Component
|
||||
const EmployeeQuestionnaireMerged: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const params = useParams();
|
||||
const { user } = useAuth();
|
||||
|
||||
// Check if this is an invite-based flow (no auth/org needed)
|
||||
const inviteCode = params.inviteCode;
|
||||
const isInviteFlow = !!inviteCode;
|
||||
|
||||
// Only use org context for authenticated flows
|
||||
let submitEmployeeAnswers, generateEmployeeReport, employees;
|
||||
if (!isInviteFlow) {
|
||||
const orgContext = useOrg();
|
||||
({ submitEmployeeAnswers, generateEmployeeReport, employees } = orgContext);
|
||||
} else {
|
||||
// For invite flows, we don't need these functions from org context
|
||||
submitEmployeeAnswers = null;
|
||||
generateEmployeeReport = null;
|
||||
employees = [];
|
||||
}
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(0); // 0 = welcome screen
|
||||
const [answers, setAnswers] = useState<EmployeeSubmissionAnswers>({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [inviteEmployee, setInviteEmployee] = useState<any>(null);
|
||||
const [isLoadingInvite, setIsLoadingInvite] = useState(false);
|
||||
|
||||
// Get non-followup questions (we'll handle followups conditionally)
|
||||
const visibleQuestions = EMPLOYEE_QUESTIONS.filter(q => !q.followupTo);
|
||||
const totalSteps = visibleQuestions.length;
|
||||
|
||||
// Load invite details if this is an invite flow
|
||||
useEffect(() => {
|
||||
if (inviteCode) {
|
||||
loadInviteDetails(inviteCode);
|
||||
}
|
||||
}, [inviteCode]);
|
||||
|
||||
const loadInviteDetails = async (code: string) => {
|
||||
setIsLoadingInvite(true);
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/getInvitationStatus?code=${code}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.used) {
|
||||
setError('This invitation has already been used');
|
||||
} else if (data.employee) {
|
||||
setInviteEmployee(data.employee);
|
||||
setError('');
|
||||
} else {
|
||||
setError('Invalid invitation data');
|
||||
}
|
||||
} else {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
||||
setError(errorData.error || 'Invalid or expired invitation link');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error loading invite details:', err);
|
||||
setError('Failed to load invitation details');
|
||||
} finally {
|
||||
setIsLoadingInvite(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Get employee info from multiple sources
|
||||
const invitedEmployee = location.state?.invitedEmployee;
|
||||
|
||||
// Determine current employee - for invite flow, use invite employee data
|
||||
let currentEmployee;
|
||||
if (isInviteFlow) {
|
||||
currentEmployee = inviteEmployee;
|
||||
} else {
|
||||
// Original auth-based logic
|
||||
currentEmployee = invitedEmployee || employees.find(emp => emp.email === user?.email);
|
||||
|
||||
if (!currentEmployee && user?.email) {
|
||||
// Try case-insensitive email matching
|
||||
currentEmployee = employees.find(emp =>
|
||||
emp.email?.toLowerCase() === user.email?.toLowerCase()
|
||||
);
|
||||
|
||||
if (!currentEmployee && invitedEmployee) {
|
||||
currentEmployee = employees.find(emp =>
|
||||
emp.name === invitedEmployee.name || emp.id === invitedEmployee.id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Demo mode fallbacks
|
||||
if (!currentEmployee && user?.email === 'demo@auditly.local' && employees.length > 0) {
|
||||
currentEmployee = employees[employees.length - 1];
|
||||
}
|
||||
|
||||
if (!currentEmployee && employees.length === 1) {
|
||||
currentEmployee = employees[0];
|
||||
}
|
||||
}
|
||||
|
||||
const handleAnswerChange = (questionId: string, value: string) => {
|
||||
setAnswers(prev => ({ ...prev, [questionId]: value }));
|
||||
};
|
||||
|
||||
const submitViaInvite = async (answers: EmployeeSubmissionAnswers, inviteCode: string) => {
|
||||
try {
|
||||
// First, consume the invite to mark it as used
|
||||
const consumeResponse = await fetch(`${API_URL}/consumeInvitation`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code: inviteCode })
|
||||
});
|
||||
|
||||
if (!consumeResponse.ok) {
|
||||
throw new Error('Failed to process invitation');
|
||||
}
|
||||
|
||||
// Get orgId from the consume response
|
||||
const consumeData = await consumeResponse.json();
|
||||
const orgId = consumeData.orgId;
|
||||
|
||||
// Submit the questionnaire answers using Cloud Function
|
||||
const submitResponse = await fetch(`${API_URL}/submitEmployeeAnswers`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
inviteCode: inviteCode,
|
||||
answers: answers,
|
||||
orgId: orgId
|
||||
})
|
||||
});
|
||||
|
||||
if (!submitResponse.ok) {
|
||||
const errorData = await submitResponse.json();
|
||||
throw new Error(errorData.error || 'Failed to submit questionnaire');
|
||||
}
|
||||
|
||||
const result = await submitResponse.json();
|
||||
return { success: true, reportGenerated: !!result.report };
|
||||
} catch (error) {
|
||||
console.error('Invite submission error:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSubmitting(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
// Validate required questions
|
||||
const requiredQuestions = visibleQuestions.filter(q => q.required);
|
||||
const missingAnswers = requiredQuestions.filter(q => !answers[q.id]?.trim());
|
||||
|
||||
if (missingAnswers.length > 0) {
|
||||
setError(`Please answer all required questions`);
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit answers - different logic for invite vs auth flow
|
||||
let result;
|
||||
if (isInviteFlow) {
|
||||
// Direct API submission for invite flow (no auth needed)
|
||||
result = await submitViaInvite(answers, inviteCode);
|
||||
} else {
|
||||
// Use org context for authenticated flow
|
||||
if (!currentEmployee) {
|
||||
// Enhanced fallback logic for authenticated users
|
||||
if (employees.length > 0) {
|
||||
let fallbackEmployee = employees.find(emp =>
|
||||
emp.email?.toLowerCase().includes(user?.email?.toLowerCase().split('@')[0] || '')
|
||||
);
|
||||
|
||||
if (!fallbackEmployee) {
|
||||
const userDomain = user?.email?.split('@')[1];
|
||||
fallbackEmployee = employees.find(emp =>
|
||||
emp.email?.split('@')[1] === userDomain
|
||||
) || employees[employees.length - 1];
|
||||
}
|
||||
|
||||
const success = await submitEmployeeAnswers(fallbackEmployee.id, answers);
|
||||
if (success) {
|
||||
try {
|
||||
const report = await generateEmployeeReport(fallbackEmployee);
|
||||
console.log('Report generated successfully:', report);
|
||||
} catch (reportError) {
|
||||
console.error('Failed to generate report:', reportError);
|
||||
}
|
||||
|
||||
// Navigate to completion
|
||||
setCurrentStep(totalSteps + 1); // Thank you page
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setError(`We couldn't match your account (${user?.email}) with an employee record. Please contact your administrator.`);
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
result = await submitEmployeeAnswers(currentEmployee.id, answers);
|
||||
}
|
||||
|
||||
if (result.success) {
|
||||
// Show thank you page
|
||||
setCurrentStep(totalSteps + 1);
|
||||
} else {
|
||||
setError(result.message || 'Failed to submit questionnaire');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Submission error:', error);
|
||||
setError('Failed to submit questionnaire. Please try again.');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (currentStep === 0) {
|
||||
// From welcome screen to first question
|
||||
setCurrentStep(1);
|
||||
} else if (currentStep === totalSteps) {
|
||||
// From last question to submission
|
||||
handleSubmit();
|
||||
} else {
|
||||
// Between questions
|
||||
setCurrentStep(currentStep + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (currentStep > 0) {
|
||||
setCurrentStep(currentStep - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSkip = () => {
|
||||
if (currentStep < totalSteps) {
|
||||
setCurrentStep(currentStep + 1);
|
||||
}
|
||||
};
|
||||
|
||||
// Early return for invite flow loading state
|
||||
if (isInviteFlow && isLoadingInvite) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[--background-primary] py-8 px-4 flex items-center justify-center">
|
||||
<div className="max-w-4xl mx-auto text-center">
|
||||
<div className="w-16 h-16 bg-[--accent] rounded-full flex items-center justify-center font-bold text-white text-2xl mx-auto mb-4">
|
||||
A
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-[--text-primary] mb-4">Loading Your Invitation...</h1>
|
||||
<p className="text-[--text-secondary]">Please wait while we verify your invitation.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Early return for invite flow error state
|
||||
if (isInviteFlow && error && currentStep === 0) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[--background-primary] py-8 px-4 flex items-center justify-center">
|
||||
<div className="max-w-4xl mx-auto text-center">
|
||||
<div className="w-16 h-16 bg-red-500 rounded-full flex items-center justify-center font-bold text-white text-2xl mx-auto mb-4">
|
||||
!
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-[--text-primary] mb-4">Invitation Error</h1>
|
||||
<p className="text-[--text-secondary] mb-6">{error}</p>
|
||||
<button
|
||||
onClick={() => window.location.href = '/'}
|
||||
className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700"
|
||||
>
|
||||
Return to Homepage
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Render current step
|
||||
if (currentStep === 0) {
|
||||
// Welcome screen
|
||||
return (
|
||||
<WelcomeScreen
|
||||
onStart={handleNext}
|
||||
currentEmployee={currentEmployee}
|
||||
isInviteFlow={isInviteFlow}
|
||||
error={!currentEmployee && !isInviteFlow ? `Employee info not found. User: ${user?.email}` : undefined}
|
||||
/>
|
||||
);
|
||||
} else if (currentStep > totalSteps) {
|
||||
// Thank you page
|
||||
return <ThankYouPage />;
|
||||
} else {
|
||||
// Question step
|
||||
const question = visibleQuestions[currentStep - 1];
|
||||
const isLastStep = currentStep === totalSteps;
|
||||
|
||||
return (
|
||||
<QuestionStep
|
||||
question={question}
|
||||
value={answers[question.id] || ''}
|
||||
onChange={(value) => handleAnswerChange(question.id, value)}
|
||||
onNext={handleNext}
|
||||
onBack={currentStep > 1 ? handleBack : undefined}
|
||||
onSkip={!question.required ? handleSkip : undefined}
|
||||
currentStep={currentStep}
|
||||
totalSteps={totalSteps}
|
||||
isSubmitting={isSubmitting}
|
||||
isLastStep={isLastStep}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default EmployeeQuestionnaireMerged;
|
||||
675
pages/EmployeeQuestionnaire_Backup.tsx
Normal file
675
pages/EmployeeQuestionnaire_Backup.tsx
Normal file
@@ -0,0 +1,675 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate, useLocation, useParams } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useOrg } from '../contexts/OrgContext';
|
||||
import { EMPLOYEE_QUESTIONS, EmployeeSubmissionAnswers } from '../employeeQuestions';
|
||||
import { API_URL } from '../constants';
|
||||
import { FigmaRatingScale, FigmaTextArea, FigmaNavigationButtons } from '../components/figma/FigmaQuestion';
|
||||
import { FigmaMultipleChoice } from '../components/figma/FigmaMultipleChoice';
|
||||
|
||||
// Icon SVG Component
|
||||
const AuditlyIcon: React.FC = () => (
|
||||
<svg width="24" height="30" viewBox="0 0 24 30" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path opacity="0.5" fillRule="evenodd" clipRule="evenodd" d="M2.57408 17.8138C3.11835 18.3649 3.11834 19.2585 2.57406 19.8097L2.54619 19.8379C2.00191 20.389 1.11946 20.389 0.57519 19.8379C0.030919 19.2867 0.0309274 18.3931 0.575208 17.842L0.603083 17.8137C1.14736 17.2626 2.02981 17.2626 2.57408 17.8138Z" fill="url(#paint0_linear_981_10577)" />
|
||||
<path opacity="0.7" fillRule="evenodd" clipRule="evenodd" d="M9.12583 18.2374C9.66912 18.7896 9.66752 19.6832 9.12226 20.2333L5.2617 24.1286C4.71644 24.6787 3.83399 24.6771 3.2907 24.125C2.74741 23.5728 2.74901 22.6792 3.29427 22.1291L7.15483 18.2338C7.70009 17.6837 8.58254 17.6853 9.12583 18.2374Z" fill="url(#paint1_linear_981_10577)" />
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_981_10577" x1="1.57463" y1="17.4004" x2="1.57463" y2="20.2513" gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" stopOpacity="0.8" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
<linearGradient id="paint1_linear_981_10577" x1="6.20827" y1="17.8223" x2="6.20827" y2="24.5401" gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" stopOpacity="0.8" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Progress Bar Component for Section Headers
|
||||
const SectionProgressBar: React.FC<{ currentStep: number; totalSteps: number }> = ({ currentStep, totalSteps }) => {
|
||||
return (
|
||||
<div className="p-4 bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden">
|
||||
{Array.from({ length: Math.min(7, totalSteps) }, (_, index) => {
|
||||
const isActive = index < Math.ceil((currentStep / totalSteps) * 7);
|
||||
return (
|
||||
<div key={index}>
|
||||
{isActive ? (
|
||||
<div className="w-6 h-1 bg-Brand-Orange rounded-3xl" />
|
||||
) : (
|
||||
<svg width="4" height="4" viewBox="0 0 4 4" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="4" height="4" rx="2" fill="var(--Neutrals-NeutralSlate300, #D5D7DA)" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Question Input Component
|
||||
const QuestionInput: React.FC<{
|
||||
question: EmployeeQuestion;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}> = ({ question, value, onChange }) => {
|
||||
switch (question.type) {
|
||||
case 'scale':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch flex justify-between items-center gap-2">
|
||||
<span className="text-sm text-Neutrals-NeutralSlate500">{question.scaleLabels?.min}</span>
|
||||
<div className="flex gap-2">
|
||||
{Array.from({ length: question.scaleMax! - question.scaleMin! + 1 }, (_, index) => {
|
||||
const ratingValue = question.scaleMin! + index;
|
||||
const isSelected = parseInt(value) === ratingValue;
|
||||
return (
|
||||
<button
|
||||
key={ratingValue}
|
||||
onClick={() => onChange(ratingValue.toString())}
|
||||
className={`w-10 h-10 rounded-full flex items-center justify-center text-sm font-medium transition-colors ${
|
||||
isSelected
|
||||
? 'bg-Brand-Orange text-white'
|
||||
: 'bg-Neutrals-NeutralSlate100 text-Neutrals-NeutralSlate700 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
{ratingValue}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<span className="text-sm text-Neutrals-NeutralSlate500">{question.scaleLabels?.max}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'yesno':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch inline-flex justify-center items-center gap-3">
|
||||
<div
|
||||
onClick={() => onChange('No')}
|
||||
className={`w-20 h-20 relative rounded-[999px] overflow-hidden cursor-pointer transition-colors ${
|
||||
value === 'No'
|
||||
? 'bg-Neutrals-NeutralSlate800'
|
||||
: 'bg-Neutrals-NeutralSlate100 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
<div className={`absolute inset-0 flex items-center justify-center text-center text-base font-normal font-['Inter'] leading-normal ${
|
||||
value === 'No' ? 'text-Neutrals-NeutralSlate0' : 'text-Neutrals-NeutralSlate950'
|
||||
}`}>
|
||||
No
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
onClick={() => onChange('Yes')}
|
||||
className={`w-20 h-20 relative rounded-[999px] overflow-hidden cursor-pointer transition-colors ${
|
||||
value === 'Yes'
|
||||
? 'bg-Neutrals-NeutralSlate800'
|
||||
: 'bg-Neutrals-NeutralSlate100 hover:bg-Neutrals-NeutralSlate200'
|
||||
}`}
|
||||
>
|
||||
<div className={`absolute inset-0 flex items-center justify-center text-center text-base font-normal font-['Inter'] leading-normal ${
|
||||
value === 'Yes' ? 'text-Neutrals-NeutralSlate0' : 'text-Neutrals-NeutralSlate950'
|
||||
}`}>
|
||||
Yes
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'textarea':
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch min-h-40 p-5 relative bg-Neutrals-NeutralSlate100 rounded-xl inline-flex justify-start items-start gap-2.5">
|
||||
<textarea
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="flex-1 bg-transparent text-Neutrals-NeutralSlate950 text-base font-normal font-['Inter'] leading-normal placeholder:text-Neutrals-NeutralSlate500 outline-none resize-none"
|
||||
placeholder={question.placeholder || "Type your answer...."}
|
||||
rows={6}
|
||||
/>
|
||||
<div className="w-3 h-3 absolute right-5 bottom-5">
|
||||
<div className="w-2 h-2 absolute top-0.5 left-0.5 outline outline-1 outline-offset-[-0.50px] outline-Neutrals-NeutralSlate500" />
|
||||
<div className="w-1 h-1 absolute bottom-0 right-0 outline outline-1 outline-offset-[-0.50px] outline-Neutrals-NeutralSlate500" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
default: // text input
|
||||
return (
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate950 text-2xl font-medium font-['Neue_Montreal'] leading-normal">
|
||||
{question.prompt}
|
||||
</div>
|
||||
<div className="self-stretch px-4 py-3.5 bg-Neutrals-NeutralSlate100 rounded-[999px] inline-flex justify-start items-center gap-2 overflow-hidden">
|
||||
<input
|
||||
type={question.id === 'email' ? 'email' : 'text'}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="flex-1 bg-transparent text-Neutrals-NeutralSlate950 text-sm font-normal font-['Inter'] leading-tight placeholder:text-Neutrals-NeutralSlate500 outline-none"
|
||||
placeholder={question.placeholder || "Enter your answer..."}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Navigation Buttons Component
|
||||
const NavigationButtons: React.FC<{
|
||||
onBack?: () => void;
|
||||
onNext: () => void;
|
||||
onSkip?: () => void;
|
||||
nextDisabled?: boolean;
|
||||
isSubmitting?: boolean;
|
||||
currentStep: number;
|
||||
totalSteps: number;
|
||||
isLastStep?: boolean;
|
||||
}> = ({ onBack, onNext, onSkip, nextDisabled, isSubmitting, currentStep, totalSteps, isLastStep }) => {
|
||||
return (
|
||||
<div className="self-stretch inline-flex justify-start items-start gap-2">
|
||||
{onBack && (
|
||||
<button
|
||||
onClick={onBack}
|
||||
className="h-12 px-8 py-3.5 bg-Neutrals-NeutralSlate100 rounded-[999px] flex justify-center items-center gap-1 overflow-hidden hover:bg-Neutrals-NeutralSlate200"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Neutrals-NeutralSlate950 text-sm font-medium font-['Inter'] leading-tight">Back</div>
|
||||
</div>
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={onNext}
|
||||
disabled={nextDisabled || isSubmitting}
|
||||
className="flex-1 h-12 px-4 py-3.5 bg-Brand-Orange rounded-[999px] outline outline-2 outline-offset-[-2px] outline-blue-400 flex justify-center items-center gap-1 overflow-hidden disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Other-White text-sm font-medium font-['Inter'] leading-tight">
|
||||
{isSubmitting ? 'Submitting...' : (isLastStep ? 'Submit' : 'Next')}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
{onSkip && (
|
||||
<div
|
||||
onClick={onSkip}
|
||||
className="px-3 py-1.5 absolute right-6 top-6 bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden cursor-pointer hover:bg-Neutrals-NeutralSlate200"
|
||||
>
|
||||
<div className="justify-start text-Neutrals-NeutralSlate500 text-sm font-medium font-['Inter'] leading-none">Skip</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Welcome Screen Component
|
||||
const WelcomeScreen: React.FC<{
|
||||
onStart: () => void;
|
||||
currentEmployee?: any;
|
||||
isInviteFlow: boolean;
|
||||
error?: string;
|
||||
}> = ({ onStart, currentEmployee, isInviteFlow, error }) => {
|
||||
return (
|
||||
<div className="w-full h-screen bg-white inline-flex justify-start items-center overflow-hidden">
|
||||
<div className="flex-1 h-full px-32 py-48 bg-Neutrals-NeutralSlate0 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 max-w-[464px] inline-flex flex-col justify-start items-start gap-12">
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-6">
|
||||
<div className="w-12 h-12 relative bg-Brand-Orange rounded-xl outline outline-2 outline-offset-[-2px] outline-blue-400 overflow-hidden">
|
||||
<div className="w-12 h-12 left-0 top-0 absolute bg-gradient-to-b from-white/0 to-white/10" />
|
||||
<div className="left-[12px] top-[9.33px] absolute">
|
||||
<AuditlyIcon />
|
||||
</div>
|
||||
</div>
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch justify-start text-Neutrals-NeutralSlate800 text-5xl font-medium font-['Neue_Montreal'] leading-[48px]">
|
||||
Welcome to Auditly!
|
||||
</div>
|
||||
<div className="self-stretch justify-center text-Neutrals-NeutralSlate500 text-base font-normal font-['Inter'] leading-normal">
|
||||
Please complete this questionnaire to help us understand your role and create personalized insights.
|
||||
</div>
|
||||
{currentEmployee && (
|
||||
<div className="inline-flex items-center px-4 py-2 bg-blue-100 dark:bg-blue-900 rounded-lg">
|
||||
<span className="text-sm text-blue-800 dark:text-blue-200">
|
||||
👋 Hello {currentEmployee.name}! {currentEmployee.role && `(${currentEmployee.role})`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className="inline-flex items-center px-4 py-2 bg-red-100 dark:bg-red-900 rounded-lg">
|
||||
<span className="text-sm text-red-800 dark:text-red-200">
|
||||
⚠️ {error}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={onStart}
|
||||
className="self-stretch px-4 py-3.5 bg-Brand-Orange rounded-[999px] outline outline-2 outline-offset-[-2px] outline-blue-400 inline-flex justify-center items-center gap-1 overflow-hidden"
|
||||
>
|
||||
<div className="px-1 flex justify-center items-center">
|
||||
<div className="justify-center text-Other-White text-sm font-medium font-['Inter'] leading-tight">Start Assessment</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 h-full px-20 py-16 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 self-stretch origin-top-left rotate-180 rounded-3xl inline-flex flex-col justify-center items-center gap-2.5 overflow-hidden">
|
||||
<img className="self-stretch flex-1" src="https://placehold.co/560x682" alt="Welcome" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Question Step Component
|
||||
const QuestionStep: React.FC<{
|
||||
question: EmployeeQuestion;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
onNext: () => void;
|
||||
onBack?: () => void;
|
||||
onSkip?: () => void;
|
||||
currentStep: number;
|
||||
totalSteps: number;
|
||||
isSubmitting?: boolean;
|
||||
isLastStep?: boolean;
|
||||
}> = ({ question, value, onChange, onNext, onBack, onSkip, currentStep, totalSteps, isSubmitting, isLastStep }) => {
|
||||
const isRequired = question.required;
|
||||
const isAnswered = value && value.trim().length > 0;
|
||||
const nextDisabled = isRequired ? !isAnswered : false;
|
||||
|
||||
return (
|
||||
<div className="w-full h-screen py-6 relative bg-Neutrals-NeutralSlate0 inline-flex flex-col justify-center items-center gap-9">
|
||||
<div className="w-full max-w-[464px] min-w-[464px] flex flex-col justify-start items-start gap-12">
|
||||
<QuestionInput question={question} value={value} onChange={onChange} />
|
||||
<NavigationButtons
|
||||
onBack={onBack}
|
||||
onNext={onNext}
|
||||
onSkip={onSkip}
|
||||
nextDisabled={nextDisabled}
|
||||
isSubmitting={isSubmitting}
|
||||
currentStep={currentStep}
|
||||
totalSteps={totalSteps}
|
||||
isLastStep={isLastStep}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Progress indicators */}
|
||||
<div className="px-3 py-1.5 left-[24px] top-[24px] absolute bg-Neutrals-NeutralSlate100 rounded-[50px] inline-flex justify-center items-center gap-2 overflow-hidden">
|
||||
<div className="justify-start text-Neutrals-NeutralSlate500 text-sm font-medium font-['Inter'] uppercase leading-none">
|
||||
{currentStep} of {totalSteps}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="w-[464px] max-w-[464px] min-w-[464px] left-[488px] top-[24px] absolute flex flex-col justify-start items-center gap-4">
|
||||
<SectionProgressBar currentStep={currentStep} totalSteps={totalSteps} />
|
||||
<div className="self-stretch text-center justify-start text-Neutrals-NeutralSlate500 text-base font-medium font-['Neue_Montreal'] leading-normal">
|
||||
Employee Assessment
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Thank You Page Component
|
||||
const ThankYouPage: React.FC = () => {
|
||||
return (
|
||||
<div className="w-full h-screen bg-white inline-flex justify-start items-center overflow-hidden">
|
||||
<div className="flex-1 h-full px-32 py-48 bg-Neutrals-NeutralSlate0 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 max-w-[464px] inline-flex flex-col justify-start items-start gap-12">
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-6">
|
||||
<div className="w-12 h-12 relative bg-Brand-Orange rounded-xl outline outline-2 outline-offset-[-2px] outline-blue-400 overflow-hidden">
|
||||
<div className="w-12 h-12 left-0 top-0 absolute bg-gradient-to-b from-white/0 to-white/10" />
|
||||
<div className="left-[12px] top-[9.33px] absolute">
|
||||
<AuditlyIcon />
|
||||
</div>
|
||||
</div>
|
||||
<div className="self-stretch flex flex-col justify-start items-start gap-4">
|
||||
<div className="self-stretch justify-start text-Neutrals-NeutralSlate800 text-5xl font-medium font-['Neue_Montreal'] leading-[48px]">
|
||||
Thank you! Your assessment has been submitted!
|
||||
</div>
|
||||
<div className="self-stretch justify-center text-Neutrals-NeutralSlate500 text-base font-normal font-['Inter'] leading-normal">
|
||||
Your responses have been recorded and your AI-powered performance report will be generated shortly.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 h-full px-20 py-16 flex justify-center items-center gap-2.5 overflow-hidden">
|
||||
<div className="flex-1 self-stretch origin-top-left rotate-180 rounded-3xl inline-flex flex-col justify-center items-center gap-2.5 overflow-hidden">
|
||||
<img className="self-stretch flex-1" src="https://placehold.co/560x682" alt="Thank you" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Main Component
|
||||
const EmployeeQuestionnaire: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const params = useParams();
|
||||
const { user } = useAuth();
|
||||
|
||||
// Check if this is an invite-based flow (no auth/org needed)
|
||||
const inviteCode = params.inviteCode;
|
||||
const isInviteFlow = !!inviteCode;
|
||||
|
||||
// Only use org context for authenticated flows
|
||||
let submitEmployeeAnswers, generateEmployeeReport, employees;
|
||||
if (!isInviteFlow) {
|
||||
const orgContext = useOrg();
|
||||
({ submitEmployeeAnswers, generateEmployeeReport, employees } = orgContext);
|
||||
} else {
|
||||
// For invite flows, we don't need these functions from org context
|
||||
submitEmployeeAnswers = null;
|
||||
generateEmployeeReport = null;
|
||||
employees = [];
|
||||
}
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(0); // 0 = welcome screen
|
||||
const [answers, setAnswers] = useState<EmployeeSubmissionAnswers>({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [inviteEmployee, setInviteEmployee] = useState<any>(null);
|
||||
const [isLoadingInvite, setIsLoadingInvite] = useState(false);
|
||||
|
||||
// Get non-followup questions (we'll handle followups conditionally)
|
||||
const visibleQuestions = EMPLOYEE_QUESTIONS.filter(q => !q.followupTo);
|
||||
const totalSteps = visibleQuestions.length;
|
||||
|
||||
// Load invite details if this is an invite flow
|
||||
useEffect(() => {
|
||||
if (inviteCode) {
|
||||
loadInviteDetails(inviteCode);
|
||||
}
|
||||
}, [inviteCode]);
|
||||
|
||||
const loadInviteDetails = async (code: string) => {
|
||||
setIsLoadingInvite(true);
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/getInvitationStatus?code=${code}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.used) {
|
||||
setError('This invitation has already been used');
|
||||
} else if (data.employee) {
|
||||
setInviteEmployee(data.employee);
|
||||
setError('');
|
||||
} else {
|
||||
setError('Invalid invitation data');
|
||||
}
|
||||
} else {
|
||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
||||
setError(errorData.error || 'Invalid or expired invitation link');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error loading invite details:', err);
|
||||
setError('Failed to load invitation details');
|
||||
} finally {
|
||||
setIsLoadingInvite(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Get employee info from multiple sources
|
||||
const invitedEmployee = location.state?.invitedEmployee;
|
||||
|
||||
// Determine current employee - for invite flow, use invite employee data
|
||||
let currentEmployee;
|
||||
if (isInviteFlow) {
|
||||
currentEmployee = inviteEmployee;
|
||||
} else {
|
||||
// Original auth-based logic
|
||||
currentEmployee = invitedEmployee || employees.find(emp => emp.email === user?.email);
|
||||
|
||||
if (!currentEmployee && user?.email) {
|
||||
// Try case-insensitive email matching
|
||||
currentEmployee = employees.find(emp =>
|
||||
emp.email?.toLowerCase() === user.email?.toLowerCase()
|
||||
);
|
||||
|
||||
if (!currentEmployee && invitedEmployee) {
|
||||
currentEmployee = employees.find(emp =>
|
||||
emp.name === invitedEmployee.name || emp.id === invitedEmployee.id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Demo mode fallbacks
|
||||
if (!currentEmployee && user?.email === 'demo@auditly.local' && employees.length > 0) {
|
||||
currentEmployee = employees[employees.length - 1];
|
||||
}
|
||||
|
||||
if (!currentEmployee && employees.length === 1) {
|
||||
currentEmployee = employees[0];
|
||||
}
|
||||
}
|
||||
|
||||
const handleAnswerChange = (questionId: string, value: string) => {
|
||||
setAnswers(prev => ({ ...prev, [questionId]: value }));
|
||||
};
|
||||
|
||||
const submitViaInvite = async (answers: EmployeeSubmissionAnswers, inviteCode: string) => {
|
||||
try {
|
||||
// First, consume the invite to mark it as used
|
||||
const consumeResponse = await fetch(`${API_URL}/consumeInvitation`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code: inviteCode })
|
||||
});
|
||||
|
||||
if (!consumeResponse.ok) {
|
||||
throw new Error('Failed to process invitation');
|
||||
}
|
||||
|
||||
// Get orgId from the consume response
|
||||
const consumeData = await consumeResponse.json();
|
||||
const orgId = consumeData.orgId;
|
||||
|
||||
// Submit the questionnaire answers using Cloud Function
|
||||
const submitResponse = await fetch(`${API_URL}/submitEmployeeAnswers`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
inviteCode: inviteCode,
|
||||
answers: answers,
|
||||
orgId: orgId
|
||||
})
|
||||
});
|
||||
|
||||
if (!submitResponse.ok) {
|
||||
const errorData = await submitResponse.json();
|
||||
throw new Error(errorData.error || 'Failed to submit questionnaire');
|
||||
}
|
||||
|
||||
const result = await submitResponse.json();
|
||||
return { success: true, reportGenerated: !!result.report };
|
||||
} catch (error) {
|
||||
console.error('Invite submission error:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSubmitting(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
// Validate required questions
|
||||
const requiredQuestions = visibleQuestions.filter(q => q.required);
|
||||
const missingAnswers = requiredQuestions.filter(q => !answers[q.id]?.trim());
|
||||
|
||||
if (missingAnswers.length > 0) {
|
||||
setError(`Please answer all required questions`);
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit answers - different logic for invite vs auth flow
|
||||
let result;
|
||||
if (isInviteFlow) {
|
||||
// Direct API submission for invite flow (no auth needed)
|
||||
result = await submitViaInvite(answers, inviteCode);
|
||||
} else {
|
||||
// Use org context for authenticated flow
|
||||
if (!currentEmployee) {
|
||||
// Enhanced fallback logic for authenticated users
|
||||
if (employees.length > 0) {
|
||||
let fallbackEmployee = employees.find(emp =>
|
||||
emp.email?.toLowerCase().includes(user?.email?.toLowerCase().split('@')[0] || '')
|
||||
);
|
||||
|
||||
if (!fallbackEmployee) {
|
||||
const userDomain = user?.email?.split('@')[1];
|
||||
fallbackEmployee = employees.find(emp =>
|
||||
emp.email?.split('@')[1] === userDomain
|
||||
) || employees[employees.length - 1];
|
||||
}
|
||||
|
||||
const success = await submitEmployeeAnswers(fallbackEmployee.id, answers);
|
||||
if (success) {
|
||||
try {
|
||||
const report = await generateEmployeeReport(fallbackEmployee);
|
||||
console.log('Report generated successfully:', report);
|
||||
} catch (reportError) {
|
||||
console.error('Failed to generate report:', reportError);
|
||||
}
|
||||
|
||||
// Navigate to completion
|
||||
setCurrentStep(totalSteps + 1); // Thank you page
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setError(`We couldn't match your account (${user?.email}) with an employee record. Please contact your administrator.`);
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
result = await submitEmployeeAnswers(currentEmployee.id, answers);
|
||||
}
|
||||
|
||||
if (result.success) {
|
||||
// Show thank you page
|
||||
setCurrentStep(totalSteps + 1);
|
||||
} else {
|
||||
setError(result.message || 'Failed to submit questionnaire');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Submission error:', error);
|
||||
setError('Failed to submit questionnaire. Please try again.');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (currentStep === 0) {
|
||||
// From welcome screen to first question
|
||||
setCurrentStep(1);
|
||||
} else if (currentStep === totalSteps) {
|
||||
// From last question to submission
|
||||
handleSubmit();
|
||||
} else {
|
||||
// Between questions
|
||||
setCurrentStep(currentStep + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (currentStep > 0) {
|
||||
setCurrentStep(currentStep - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSkip = () => {
|
||||
if (currentStep < totalSteps) {
|
||||
setCurrentStep(currentStep + 1);
|
||||
}
|
||||
};
|
||||
|
||||
// Early return for invite flow loading state
|
||||
if (isInviteFlow && isLoadingInvite) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[--background-primary] py-8 px-4 flex items-center justify-center">
|
||||
<div className="max-w-4xl mx-auto text-center">
|
||||
<div className="w-16 h-16 bg-[--accent] rounded-full flex items-center justify-center font-bold text-white text-2xl mx-auto mb-4">
|
||||
A
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-[--text-primary] mb-4">Loading Your Invitation...</h1>
|
||||
<p className="text-[--text-secondary]">Please wait while we verify your invitation.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Early return for invite flow error state
|
||||
if (isInviteFlow && error && currentStep === 0) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[--background-primary] py-8 px-4 flex items-center justify-center">
|
||||
<div className="max-w-4xl mx-auto text-center">
|
||||
<div className="w-16 h-16 bg-red-500 rounded-full flex items-center justify-center font-bold text-white text-2xl mx-auto mb-4">
|
||||
!
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-[--text-primary] mb-4">Invitation Error</h1>
|
||||
<p className="text-[--text-secondary] mb-6">{error}</p>
|
||||
<button
|
||||
onClick={() => window.location.href = '/'}
|
||||
className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700"
|
||||
>
|
||||
Return to Homepage
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Render current step
|
||||
if (currentStep === 0) {
|
||||
// Welcome screen
|
||||
return (
|
||||
<WelcomeScreen
|
||||
onStart={handleNext}
|
||||
currentEmployee={currentEmployee}
|
||||
isInviteFlow={isInviteFlow}
|
||||
error={!currentEmployee && !isInviteFlow ? `Employee info not found. User: ${user?.email}` : undefined}
|
||||
/>
|
||||
);
|
||||
} else if (currentStep > totalSteps) {
|
||||
// Thank you page
|
||||
return <ThankYouPage />;
|
||||
} else {
|
||||
// Question step
|
||||
const question = visibleQuestions[currentStep - 1];
|
||||
const isLastStep = currentStep === totalSteps;
|
||||
|
||||
return (
|
||||
<QuestionStep
|
||||
question={question}
|
||||
value={answers[question.id] || ''}
|
||||
onChange={(value) => handleAnswerChange(question.id, value)}
|
||||
onNext={handleNext}
|
||||
onBack={currentStep > 1 ? handleBack : undefined}
|
||||
onSkip={!question.required ? handleSkip : undefined}
|
||||
currentStep={currentStep}
|
||||
totalSteps={totalSteps}
|
||||
isSubmitting={isSubmitting}
|
||||
isLastStep={isLastStep}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default EmployeeQuestionnaire;
|
||||
@@ -1,52 +0,0 @@
|
||||
// URL utilities for consistent URL management across the application
|
||||
|
||||
// Get site URL from environment variable or default
|
||||
export const getSiteUrl = (): string => {
|
||||
// For client-side (Vite)
|
||||
if (typeof window !== 'undefined') {
|
||||
return import.meta.env.VITE_SITE_URL || window.location.origin;
|
||||
}
|
||||
|
||||
// For server-side (Node.js)
|
||||
return process.env.SITE_URL || 'http://localhost:5173';
|
||||
};
|
||||
|
||||
// Get API URL from environment variable or default
|
||||
export const getApiUrl = (): string => {
|
||||
// For client-side (Vite)
|
||||
if (typeof window !== 'undefined') {
|
||||
return import.meta.env.VITE_API_URL || 'http://localhost:5050';
|
||||
}
|
||||
|
||||
// For server-side (Node.js)
|
||||
return process.env.API_URL || 'http://localhost:5050';
|
||||
};
|
||||
|
||||
// Build full API endpoint URL
|
||||
export const buildApiUrl = (endpoint: string): string => {
|
||||
const baseUrl = getApiUrl();
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
return `${baseUrl}${cleanEndpoint}`;
|
||||
};
|
||||
|
||||
// Build full site URL
|
||||
export const buildSiteUrl = (path: string): string => {
|
||||
const baseUrl = getSiteUrl();
|
||||
const cleanPath = path.startsWith('/') ? path : `/${path}`;
|
||||
return `${baseUrl}${cleanPath}`;
|
||||
};
|
||||
|
||||
// For hash-based routing (React Router with HashRouter)
|
||||
export const buildHashUrl = (path: string): string => {
|
||||
const baseUrl = getSiteUrl();
|
||||
const cleanPath = path.startsWith('/') ? path : `/${path}`;
|
||||
return `${baseUrl}/#${cleanPath}`;
|
||||
};
|
||||
|
||||
export default {
|
||||
getSiteUrl,
|
||||
getApiUrl,
|
||||
buildApiUrl,
|
||||
buildSiteUrl,
|
||||
buildHashUrl
|
||||
};
|
||||
Reference in New Issue
Block a user