From cf42fe43f0908e7ba0a0004df507e68f259629a0 Mon Sep 17 00:00:00 2001 From: lucieo Date: Fri, 23 Feb 2024 10:52:58 +0100 Subject: [PATCH] Fix scroll tableau + Comapgnie Admind Listing candidatures fix --- .../Company/ApplicationCompanyList.tsx | 5 +- .../ApplicationCompanyHelper.tsx | 25 ++++++---- .../ApplicationsHelpers/FullApplications.tsx | 36 +++++++++++++++ .../ApplicationsHelpers/OpenApplications.tsx | 2 + .../Account/Application/ConfirmButton.tsx | 2 +- .../Place/ApplicationPlaceList.tsx | 1 + web/components/Campaign/CampaignProvider.tsx | 46 ++++++++++++------- web/pages/compte/mes-candidatures/index.tsx | 14 +++++- web/public/locales/fr/application.json | 7 ++- 9 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 web/components/Account/Application/Company/ApplicationsHelpers/FullApplications.tsx diff --git a/web/components/Account/Application/Company/ApplicationCompanyList.tsx b/web/components/Account/Application/Company/ApplicationCompanyList.tsx index dbad50d6..b7b983cd 100644 --- a/web/components/Account/Application/Company/ApplicationCompanyList.tsx +++ b/web/components/Account/Application/Company/ApplicationCompanyList.tsx @@ -58,7 +58,10 @@ const ApplicationCompanyList = ({ applications = [] }: Props) => { {t('company.title', { title: currentCampaign?.title })} - + {t('company.table.head.number')} diff --git a/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx b/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx index 11fa2644..153f9e37 100644 --- a/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx +++ b/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx @@ -1,21 +1,30 @@ -import { Box, Button, Stack, Text } from '@chakra-ui/react' -import { useTranslation } from 'next-i18next' import useCampaignContext from '~components/Campaign/useCampaignContext' -import { ROUTE_PLACES } from '~constants' import { useCurrentUser } from '~hooks/useCurrentUser' -import { format } from '~utils/date' -import Link from '~components/Link' import OpenApplications from '~components/Account/Application/Company/ApplicationsHelpers/OpenApplications' import ClosedApplications from '~components/Account/Application/Company/ApplicationsHelpers/ClosedApplications' +import { getEndDateTime } from '~components/Campaign/CampaignProvider' +import FullApplications from '~components/Account/Application/Company/ApplicationsHelpers/FullApplications' const ApplicationCompanyHelper = () => { - const { remainingApplications } = useCurrentUser() + const { remainingApplications, applications } = useCurrentUser() const { currentCampaign } = useCampaignContext() - const { t } = useTranslation('application') + const today = new Date() + + if ( + applications.length > 0 && + !remainingApplications && + currentCampaign.mode === 'applications' + ) { + return + } + if (remainingApplications > 0 && currentCampaign.mode === 'applications') return - if (currentCampaign.mode === 'preselections') { + if ( + today <= getEndDateTime(currentCampaign.preselection_end) && + today >= getEndDateTime(currentCampaign.application_end) + ) { return } return null diff --git a/web/components/Account/Application/Company/ApplicationsHelpers/FullApplications.tsx b/web/components/Account/Application/Company/ApplicationsHelpers/FullApplications.tsx new file mode 100644 index 00000000..ebc361cc --- /dev/null +++ b/web/components/Account/Application/Company/ApplicationsHelpers/FullApplications.tsx @@ -0,0 +1,36 @@ +import { Box, Stack, Text } from '@chakra-ui/react' +import { useTranslation } from 'next-i18next' +import useCampaignContext from '~components/Campaign/useCampaignContext' +import { format } from '~utils/date' + +const FullApplications = ({ numApplications }: { numApplications: number }) => { + const { currentCampaign } = useCampaignContext() + const { t } = useTranslation('application') + + return ( + + + + + {t(`company.helper.full_start${numApplications > 1 ? 's' : ''}`)} + + + {t('company.helper.full_end', { + date: format(currentCampaign.preselection_end), + })} + + + + + ) +} + +export default FullApplications diff --git a/web/components/Account/Application/Company/ApplicationsHelpers/OpenApplications.tsx b/web/components/Account/Application/Company/ApplicationsHelpers/OpenApplications.tsx index eaec0175..a9009232 100644 --- a/web/components/Account/Application/Company/ApplicationsHelpers/OpenApplications.tsx +++ b/web/components/Account/Application/Company/ApplicationsHelpers/OpenApplications.tsx @@ -43,6 +43,8 @@ const OpenApplications = ({ size="lg" whiteSpace={'break-spaces'} textAlign="center" + p={4} + height="auto" > {t('company.helper.cta')} diff --git a/web/components/Account/Application/ConfirmButton.tsx b/web/components/Account/Application/ConfirmButton.tsx index bed21b3d..4e08bbf5 100644 --- a/web/components/Account/Application/ConfirmButton.tsx +++ b/web/components/Account/Application/ConfirmButton.tsx @@ -27,7 +27,7 @@ const ConfirmButton = ({ const { isOpen, onClose, onToggle } = useDisclosure() return ( - + {children} diff --git a/web/components/Account/Application/Place/ApplicationPlaceList.tsx b/web/components/Account/Application/Place/ApplicationPlaceList.tsx index f3461520..633dc7b5 100644 --- a/web/components/Account/Application/Place/ApplicationPlaceList.tsx +++ b/web/components/Account/Application/Place/ApplicationPlaceList.tsx @@ -48,6 +48,7 @@ const ApplicationPlaceList = ({ applications = [] }: Props) => { ? 'minmax(auto, auto)' : '' }`} + overflowX="auto" > {t('place.table.head.number')} diff --git a/web/components/Campaign/CampaignProvider.tsx b/web/components/Campaign/CampaignProvider.tsx index 9416c531..f1cbad1c 100644 --- a/web/components/Campaign/CampaignProvider.tsx +++ b/web/components/Campaign/CampaignProvider.tsx @@ -9,6 +9,20 @@ interface ICampaignProvider { children: React.ReactNode } +export const getStartDateTime = (date) => { + const newDate = new Date(date) + newDate.setHours(0) + newDate.setMinutes(1) + return newDate +} + +export const getEndDateTime = (date) => { + const newDate = new Date(date) + newDate.setHours(23) + newDate.setMinutes(59) + return newDate +} + const CampaignProvider = ({ children }: ICampaignProvider) => { const today = new Date() const { data: user } = useCurrentUser() @@ -40,21 +54,21 @@ const CampaignProvider = ({ children }: ICampaignProvider) => { const getCampaignMode = (campaign) => { if ( - today >= new Date(campaign.disponibility_start) && - today <= new Date(campaign.disponibility_end) + today >= getStartDateTime(campaign.disponibility_start) && + today <= getEndDateTime(campaign.disponibility_end) ) { return 'disponibilities' } else if ( - today >= new Date(campaign.application_start) && - today <= new Date(campaign.application_end) + today >= getStartDateTime(campaign.application_start) && + today <= getEndDateTime(campaign.application_end) ) { return 'applications' } else if ( - today >= new Date(campaign.preselection_start) && - today <= new Date(campaign.preselection_end) + today >= getStartDateTime(campaign.preselection_start) && + today <= getEndDateTime(campaign.preselection_end) ) { return 'preselections' - } else if (today >= new Date(campaign.preselection_end)) { + } else if (today >= getEndDateTime(campaign.preselection_end)) { return 'closed' } return null @@ -106,15 +120,15 @@ const CampaignProvider = ({ children }: ICampaignProvider) => { (currentCampaign?.mode === 'disponibilities' && isCampaignPlace) || currentCampaign?.mode === 'applications' - console.log( - activeCampaigns, - currentCampaign, - isCampaignPlace, - hasActiveCampaign, - isLoading, - allPlaceCampaigns, - isLoadingAllPlaceCampaigns, - ) + // console.log( + // activeCampaigns, + // currentCampaign, + // isCampaignPlace, + // hasActiveCampaign, + // isLoading, + // allPlaceCampaigns, + // isLoadingAllPlaceCampaigns, + // ) return ( { + const router = useRouter() const { t } = useTranslation('account') - const { currentCampaign } = useCampaignContext() + const { currentCampaign, isLoading: isLoadingCampaign } = useCampaignContext() const { data: applications, isLoading } = useMyApplications({ campaignId: currentCampaign?.id, options: { enabled: !!currentCampaign?.id }, @@ -27,6 +30,13 @@ const CompanyApplications = ({ user }: Props) => { 'disponibility.campaign': currentCampaign?.id, }, }) + + useEffect(() => { + if (!currentCampaign && !isLoadingCampaign) { + router.push(ROUTE_ACCOUNT) + } + }, [currentCampaign]) + if (!currentCampaign) return null return ( diff --git a/web/public/locales/fr/application.json b/web/public/locales/fr/application.json index 95bd3074..a8d2a58f 100644 --- a/web/public/locales/fr/application.json +++ b/web/public/locales/fr/application.json @@ -18,8 +18,11 @@ "starts": "Il est encore possible de déposer {{num}} candidatures,", "end": " avant le {{date}}.", "cta": "Voir les espaces partenaires", - "closed_start": "Le créneau de candidatures pour le dispositif {{title}} est maintenant clôturé,", - "closed_end": "la décision de chaque lieu sera connue d’ici au {{date}}. En cas de sélection, le lieu prendra contact directement avec vous hors de cette plateforme." + "closed_start": "La période de candidature au dispositif {{title}} est maintenant clôturée.", + "closed_end": "La décision de chaque lieu sera connue d’ici au {{date}}. En cas de sélection, le lieu prendra contact directement avec vous hors de cette plateforme.", + "full_start": "Votre candidature est déposée pour le dispositif {{title}}.", + "full_starts": "Vos candidatures sont déposées pour le dispositif {{title}}.", + "full_end": "La décision de chaque lieu sera connue d’ici au {{date}}. En cas de sélection, le lieu prendra contact directement avec vous par email. Merci pour votre participation." }, "delete_error": "Une erreur est survenue lors de la suppression de votre candidature", "delete_success": "Votre candidature a bien été supprimée"