Rework step logic so deep links work
This commit is contained in:
parent
fbe0bd98c7
commit
89bcc1cb55
@ -103,10 +103,27 @@ const JobAnalysisPage: React.FC<BackstoryPageProps> = () => {
|
|||||||
const maxStep = 4;
|
const maxStep = 4;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (jobId && candidateId && stepId && activeStep !== parseFloat(stepId)) {
|
if (
|
||||||
setActiveStep(parseFloat(stepId));
|
jobId !== selectedJob?.id ||
|
||||||
|
candidateId !== selectedCandidate?.id ||
|
||||||
|
parseFloat(stepId || '0') !== activeStep
|
||||||
|
) {
|
||||||
|
if (!selectedCandidate) {
|
||||||
|
navigate('/job-analysis/');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [jobId, candidateId, activeStep, stepId]);
|
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, selectedJob, selectedCandidate, stepId, activeStep]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let routeCandidateId = candidateId || '';
|
let routeCandidateId = candidateId || '';
|
||||||
@ -150,11 +167,6 @@ const JobAnalysisPage: React.FC<BackstoryPageProps> = () => {
|
|||||||
} else {
|
} else {
|
||||||
routeJobId = selectedJob?.id || '';
|
routeJobId = selectedJob?.id || '';
|
||||||
}
|
}
|
||||||
if (routeCandidateId && routeJobId) {
|
|
||||||
navigate(`/job-analysis/${routeCandidateId}/${routeJobId}${routeStepId}`, {
|
|
||||||
replace: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [candidateId, jobId, setSelectedCandidate, setSelectedJob]);
|
}, [candidateId, jobId, setSelectedCandidate, setSelectedJob]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -244,16 +256,11 @@ const JobAnalysisPage: React.FC<BackstoryPageProps> = () => {
|
|||||||
if (activeStep === maxStep) {
|
if (activeStep === maxStep) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let nextStep = activeStep;
|
const nextStep = activeStep + 1;
|
||||||
for (let i = activeStep + 1; i < maxStep; i++) {
|
if (getMissingStepRequirement(nextStep)) {
|
||||||
if (getMissingStepRequirement(i)) {
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
nextStep = i;
|
|
||||||
}
|
|
||||||
if (nextStep !== activeStep) {
|
|
||||||
setActiveStep(nextStep);
|
setActiveStep(nextStep);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBack = (): void => {
|
const handleBack = (): void => {
|
||||||
@ -271,12 +278,6 @@ const JobAnalysisPage: React.FC<BackstoryPageProps> = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setActiveStep(step);
|
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 => {
|
const onCandidateSelect = (candidate: Candidate): void => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user