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;
|
||||
|
||||
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<BackstoryPageProps> = () => {
|
||||
} 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<BackstoryPageProps> = () => {
|
||||
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<BackstoryPageProps> = () => {
|
||||
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 => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user