diff --git a/back/extensions/documentation/documentation/1.0.0/full_documentation.json b/back/extensions/documentation/documentation/1.0.0/full_documentation.json index 426a7745..ca352846 100644 --- a/back/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/back/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "02/22/2024 8:24:57 PM" + "x-generation-date": "02/23/2024 1:16:02 PM" }, "x-strapi-config": { "path": "/documentation", diff --git a/web/components/Account/Place/ListItem/CampaignDisponibilitiesInfo.tsx b/web/components/Account/Place/ListItem/CampaignDisponibilitiesInfo.tsx index 0be44c04..d0e6021d 100644 --- a/web/components/Account/Place/ListItem/CampaignDisponibilitiesInfo.tsx +++ b/web/components/Account/Place/ListItem/CampaignDisponibilitiesInfo.tsx @@ -5,14 +5,12 @@ import { Espace } from '~typings/api' import { format } from '~utils/date' import { ROUTE_ACCOUNT_PLACE_DETAIL } from '~constants' import Link from '~components/Link' +import useCampaignDispo from '~hooks/useCampaignDispo' const CampaignDisponibilitiesInfo = ({ place }: { place: Espace }) => { const { t } = useTranslation('place') const { currentCampaign } = useCampaignContext() - const campaignDispo = place?.disponibilities?.filter( - //@ts-expect-error - (d) => d.campaign === currentCampaign?.id, - )?.length + const { campaignDisposNum } = useCampaignDispo(place?.disponibilities) return ( @@ -52,7 +50,7 @@ const CampaignDisponibilitiesInfo = ({ place }: { place: Espace }) => { {`${t(`list.slots_filled`, { - nb: campaignDispo, + nb: campaignDisposNum, nbTotal: currentCampaign?.disponibilities_max, })}`} diff --git a/web/components/Account/Place/ListItem/PlaceListItem.tsx b/web/components/Account/Place/ListItem/PlaceListItem.tsx index f736bac0..ff7cdef9 100644 --- a/web/components/Account/Place/ListItem/PlaceListItem.tsx +++ b/web/components/Account/Place/ListItem/PlaceListItem.tsx @@ -12,6 +12,7 @@ import PlaceListItemInfo from '~components/Account/Place/ListItem/PlaceListItemI import PlaceListItemImage from '~components/Account/Place/ListItem/PlaceListItemImage' import CampaignDisponibilitiesInfo from '~components/Account/Place/ListItem/CampaignDisponibilitiesInfo' import useCampaignContext from '~components/Campaign/useCampaignContext' +import useCampaignDispo from '~hooks/useCampaignDispo' interface Props { place: Espace @@ -29,12 +30,10 @@ const PlaceListItem = ({ place, setVisible, isFirst }: Props) => { } }, [isComplete]) + const { campaignDisposNum } = useCampaignDispo(place?.disponibilities) + console.log(campaignDisposNum, currentCampaign) const showCampaignDisponibilities = - currentCampaign?.mode === 'disponibilities' || - (place?.disponibilities && - place?.disponibilities?.some( - (d) => d?.campaign?.toString() === currentCampaign?.id.toString(), - )) + currentCampaign?.mode === 'disponibilities' || campaignDisposNum return ( { return ( @@ -49,13 +50,7 @@ const PlaceTabList = ({ ).length }, [place?.disponibilities]) - const campaignDispo = useMemo(() => { - if (!place || !place.disponibilities) return 0 - return place.disponibilities.filter( - //@ts-expect-error - (dispo) => dispo.campaign === currentCampaign?.id, - ).length - }, [place]) + const { campaignDisposNum } = useCampaignDispo(place.disponibilities) return ( { const { t } = useTranslation('place') const { currentCampaign } = useCampaignContext() - const campaignDispo = place?.disponibilities?.filter( - //@ts-expect-error - (d) => d.campaign === currentCampaign?.id, + const { campaignDisposNum, campaignDispos } = useCampaignDispo( + place?.disponibilities, ) + const isMobile = useBreakpointValue({ base: true, sm: false }) const { eventsIdToDelete } = useContext(ScheduleContext) @@ -51,8 +52,8 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => { {currentCampaign?.mode === 'disponibilities' - ? `${campaignDispo?.length}/${currentCampaign?.disponibilities_max}` - : campaignDispo?.length} + ? `${campaignDisposNum}/${currentCampaign?.disponibilities_max}` + : campaignDisposNum} {currentCampaign?.mode === 'disponibilities' @@ -62,7 +63,7 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => { ) : t( `campaign.helpers.applications.schedule.${ - campaignDispo?.length <= 1 + campaignDisposNum <= 1 ? 'open_applications_one' : 'open_applications_many' }`, @@ -76,12 +77,13 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => { mt={6} onClick={showForm} disabled={ - campaignDispo?.length === currentCampaign?.disponibilities_max + currentCampaign && + campaignDisposNum === currentCampaign?.disponibilities_max } > {isMobile ? t(`list.add`) : t(`schedule.add`)} - ) : campaignDispo?.length > 0 ? ( + ) : campaignDisposNum > 0 ? ( diff --git a/web/components/Campaign/Places/Detail/CampaignPlaceDetail.tsx b/web/components/Campaign/Places/Detail/CampaignPlaceDetail.tsx index 68812937..b19710bf 100644 --- a/web/components/Campaign/Places/Detail/CampaignPlaceDetail.tsx +++ b/web/components/Campaign/Places/Detail/CampaignPlaceDetail.tsx @@ -19,7 +19,7 @@ import { useRouter } from 'next/router' import CampaignApplicationSchedule from '~components/Campaign/Places/Application/CampaignApplicationSchedule' import PlaceDetailCalendar from '~components/Place/PlaceDetailPage/PlaceDetailCalendar' import CampaignDetailSwitcher from '~components/Campaign/Places/Detail/CampaignDetailSwitcher' -import useCampaignContext from '~components/Campaign/useCampaignContext' +import useCampaignDispo from '~hooks/useCampaignDispo' interface Props { place: Espace @@ -29,7 +29,6 @@ const CampaignPlaceDetail = ({ place }: Props) => { const isMobile = useBreakpointValue({ base: true, lg: false }) const router = useRouter() const isCampaignTab = router.query.tab === '1' - const { currentCampaign } = useCampaignContext() const displayPrecise = useMemo(() => { if (!place) return false @@ -40,6 +39,8 @@ const CampaignPlaceDetail = ({ place }: Props) => { ) }, [place]) + const { campaignDispos } = useCampaignDispo(place?.disponibilities) + return ( @@ -69,11 +70,7 @@ const CampaignPlaceDetail = ({ place }: Props) => { {isCampaignTab ? ( - d?.campaign?.toString() === currentCampaign?.id.toString(), - )} - /> + ) : ( )} diff --git a/web/components/Place/PlaceGridCard.tsx b/web/components/Place/PlaceGridCard.tsx index af3298c0..d3593a2e 100644 --- a/web/components/Place/PlaceGridCard.tsx +++ b/web/components/Place/PlaceGridCard.tsx @@ -22,6 +22,7 @@ import addWeeks from 'date-fns/addWeeks' import useCampaignContext from '~components/Campaign/useCampaignContext' import { format } from '~utils/date' import CampaignTag from '~components/Campaign/CampaignTag' +import useCampaignDispo from '~hooks/useCampaignDispo' interface Props { place: Espace @@ -48,12 +49,9 @@ const PlaceGridCard = ({ place, searchParams, isCampaignTab }: Props) => { disposInRange || place?.disponibilities, ) + const { campaignDispos } = useCampaignDispo(place?.disponibilities) const hasCampaignDispo = - currentCampaign?.mode === 'applications' && - place?.disponibilities?.some( - //@ts-expect-error - (d) => d?.campaign === currentCampaign?.id, - ) + currentCampaign?.mode === 'applications' && !!campaignDispos?.length return ( diff --git a/web/hooks/useCampaignDispo.tsx b/web/hooks/useCampaignDispo.tsx new file mode 100644 index 00000000..8366db86 --- /dev/null +++ b/web/hooks/useCampaignDispo.tsx @@ -0,0 +1,24 @@ +import { useMemo } from 'react' +import useCampaignContext from '~components/Campaign/useCampaignContext' +import { Disponibility } from '~typings/api' + +const useCampaignDispo = (disponibilities?: Disponibility[]) => { + const { currentCampaign } = useCampaignContext() + + const campaignDispos = useMemo( + () => + disponibilities?.filter( + (d) => + currentCampaign && + d?.campaign?.toString() === currentCampaign?.id?.toString(), + ), + [disponibilities, currentCampaign], + ) + + return { + campaignDispos, + campaignDisposNum: campaignDispos?.length, + } +} + +export default useCampaignDispo diff --git a/web/hooks/useCurrentUser.tsx b/web/hooks/useCurrentUser.tsx index 6f60490b..de088863 100644 --- a/web/hooks/useCurrentUser.tsx +++ b/web/hooks/useCurrentUser.tsx @@ -20,7 +20,8 @@ export const useCurrentUser = () => { if (userData && currentCampaign) { //@ts-expect-error return userData?.data?.companyApplications?.filter( - (application) => application?.campaign === currentCampaign?.id, + (application) => + currentCampaign && application?.campaign === currentCampaign?.id, ) } }, [userData?.data, currentCampaign]) diff --git a/web/hooks/useSelectedCampaign.tsx b/web/hooks/useSelectedCampaign.tsx index dcc44d62..91533b5d 100644 --- a/web/hooks/useSelectedCampaign.tsx +++ b/web/hooks/useSelectedCampaign.tsx @@ -5,7 +5,7 @@ const useSelectedCampaign = () => { const { allPlaceCampaigns } = useCampaignContext() const { query } = useRouter() const selectedCampaign = allPlaceCampaigns?.find( - (c) => c.id.toString() === query.campaign.toString(), + (c) => c?.id?.toString() === query?.campaign?.toString(), ) return { selectedCampaign } diff --git a/web/pages/compte/candidatures/index.tsx b/web/pages/compte/candidatures/index.tsx index d8e90c33..7aca50ca 100644 --- a/web/pages/compte/candidatures/index.tsx +++ b/web/pages/compte/candidatures/index.tsx @@ -16,25 +16,24 @@ const PlaceApplications = () => { const { t: tAccount } = useTranslation('account') const { selectedCampaign } = useSelectedCampaign() - if (selectedCampaign) - return ( - <> - - {selectedCampaign?.mode === 'applications' && ( - - - - )} - - - - - ) + return ( + <> + + {selectedCampaign?.mode === 'applications' && ( + + + + )} + + + + + ) return null }