Fix up a ton of pages, settings/help/wiki need improvements, report generation needs slight updates. Otherwise completed
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useOrg } from '../contexts/OrgContext';
|
||||
import { onboardingSteps, OnboardingData, initializeOnboardingData } from '../data/onboardingSteps';
|
||||
import { secureApiPOST } from '../services/secureApi';
|
||||
import { secureApiPOST, secureApi } from '../services/secureApi';
|
||||
import {
|
||||
FigmaOnboardingIntro,
|
||||
FigmaOnboardingQuestion,
|
||||
FigmaOnboardingMultipleChoice,
|
||||
FigmaOnboardingForm
|
||||
FigmaOnboardingIntro,
|
||||
FigmaOnboardingQuestion,
|
||||
FigmaOnboardingMultipleChoice,
|
||||
FigmaOnboardingForm
|
||||
} from '../components/onboarding/FigmaOnboardingComponents';
|
||||
|
||||
const Onboarding: React.FC = () => {
|
||||
const { org, upsertOrg, generateCompanyWiki } = useOrg();
|
||||
const { user } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -36,10 +38,12 @@ const Onboarding: React.FC = () => {
|
||||
|
||||
switch (currentStep.type) {
|
||||
case 'form':
|
||||
// Check required fields for form step - using companyDetails field
|
||||
const companyDetails = formData.companyDetails;
|
||||
return typeof companyDetails === 'string' && companyDetails.trim().length > 0;
|
||||
|
||||
// Check required fields for form step - company name and user name
|
||||
const companyName = formData.companyName;
|
||||
const yourName = formData.yourName;
|
||||
return typeof companyName === 'string' && companyName.trim().length > 0 &&
|
||||
typeof yourName === 'string' && yourName.trim().length > 0;
|
||||
|
||||
case 'question':
|
||||
// Check if field is filled
|
||||
if (currentStep.field) {
|
||||
@@ -47,7 +51,7 @@ const Onboarding: React.FC = () => {
|
||||
return Array.isArray(fieldValue) ? fieldValue.length > 0 : String(fieldValue || '').trim().length > 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
case 'multiple_choice':
|
||||
// Check if option is selected
|
||||
if (currentStep.field) {
|
||||
@@ -55,10 +59,10 @@ const Onboarding: React.FC = () => {
|
||||
return String(fieldValue || '').trim().length > 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
case 'intro':
|
||||
return true;
|
||||
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -75,25 +79,15 @@ const Onboarding: React.FC = () => {
|
||||
// Final step: submit all data and complete onboarding
|
||||
setIsGeneratingReport(true);
|
||||
try {
|
||||
// Submit the complete onboarding data
|
||||
const response = await secureApiPOST('onboarding/complete', formData);
|
||||
|
||||
if (response.success) {
|
||||
// Update org with completion status
|
||||
const updatedOrg = {
|
||||
...org,
|
||||
name: formData.companyName,
|
||||
onboardingCompleted: true,
|
||||
updatedAt: Date.now()
|
||||
};
|
||||
|
||||
await upsertOrg(updatedOrg);
|
||||
|
||||
// Navigate to reports
|
||||
navigate('/reports', { replace: true });
|
||||
} else {
|
||||
throw new Error(response.error || 'Failed to complete onboarding');
|
||||
}
|
||||
await upsertOrg({
|
||||
...org,
|
||||
companyName: formData.companyName,
|
||||
companyLogo: formData.companyLogo,
|
||||
onboardingData: formData,
|
||||
onboardingCompleted: true,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
navigate('/reports', { replace: true });
|
||||
} catch (error) {
|
||||
console.error('Error completing onboarding:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||
@@ -119,7 +113,7 @@ const Onboarding: React.FC = () => {
|
||||
const sectionSteps = onboardingSteps.filter(step => step.section === currentStep.section);
|
||||
const currentSectionIndex = sectionSteps.findIndex(step => step.id === currentStep.id);
|
||||
const sectionName = currentStep.sectionName || `Section ${currentStep.section}`;
|
||||
|
||||
|
||||
return {
|
||||
sectionPosition: currentStep.section,
|
||||
totalInSection: sectionSteps.length,
|
||||
@@ -130,7 +124,7 @@ const Onboarding: React.FC = () => {
|
||||
|
||||
const renderStepContent = () => {
|
||||
if (!currentStep) return null;
|
||||
|
||||
|
||||
const sectionInfo = getSectionInfo();
|
||||
|
||||
switch (currentStep.type) {
|
||||
@@ -160,18 +154,18 @@ const Onboarding: React.FC = () => {
|
||||
);
|
||||
|
||||
case 'question':
|
||||
const questionValue = currentStep.fieldMapping
|
||||
? String(formData[currentStep.fieldMapping as keyof OnboardingData] || '')
|
||||
const questionValue = currentStep.field
|
||||
? String(formData[currentStep.field as keyof OnboardingData] || '')
|
||||
: '';
|
||||
|
||||
|
||||
return (
|
||||
<FigmaOnboardingQuestion
|
||||
question={currentStep.question || ''}
|
||||
question={currentStep.title || ''}
|
||||
placeholder={currentStep.placeholder}
|
||||
value={questionValue}
|
||||
onChange={(value) => {
|
||||
if (currentStep.fieldMapping) {
|
||||
updateFormData(currentStep.fieldMapping as keyof OnboardingData, value);
|
||||
if (currentStep.field) {
|
||||
updateFormData(currentStep.field as keyof OnboardingData, value);
|
||||
}
|
||||
}}
|
||||
onBack={handleBack}
|
||||
@@ -180,24 +174,24 @@ const Onboarding: React.FC = () => {
|
||||
totalInSection={sectionInfo.totalInSection}
|
||||
sectionName={sectionInfo.sectionName}
|
||||
canProceed={canProceed()}
|
||||
canSkip={currentStep.optional}
|
||||
canSkip={!currentStep.required}
|
||||
rows={6}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'multiple_choice':
|
||||
const multipleChoiceValue = currentStep.fieldMapping
|
||||
? String(formData[currentStep.fieldMapping as keyof OnboardingData] || '')
|
||||
const multipleChoiceValue = currentStep.field
|
||||
? String(formData[currentStep.field as keyof OnboardingData] || '')
|
||||
: '';
|
||||
|
||||
|
||||
return (
|
||||
<FigmaOnboardingMultipleChoice
|
||||
question={currentStep.question || ''}
|
||||
question={currentStep.title || ''}
|
||||
options={currentStep.options || []}
|
||||
selectedValue={multipleChoiceValue}
|
||||
onSelect={(value) => {
|
||||
if (currentStep.fieldMapping) {
|
||||
updateFormData(currentStep.fieldMapping as keyof OnboardingData, value);
|
||||
if (currentStep.field) {
|
||||
updateFormData(currentStep.field as keyof OnboardingData, value);
|
||||
}
|
||||
}}
|
||||
onBack={handleBack}
|
||||
@@ -205,7 +199,7 @@ const Onboarding: React.FC = () => {
|
||||
sectionPosition={sectionInfo.sectionPosition}
|
||||
totalInSection={sectionInfo.totalInSection}
|
||||
sectionName={sectionInfo.sectionName}
|
||||
canSkip={currentStep.optional}
|
||||
canSkip={!currentStep.required}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user