Skip to content

Commit

Permalink
fix : fix disponibilities solidarity
Browse files Browse the repository at this point in the history
  • Loading branch information
baptadn committed Sep 16, 2024
1 parent 9bd7ddf commit 72df7d4
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 84 deletions.
37 changes: 25 additions & 12 deletions back/api/espace/controllers/espace.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const isToday = require("date-fns/isToday");
* to customize this controller
*/

const filterUserAttributes = (users_permissions_user) => {
const { id, structureName, email, phone, website, blocked } = users_permissions_user

return { id, structureName, email, phone, website, blocked }
}

const populate = [
"disponibilities",
"disponibilities.booking",
Expand All @@ -23,7 +29,7 @@ const populate = [

module.exports = {
async myPlaces(ctx) {
const {query}=ctx.request;
const { query } = ctx.request;
const { id } = ctx.state.user;
return strapi.query("espace").find(
{
Expand All @@ -38,6 +44,8 @@ module.exports = {
async find(ctx) {
const { _sort, perimeter, ...query } = ctx.query;
const isSortOnDisponibility = ["dispoAsc", "nbDispoDesc"].includes(_sort);
const isCampaignMode = Boolean(query['disponibilities.campaign'])


if (perimeter && query["city.name_eq"]) {
const placesInPerimeter =
Expand All @@ -51,7 +59,6 @@ module.exports = {
}
}


let places = await strapi.services.espace
.find(
{
Expand Down Expand Up @@ -81,8 +88,11 @@ module.exports = {
);

return place;
});
}).map(p => ({ ...p, users_permissions_user: filterUserAttributes(p.users_permissions_user) }))

const filterDispo = (disponibilities) => disponibilities?.filter(d => {
return isCampaignMode ? d.campaign !== null : d.campaign === null
})

if (isSortOnDisponibility) {
if (_sort === "nbDispoDesc") {
Expand All @@ -92,33 +102,36 @@ module.exports = {
} else if (_sort === "dispoAsc") {
return places.sort((a, b) => {
const dateFirst =
a.disponibilities.length > 0
? min(a.disponibilities.map(({ start }) => new Date(start)))
filterDispo(a.disponibilities).length > 0
? min(filterDispo(a.disponibilities).map(({ start }) => new Date(start)))
: new Date("3000-01-01");


const dateSecond =
b.disponibilities.length > 0
? min(b.disponibilities.map(({ start }) => new Date(start)))
filterDispo(b.disponibilities).length > 0
? min(filterDispo(b.disponibilities).map(({ start }) => new Date(start)))
: new Date("3000-01-01");

return dateFirst - dateSecond;
});
}
}
return places;

return places
},
async update(ctx) {
const { id } = ctx.params;

let entity;
if (ctx.is("multipart")) {
const { data, files, campaign_files } = parseMultipartData(ctx);
entity = await strapi.services.espace.update({ id }, data, {files, campaign_files});
entity = await strapi.services.espace.update({ id }, data, { files, campaign_files });
} else {
const { files,campaign_files, ...body } = ctx.request.body;
await Promise.all([files, campaign_files].map(async(fileList)=>{
const { files, campaign_files, ...body } = ctx.request.body;
await Promise.all([files, campaign_files].map(async (fileList) => {
if (fileList && fileList.length > 0) {
await Promise.all(
fileList.map(async(file) => {
fileList.map(async (file) => {
await strapi.plugins["upload"].services.upload.updateFileInfo(file.id, {
caption: file.caption,
});
Expand Down
13 changes: 6 additions & 7 deletions web/components/Actuality/ActuCard.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React from 'react'
import { Text, Box, Flex, Button, AspectRatio, LinkBox } from '@chakra-ui/react'
import LinkOverlay from '~components/LinkOverlay'
import { AspectRatio, Box, Button, Flex, Text } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import removeMd from 'remove-markdown'
import Image from '~components/Image'
import Link from '~components/Link'
import { format } from '~utils/date'
import { ROUTE_ACTU_DETAIL } from '~constants'
import { Actuality } from '~typings/api'
import { useTranslation } from 'next-i18next'
import removeMd from 'remove-markdown'
import { format } from '~utils/date'

interface IActuCard {
actu: Actuality
}

const ActuCard = ({ actu }: IActuCard) => {
const { t } = useTranslation('actuality')
console.log({ lol: actu?.image.formats })
return (
<Link
_hover={{
Expand All @@ -28,7 +27,7 @@ const ActuCard = ({ actu }: IActuCard) => {
<AspectRatio w="100%" maxH="300px" ratio={16 / 9} overflow="hidden">
<Image
// @ts-ignore
src={actu?.image.formats.thumbnail.url || actu?.image?.url}
src={actu?.image.formats.large.url || actu?.image?.url}
objectFit="cover"
transition="transform ease-in-out 200ms"
_groupHover={{ transform: 'scale(1.05)' }}
Expand Down
15 changes: 7 additions & 8 deletions web/components/Home/HomePlacesSolidarity.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import React from 'react'
import {
Flex,
Box,
Text,
Button,
useBreakpointValue,
Flex,
HStack,
Stack,
Text,
useBreakpointValue,
} from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import Arrow from 'public/assets/img/arrow-bottom.svg'
import { usePlaces } from '~hooks/usePlaces'
import PlaceGrid from '~components/Place/PlaceGrid'
import HomeHelperSolidarity from '~components/Campaign/HomeHelperSolidarity'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import Link from '~components/Link'
import PlaceGrid from '~components/Place/PlaceGrid'
import { ROUTE_PLACES } from '~constants'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import HomeHelperSolidarity from '~components/Campaign/HomeHelperSolidarity'
import { usePlaces } from '~hooks/usePlaces'

const HomePlacesSolidarity = () => {
const isLgOrSm = useBreakpointValue({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react'
import { Button, Text, Box, ButtonGroup } from '@chakra-ui/react'
import { Box, Button, ButtonGroup, Text } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import Link from '~components/Link'
import { ROUTE_SIGNUP } from '~constants'
import SigninModal from '~components/Signin/SigninModal'
import { useTranslation } from 'next-i18next'
import { ROUTE_SIGNUP } from '~constants'

const AuthBookingInsert = ({
nbSelected,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useMemo, useContext } from 'react'
import { Flex, Text, Box } from '@chakra-ui/react'
import BookingScheduleContext from '~components/Place/Booking/BookingScheduleContext'
import { Flex } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import { useCurrentUser } from '~hooks/useCurrentUser'
import { useContext, useMemo } from 'react'
import AuthBookingInsert from '~components/Place/Booking/BookingRecapInsert/AuthBookingInsert'
import ConfirmBookingInsert from '~components/Place/Booking/BookingRecapInsert/ConfirmBookingInsert'
import { is } from 'date-fns/locale'
import NotConfirmedBookingInsert from '~components/Place/Booking/BookingRecapInsert/NotConfirmedBookingInsert'
import BookingScheduleContext from '~components/Place/Booking/BookingScheduleContext'
import { useCurrentUser } from '~hooks/useCurrentUser'

const BookingRecap = ({ isCampaignMode }: { isCampaignMode?: boolean }) => {
const { t } = useTranslation('place')
Expand Down
5 changes: 2 additions & 3 deletions web/components/Place/PlaceDetailPage/PlaceDetailCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Flex, Text } from '@chakra-ui/react'
import BookingScheduleContainer from '~components/Place/Booking/BookingScheduleContainer'
import { useTranslation } from 'next-i18next'
import Calendar from 'public/assets/img/calendar.svg'
import BookingScheduleContainer from '~components/Place/Booking/BookingScheduleContainer'
import { Espace } from '~typings/api'
import { useTranslation } from 'next-i18next'

const PlaceDetailCalendar = ({ place }: { place: Espace }) => {
const { t } = useTranslation('place')
Expand All @@ -17,7 +17,6 @@ const PlaceDetailCalendar = ({ place }: { place: Espace }) => {
{t('detail.calendar')}
</Text>
</Flex>

<BookingScheduleContainer place={place} />
</>
)
Expand Down
59 changes: 37 additions & 22 deletions web/components/Place/PlaceGridCard.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import React from 'react'
import {
AspectRatio,
Box,
Flex,
Text,
Divider,
AspectRatio,
Flex,
LinkBox,
Text,
} from '@chakra-ui/react'
import { Espace } from '~typings/api'
import PlaceCardCarousel from '~components/Place/PlaceCardCarousel'
import { ROUTE_PLACE_DETAIL } from '~constants'
import addWeeks from 'date-fns/addWeeks'
import { useTranslation } from 'next-i18next'
import { DisponibilityStatus } from '~@types/disponibility.d'
import CampaignTag from '~components/Campaign/CampaignTag'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import FallbackImage from '~components/FallbackImage'
import LinkOverlay from '~components/LinkOverlay'
import PlaceCardCarousel from '~components/Place/PlaceCardCarousel'
import Tag from '~components/Tag'
import { DisponibilityStatus } from '~@types/disponibility.d'
import { SearchQuery } from '~utils/search'
import { ROUTE_PLACE_DETAIL } from '~constants'
import useCampaignDispo from '~hooks/useCampaignDispo'
import { useCurrentUser } from '~hooks/useCurrentUser'
import useDispoInRange from '~hooks/useDispoInRange'
import useNbDispoPerWeek from '~hooks/useNbDispoPerWeek'
import addWeeks from 'date-fns/addWeeks'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import { Espace } from '~typings/api'
import { format } from '~utils/date'
import CampaignTag from '~components/Campaign/CampaignTag'
import useCampaignDispo from '~hooks/useCampaignDispo'
import { useCurrentUser } from '~hooks/useCurrentUser'
import { SearchQuery } from '~utils/search'

interface Props {
place: Espace
Expand All @@ -36,28 +35,44 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => {
const { applications } = useCurrentUser()
const { t } = useTranslation('place')

const filteredDisponibilities =
place?.disponibilities?.filter((item) => {
if (gridMode === 'campaign') {
return Boolean(item.campaign)
}

return item.campaign === null
}) ?? []

const disposInRange = useDispoInRange(
place?.disponibilities,
filteredDisponibilities,
searchParams?.['disponibilities.start_gte'],
searchParams?.['disponibilities.end_lte'],
)

const disposThisWeek = useNbDispoPerWeek(
new Date(),
disposInRange || place?.disponibilities,
disposInRange || filteredDisponibilities,
)

const disposNextWeek = useNbDispoPerWeek(
addWeeks(new Date(), 1),
disposInRange || place?.disponibilities,
disposInRange || filteredDisponibilities,
)

const { campaignDisposNum, campaignDispos } = useCampaignDispo(
place?.disponibilities,
)
const {
campaignDisposNum,
campaignDispos,
solidarityDispos,
solidarityDisposNum,
} = useCampaignDispo(place?.disponibilities)

const hasCampaignDispo =
currentCampaign?.mode === 'applications' && !!campaignDisposNum

if (!place) return null
if (!place) {
return null
}

return (
<LinkBox>
Expand Down Expand Up @@ -120,7 +135,7 @@ const PlaceGridCard = ({ place, searchParams, gridMode }: Props) => {
{place?.users_permissions_user?.structureName}
</Text>
</Box>
{place?.disponibilities?.length === 0 && gridMode !== 'campaign' && (
{filteredDisponibilities?.length === 0 && gridMode !== 'campaign' && (
<Tag
status={DisponibilityStatus.PAST}
alignSelf="flex-start"
Expand Down
6 changes: 3 additions & 3 deletions web/components/Place/PlaceList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useMemo, useState } from 'react'
import { Box, VStack, Flex } from '@chakra-ui/react'
import { Box, Flex, VStack } from '@chakra-ui/react'
import dynamic from 'next/dynamic'
import Loading from '~components/Loading'
import { useMemo, useState } from 'react'
import Loader from '~components/Loader'
import Loading from '~components/Loading'
import PlaceListCard from '~components/Place/PlaceListCard'
import PlaceListCardSkeleton from '~components/Place/PlaceListCardSkeleton'
const Map = dynamic(() => import('~components/Map'), { ssr: false })
Expand Down
17 changes: 8 additions & 9 deletions web/components/Place/PlaceListCard.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import React from 'react'
import {
AspectRatio,
Box,
Flex,
Text,
AspectRatio,
LinkBox,
SimpleGrid,
Text,
} from '@chakra-ui/react'
import { Espace } from '~typings/api'
import PlaceCardCarousel from '~components/Place/PlaceCardCarousel'
import { ROUTE_PLACE_DETAIL } from '~constants'
import { useTranslation } from 'next-i18next'
import FallbackImage from '~components/FallbackImage'
import LinkOverlay from '~components/LinkOverlay'
import { format } from '~utils/date'
import CampaignTag from '~components/Campaign/CampaignTag'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import FallbackImage from '~components/FallbackImage'
import LinkOverlay from '~components/LinkOverlay'
import PlaceCardCarousel from '~components/Place/PlaceCardCarousel'
import { ROUTE_PLACE_DETAIL } from '~constants'
import useCampaignDispo from '~hooks/useCampaignDispo'
import { Espace } from '~typings/api'
import { format } from '~utils/date'

interface Props {
place: Espace
Expand Down
1 change: 0 additions & 1 deletion web/components/Place/PlacesCampaignTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const PlacesCampaignTabs = () => {
display={{ base: 'none', xl: 'inherit' }}
/>
</HStack>

<TabPanels>
<TabPanel padding={0}>
<PlacesPage />
Expand Down
Loading

0 comments on commit 72df7d4

Please sign in to comment.