Skip to content

Commit

Permalink
feat: redirect if only 1 active recruitmetn
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Dec 9, 2024
1 parent c5a9ca8 commit 26d2bf2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions frontend/src/Pages/RecruitmentPage/RecruitmentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { useTranslation } from 'react-i18next';
import { Page, SamfundetLogoSpinner } from '~/Components';
import { getActiveRecruitments } from '~/api';
import type { RecruitmentDto } from '~/dto';
import { useTitle } from '~/hooks';
import { useCustomNavigate, useTitle } from '~/hooks';
import { KEY } from '~/i18n/constants';
import { reverse } from '~/named-urls';
import { ROUTES } from '~/routes';
import { dbT, getObjectFieldOrNumber } from '~/utils';
import { NoPositions, RecruitmentCard } from './Components';
import styles from './RecruitmentPage.module.scss';

export function RecruitmentPage() {
const navigate = useCustomNavigate();
const [recruitments, setRecruitments] = useState<RecruitmentDto[]>([]);
const [loading, setLoading] = useState(true);
const { t } = useTranslation();
Expand All @@ -18,13 +21,24 @@ export function RecruitmentPage() {
useEffect(() => {
getActiveRecruitments()
.then((response) => {
setRecruitments(response.data);
if (response.data.length === 1) {
navigate({
url: reverse({
pattern: ROUTES.frontend.organization_recruitment,
urlParams: { recruitmentId: (response.data[0] as RecruitmentDto).id },
}),
replace: true,
});
} else {
setRecruitments(response.data);
setLoading(false);
}
})
.catch((error) => {
console.log('Error fetching data:', error);
setLoading(false);
});
setLoading(false);
}, []);
}, [navigate]);

return (
<Page>
Expand Down

0 comments on commit 26d2bf2

Please sign in to comment.