From 02016a7f0926e3085c259ebe3f9acc927438b7e1 Mon Sep 17 00:00:00 2001 From: lucieo Date: Fri, 1 Mar 2024 12:05:38 +0100 Subject: [PATCH] Fixes and campaign update before lifecycle --- back/api/application/models/application.js | 2 +- back/api/campaign/models/campaign.js | 17 +++++++++++++++-- back/api/campaign/services/campaign.js | 8 ++++---- back/config/functions/bootstrap.js | 2 +- .../1.0.0/full_documentation.json | 2 +- .../ApplicationsHelpers/ConfirmSelections.tsx | 2 +- .../{PlaceList.tsx => AdminPlaceList.tsx} | 9 +++++---- ...laceListItem.tsx => AdminPlaceListItem.tsx} | 5 +++-- web/components/Campaign/CampaignProvider.tsx | 3 +-- web/components/Place/PlaceGridCard.tsx | 18 ++++++++++-------- web/pages/compte/espaces/index.tsx | 4 ++-- 11 files changed, 44 insertions(+), 28 deletions(-) rename web/components/Account/Place/{PlaceList.tsx => AdminPlaceList.tsx} (88%) rename web/components/Account/Place/ListItem/{PlaceListItem.tsx => AdminPlaceListItem.tsx} (96%) diff --git a/back/api/application/models/application.js b/back/api/application/models/application.js index 86513c0e..e8f75f08 100644 --- a/back/api/application/models/application.js +++ b/back/api/application/models/application.js @@ -55,7 +55,7 @@ module.exports = { user_name: created.company.firstname, applications_end_date: format( new Date(campaign.application_end), - 'dd/MM', + 'dd MMMM yyyy', locale, ), nb_applications, diff --git a/back/api/campaign/models/campaign.js b/back/api/campaign/models/campaign.js index 0054d33c..15670351 100644 --- a/back/api/campaign/models/campaign.js +++ b/back/api/campaign/models/campaign.js @@ -1,8 +1,21 @@ -'use strict'; +'use strict' /** * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) * to customize this model */ -module.exports = {}; +module.exports = { + lifecycles: { + beforeUpdate: async (params, data) => { + // Campaign has a relationship with applications and disponibilities but shouldn't update those to avoid data loss on admin update + const currentCampaignState = await strapi.services.campaign.findOne( + params, + ) + if (currentCampaignState) { + data.applications = currentCampaignState.applications + data.disponibilities = currentCampaignState.disponibilities + } + }, + }, +} diff --git a/back/api/campaign/services/campaign.js b/back/api/campaign/services/campaign.js index 336d076b..21a03882 100644 --- a/back/api/campaign/services/campaign.js +++ b/back/api/campaign/services/campaign.js @@ -24,11 +24,11 @@ module.exports = { }, { date_end: format( - new Date(campaign.application_end), + new Date(campaign.preselection_end), 'dd/MM/yyyy', locale, ), - url_btn: `${process.env.FRONT_URL}/compte/candidatures/campaign=${campaign.id}`, + url_btn: `${process.env.FRONT_URL}/compte/candidatures?campaign=${campaign.id}`, }, ) }, @@ -53,7 +53,7 @@ module.exports = { reminder_days: `${campaign?.reminder_days} ${ campaign?.reminder_days > 1 ? 'jours' : 'jour' }`, - url_btn: `${process.env.FRONT_URL}/compte/candidatures/campaign=${campaign.id}`, + url_btn: `${process.env.FRONT_URL}/compte/candidatures?campaign=${campaign.id}`, }, ) } @@ -71,7 +71,7 @@ module.exports = { }, { templateId: 'place-preselections-end', - subject: `La période de candidature est terminée`, + subject: `La date limite de pré-sélection a été atteinte`, }, { missing_selections: place_missing_selections, diff --git a/back/config/functions/bootstrap.js b/back/config/functions/bootstrap.js index 712b57b3..025d4ba9 100644 --- a/back/config/functions/bootstrap.js +++ b/back/config/functions/bootstrap.js @@ -29,7 +29,7 @@ module.exports = () => { } // Every night check for campaigns emails to send - cron.schedule(cronSchedule, async () => { + cron.schedule(testCron, async () => { const activeCampaigns = await strapi.services.campaign.find({ is_active: true, }) 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 b5d57359..31c49aa6 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": "03/01/2024 10:45:51 AM" + "x-generation-date": "03/01/2024 11:49:42 AM" }, "x-strapi-config": { "path": "/documentation", diff --git a/web/components/Account/Application/Place/ApplicationsHelpers/ConfirmSelections.tsx b/web/components/Account/Application/Place/ApplicationsHelpers/ConfirmSelections.tsx index 784cc48a..61a30250 100644 --- a/web/components/Account/Application/Place/ApplicationsHelpers/ConfirmSelections.tsx +++ b/web/components/Account/Application/Place/ApplicationsHelpers/ConfirmSelections.tsx @@ -20,7 +20,7 @@ const ConfirmSelections = ({ const { campaign } = query const confirmSelections = async () => { try { - client.disponibilities.campaignConfirmCreate( + await client.disponibilities.campaignConfirmCreate( preselectedApplications[0]?.disponibility.id as string, campaign as string, //@ts-expect-error diff --git a/web/components/Account/Place/PlaceList.tsx b/web/components/Account/Place/AdminPlaceList.tsx similarity index 88% rename from web/components/Account/Place/PlaceList.tsx rename to web/components/Account/Place/AdminPlaceList.tsx index af0cc635..efcf9bce 100644 --- a/web/components/Account/Place/PlaceList.tsx +++ b/web/components/Account/Place/AdminPlaceList.tsx @@ -5,14 +5,15 @@ import Link from '~components/Link' import { Box, Button, Text, Flex, VStack } from '@chakra-ui/react' import { useTranslation } from 'next-i18next' import Add from 'public/assets/img/add.svg' -import PlaceListItem from '~components/Account/Place/ListItem/PlaceListItem' + import MigrationMessage from '~components/MigrationMessage' +import AdminPlaceListItem from '~components/Account/Place/ListItem/AdminPlaceListItem' interface Props { places: Espace[] } -const PlaceList = ({ places }: Props) => { +const AdminPlaceList = ({ places }: Props) => { const { t } = useTranslation('place') const [isVisible, setVisible] = useState(false) @@ -50,7 +51,7 @@ const PlaceList = ({ places }: Props) => { {places.map((place, index) => ( - { ) } -export default PlaceList +export default AdminPlaceList diff --git a/web/components/Account/Place/ListItem/PlaceListItem.tsx b/web/components/Account/Place/ListItem/AdminPlaceListItem.tsx similarity index 96% rename from web/components/Account/Place/ListItem/PlaceListItem.tsx rename to web/components/Account/Place/ListItem/AdminPlaceListItem.tsx index 076d2050..101cf9e3 100644 --- a/web/components/Account/Place/ListItem/PlaceListItem.tsx +++ b/web/components/Account/Place/ListItem/AdminPlaceListItem.tsx @@ -20,7 +20,7 @@ interface Props { isFirst?: boolean } -const PlaceListItem = ({ place, setVisible, isFirst }: Props) => { +const AdminPlaceListItem = ({ place, setVisible, isFirst }: Props) => { const isComplete = useIsComplete(place) const { currentCampaign, isCampaignPlace } = useCampaignContext() @@ -31,6 +31,7 @@ const PlaceListItem = ({ place, setVisible, isFirst }: Props) => { }, [isComplete]) const { campaignDisposNum } = useCampaignDispo(place?.disponibilities) + const showCampaignDisponibilities = (currentCampaign?.mode === 'disponibilities' || campaignDisposNum) && isCampaignPlace @@ -93,4 +94,4 @@ const PlaceListItem = ({ place, setVisible, isFirst }: Props) => { ) } -export default PlaceListItem +export default AdminPlaceListItem diff --git a/web/components/Campaign/CampaignProvider.tsx b/web/components/Campaign/CampaignProvider.tsx index 54515164..31f4d063 100644 --- a/web/components/Campaign/CampaignProvider.tsx +++ b/web/components/Campaign/CampaignProvider.tsx @@ -29,8 +29,7 @@ const CampaignProvider = ({ children }: ICampaignProvider) => { const activeCampaignsQueryParameters = useMemo( () => ({ - disponibility_start_lte: today.toISOString(), - preselection_end_gte: today.toISOString(), + is_active: true, _sort: 'id:desc', }), [], diff --git a/web/components/Place/PlaceGridCard.tsx b/web/components/Place/PlaceGridCard.tsx index 9d64cb96..8c5995fd 100644 --- a/web/components/Place/PlaceGridCard.tsx +++ b/web/components/Place/PlaceGridCard.tsx @@ -55,13 +55,15 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => { const hasCampaignDispo = currentCampaign?.mode === 'applications' && !!campaignDisposNum + if (!place) return null + return ( { className="placeCard" role="group" h="100%" - id={`place-${place.id}`} + id={`place-${place?.id}`} > { overflow="hidden" pos="relative" > - {place.images.length > 0 ? ( - + {place?.images.length > 0 ? ( + ) : ( )} @@ -110,10 +112,10 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => { > - {place.name} + {place?.name} - {place.users_permissions_user.structureName} + {place?.users_permissions_user?.structureName} {place?.disponibilities?.length === 0 && gridMode !== 'campaign' && ( @@ -161,7 +163,7 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => { {t('card.city')} - {place.city?.name} + {place?.city?.name} @@ -182,7 +184,7 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => { {t('card.dim')} - {`${place.roomLength} x ${place.width} m`} + {`${place?.roomLength} x ${place?.width} m`} diff --git a/web/pages/compte/espaces/index.tsx b/web/pages/compte/espaces/index.tsx index cb655eb9..2a53c2b0 100644 --- a/web/pages/compte/espaces/index.tsx +++ b/web/pages/compte/espaces/index.tsx @@ -3,7 +3,6 @@ import { SSRConfig } from 'next-i18next' import { GetServerSideProps } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import InfoPlace from '~components/Account/Info/InfoPlace' -import PlaceList from '~components/Account/Place/PlaceList' import Loading from '~components/Loading' import { useMyPlaces } from '~hooks/useMyPlaces' import { UsersPermissionsUser } from '~typings/api' @@ -14,6 +13,7 @@ import PlacesAdminCampaignHelper from '~components/Campaign/Places/Admin/PlacesA import useCampaignContext from '~components/Campaign/useCampaignContext' import { format } from '~utils/date' import { Box } from '@chakra-ui/react' +import AdminPlaceList from '~components/Account/Place/AdminPlaceList' interface Props { user: UsersPermissionsUser } @@ -45,7 +45,7 @@ const AccountPlace = ({ user }: Props) => { {!places || places?.length === 0 ? ( ) : ( - + )} )