diff --git a/frontend/src/pages/JobAnalysisPage.tsx b/frontend/src/pages/JobAnalysisPage.tsx index 49f83aa..0263916 100644 --- a/frontend/src/pages/JobAnalysisPage.tsx +++ b/frontend/src/pages/JobAnalysisPage.tsx @@ -103,10 +103,27 @@ const JobAnalysisPage: React.FC = () => { const maxStep = 4; useEffect(() => { - if (jobId && candidateId && stepId && activeStep !== parseFloat(stepId)) { - setActiveStep(parseFloat(stepId)); + if ( + jobId !== selectedJob?.id || + candidateId !== selectedCandidate?.id || + parseFloat(stepId || '0') !== activeStep + ) { + if (!selectedCandidate) { + navigate('/job-analysis/'); + return; + } + if (!selectedJob) { + navigate(`/job-analysis/${selectedCandidate.id}`, { replace: true }); + return; + } + if (selectedCandidate && selectedJob) { + const routeStep = activeStep ? `/${activeStep.toString()}` : ''; + navigate(`/job-analysis/${selectedCandidate.id}/${selectedJob.id}${routeStep}`, { + replace: true, + }); + } } - }, [jobId, candidateId, activeStep, stepId]); + }, [jobId, candidateId, selectedJob, selectedCandidate, stepId, activeStep]); useEffect(() => { let routeCandidateId = candidateId || ''; @@ -150,11 +167,6 @@ const JobAnalysisPage: React.FC = () => { } else { routeJobId = selectedJob?.id || ''; } - if (routeCandidateId && routeJobId) { - navigate(`/job-analysis/${routeCandidateId}/${routeJobId}${routeStepId}`, { - replace: true, - }); - } }, [candidateId, jobId, setSelectedCandidate, setSelectedJob]); useEffect(() => { @@ -244,16 +256,11 @@ const JobAnalysisPage: React.FC = () => { if (activeStep === maxStep) { return; } - let nextStep = activeStep; - for (let i = activeStep + 1; i < maxStep; i++) { - if (getMissingStepRequirement(i)) { - break; - } - nextStep = i; - } - if (nextStep !== activeStep) { - setActiveStep(nextStep); + const nextStep = activeStep + 1; + if (getMissingStepRequirement(nextStep)) { + return; } + setActiveStep(nextStep); }; const handleBack = (): void => { @@ -271,12 +278,6 @@ const JobAnalysisPage: React.FC = () => { return; } setActiveStep(step); - if (selectedCandidate?.id && selectedJob?.id) { - const routeStep = step ? `/${step.toString()}` : ''; - navigate(`/job-analysis/${selectedCandidate.id}/${selectedJob.id}${routeStep}`, { - replace: true, - }); - } }; const onCandidateSelect = (candidate: Candidate): void => {