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'
32import isAfter from 'date-fns/isAfter'
4- import { format } from '~utils/date'
5- import { Espace } from '~typings/api'
63import { useTranslation } from 'next-i18next'
4+ import { useEffect , useState } from 'react'
5+ import { Espace } from '~typings/api'
6+ import { format } from '~utils/date'
77
88interface 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 >
0 commit comments