From b2b2cd60a8d3763b4e4bbfd9f42b33ffa66b2915 Mon Sep 17 00:00:00 2001 From: magsyg Date: Fri, 6 Dec 2024 15:39:20 +0100 Subject: [PATCH 1/4] remove unecessary extra calls to organization --- .../OrganizationRecruitmentPage.tsx | 53 ++++++++++--------- .../Components/PersonalRow/PersonalRow.tsx | 2 +- .../RecruitmentCard/RecruitmentCard.tsx | 39 ++++---------- .../Pages/RecruitmentPage/RecruitmentPage.tsx | 5 +- .../RecruitmentFormAdminPage.tsx | 6 +-- frontend/src/api.ts | 5 +- frontend/src/dto.ts | 6 ++- 7 files changed, 52 insertions(+), 64 deletions(-) diff --git a/frontend/src/Pages/OrganizationRecruitmentPage/OrganizationRecruitmentPage.tsx b/frontend/src/Pages/OrganizationRecruitmentPage/OrganizationRecruitmentPage.tsx index f567826df..6413c9e83 100644 --- a/frontend/src/Pages/OrganizationRecruitmentPage/OrganizationRecruitmentPage.tsx +++ b/frontend/src/Pages/OrganizationRecruitmentPage/OrganizationRecruitmentPage.tsx @@ -4,18 +4,33 @@ import { useTranslation } from 'react-i18next'; import { useParams } from 'react-router-dom'; import { Button, Logo, OccupiedFormModal, Page, SamfundetLogoSpinner, Text, Video } from '~/Components'; import { PersonalRow } from '~/Pages/RecruitmentPage'; -import { getOrganization, getRecruitment } from '~/api'; +import { getRecruitment } from '~/api'; import { useOrganizationContext } from '~/context/OrgContextProvider'; import type { RecruitmentDto } from '~/dto'; import { useDesktop, useTitle } from '~/hooks'; import { KEY } from '~/i18n/constants'; import { OrgNameType, type OrgNameTypeValue } from '~/types'; -import { dbT, getObjectFieldOrNumber } from '~/utils'; +import { dbT } from '~/utils'; import { GangSeparatePositions, GangTypeContainer, RecruitmentTabs } from './Components'; import styles from './OrganizationRecruitmentPage.module.scss'; type ViewMode = 'list' | 'tab'; +const ORG_STYLES = { + [OrgNameType.SAMFUNDET_NAME]: { + subHeaderStyle: styles.samfRecruitmentSubHeader, + }, + [OrgNameType.UKA_NAME]: { + subHeaderStyle: styles.ukaRecruitmentSubHeader, + }, + [OrgNameType.ISFIT_NAME]: { + subHeaderStyle: styles.isfitRecruitmentSubHeader, + }, + [OrgNameType.FALLBACK]: { + subHeaderStyle: '', + }, +}; + export function OrganizationRecruitmentPage() { const isDesktop = useDesktop(); const { recruitmentId } = useParams<{ recruitmentId: string }>(); @@ -23,7 +38,6 @@ export function OrganizationRecruitmentPage() { const { t } = useTranslation(); const { changeOrgTheme, organizationTheme } = useOrganizationContext(); const [recruitment, setRecruitment] = useState(); - const [organizationName, setOrganizationName] = useState(OrgNameType.FALLBACK); const [loading, setLoading] = useState(true); const [positionsViewMode, setViewMode] = useState('list'); @@ -43,25 +57,10 @@ export function OrganizationRecruitmentPage() { useEffect(() => { if (recruitment) { - getOrganization(getObjectFieldOrNumber(recruitment.organization, 'id')) - .then((response) => { - if (Object.values(OrgNameType).includes(response.name as OrgNameTypeValue)) { - setOrganizationName(response.name as OrgNameTypeValue); - } - }) - .catch((error) => { - console.log(error); - setOrganizationName(OrgNameType.FALLBACK); - }); + changeOrgTheme(recruitment.organization.name as OrgNameTypeValue); } setLoading(false); - }, [recruitment]); - - useEffect(() => { - if (organizationName) { - changeOrgTheme(organizationName); - } - }, [organizationName, changeOrgTheme]); + }, [recruitment, changeOrgTheme]); function toggleViewAll() { const toggledValue = !viewAllPositions; @@ -75,7 +74,11 @@ export function OrganizationRecruitmentPage() { ) : (
- + {dbT(recruitment, 'name')} @@ -83,14 +86,12 @@ export function OrganizationRecruitmentPage() { {recruitment?.promo_media &&