Skip to content

Commit 148cd09

Browse files
committed
fix: improve no disponibilites handler
1 parent 70caa89 commit 148cd09

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

web/components/Place/Booking/BookingFilledUntil.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
1-
import React, { useEffect, useState } from 'react'
2-
import { Box, Text, Flex } from '@chakra-ui/react'
1+
import { Box, Flex, Text } from '@chakra-ui/react'
32
import isAfter from 'date-fns/isAfter'
4-
import { format } from '~utils/date'
5-
import { Espace } from '~typings/api'
63
import { useTranslation } from 'next-i18next'
4+
import { useEffect, useState } from 'react'
5+
import { Espace } from '~typings/api'
6+
import { format } from '~utils/date'
77

88
interface Props {
9-
start: Date
9+
start?: Date
1010
place: Espace
11+
isMonthlyView?: boolean
1112
}
1213

13-
const BookingFilledUntil = ({ start, place }: Props) => {
14-
const { t } = useTranslation('place')
14+
const BookingFilledUntil = ({ start, place, isMonthlyView = false }: Props) => {
1515
const [isVisible, setVisible] = useState(false)
16+
const { t } = useTranslation('place')
1617

18+
const isAllCampaign = place.disponibilities.every((d) => d.campaign)
1719
const typeMessage =
18-
!place.filledUntil || place.disponibilities.length === 0
20+
!place.filledUntil || place.disponibilities.length === 0 || isAllCampaign
1921
? 'empty'
2022
: 'default'
2123

2224
useEffect(() => {
23-
if (!start) return
25+
if (!start && !isMonthlyView) {
26+
return
27+
}
28+
2429
setVisible(
2530
isAfter(start, new Date(place?.filledUntil)) ||
26-
place.disponibilities.length === 0,
31+
place.disponibilities.length === 0 ||
32+
isAllCampaign,
2733
)
2834
}, [start])
2935

30-
if (!isVisible) return null
36+
if (!isVisible) {
37+
return null
38+
}
39+
3140
return (
3241
<Flex
3342
layerStyle="absoluteFull"
3443
pt="60px"
3544
justifyContent="center"
3645
alignItems="center"
46+
zIndex={isMonthlyView ? 99 : 1}
47+
bg={isMonthlyView ? 'rgba(244, 245, 249, 0.8)' : 'transparent'}
3748
>
3849
<Flex
3950
zIndex={99}
@@ -44,11 +55,15 @@ const BookingFilledUntil = ({ start, place }: Props) => {
4455
maxW="800px"
4556
>
4657
<Box maxW="container.md">
47-
<Text>
48-
{t(`detail.filledUntil.title.${typeMessage}`, {
49-
date: format(place.filledUntil, 'dd/MM/yyyy'),
50-
})}
51-
</Text>
58+
{typeMessage === 'default' ? (
59+
<Text>
60+
{t(`detail.filledUntil.title.${typeMessage}`, {
61+
date: format(place.filledUntil, 'dd/MM/yyyy'),
62+
})}
63+
</Text>
64+
) : (
65+
<Text>{t(`detail.filledUntil.title.${typeMessage}`)}</Text>
66+
)}
5267
<Text color="grayText.1">
5368
{t(`detail.filledUntil.text.${typeMessage}`)}
5469
</Text>

web/components/Place/Booking/BookingScheduleContainer.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
Box,
3-
Button,
4-
Center,
5-
Flex,
6-
Text,
7-
useBreakpointValue,
8-
} from '@chakra-ui/react'
1+
import { Box, Button, Flex, Text, useBreakpointValue } from '@chakra-ui/react'
92
import { useTranslation } from 'next-i18next'
103
import { useEffect, useMemo, useState } from 'react'
114
import BookingRecap from '~components/Place/Booking/BookingRecapInsert/BookingRecap'
@@ -44,13 +37,7 @@ const BookingScheduleContainer = ({ place }: Props) => {
4437
px={{ base: 4, lg: 6 }}
4538
py={6}
4639
borderRadius="sm"
47-
pos="relative"
4840
>
49-
{events.length === 0 && (
50-
<Center position="absolute" zIndex={100} bg="whiteAlpha.800" inset={0}>
51-
<Text textStyle="h2">{t('list.noDisponibility')}</Text>
52-
</Center>
53-
)}
5441
<Flex
5542
justifyContent="space-between"
5643
pb={{ base: 6, lg: 14 }}

web/components/Place/Booking/BookingScheduleMonth.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { Box, Flex, useBreakpointValue } from '@chakra-ui/react'
12
import FullCalendar, { createPlugin } from '@fullcalendar/react'
2-
import React, { useRef } from 'react'
3+
import frLocale from '@fullcalendar/core/locales/fr'
34
import dayGridPlugin from '@fullcalendar/daygrid'
45
import interactionPlugin from '@fullcalendar/interaction'
5-
import frLocale from '@fullcalendar/core/locales/fr'
6-
import { Box, Flex, useBreakpointValue } from '@chakra-ui/react'
7-
import { Espace } from '~typings/api'
8-
import BookingScheduleSlot from '~components/Place/Booking/BookingScheduleSlot'
9-
import { ScheduleEvent } from '~@types/schedule-event.d'
106
import addMonths from 'date-fns/addMonths'
117
import isSameDay from 'date-fns/isSameDay'
8+
import { useRef } from 'react'
9+
import { ScheduleEvent } from '~@types/schedule-event.d'
10+
import BookingScheduleSlot from '~components/Place/Booking/BookingScheduleSlot'
11+
import { Espace } from '~typings/api'
12+
import BookingFilledUntil from '~components/Place/Booking/BookingFilledUntil'
1213

1314
const view = createPlugin({
1415
views: {
@@ -123,6 +124,7 @@ const BookingScheduleMonth = ({ place, events }: Props) => {
123124
/>
124125
)}
125126
</Flex>
127+
<BookingFilledUntil isMonthlyView place={place} />
126128
</Flex>
127129
)
128130
}

0 commit comments

Comments
 (0)