Skip to content

Commit

Permalink
feat(events): event card status
Browse files Browse the repository at this point in the history
  • Loading branch information
OverGlass committed Jul 26, 2024
1 parent d952465 commit 815375f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/components/Cards/EventCard/EventCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentProps } from 'react'
import React, { ComponentProps, useMemo } from 'react'
import { ImageRequireSource } from 'react-native'
import { Button } from '@/components'
import { VoxAlertDialog } from '@/components/AlertDialog'
import InternAlert from '@/components/InternAlert/InternAlert'
import VoxCard, { VoxCardAuthorProps, VoxCardDateProps, VoxCardFrameProps, VoxCardLocationProps } from '@/components/VoxCard/VoxCard'
import { useSession } from '@/ctx/SessionProvider'
import { useSubscribeEvent, useUnsubscribeEvent } from '@/services/events/hook'
Expand Down Expand Up @@ -76,16 +77,39 @@ export const SubscribeEventButton = ({
}

const EventCard = ({ payload, onShow, ...props }: EventVoxCardProps) => {
const isCancelled = payload.status === 'CANCELLED'
const isPassed = isPast(payload.date.end ?? payload.date.start)
const canSubscribe = [
!isPast(payload.date.end),
payload.isSubscribed !== undefined,
payload.status !== 'CANCELLED',
!isCancelled,
!payload.isCompleted || (payload.isCompleted && payload.isSubscribed),
].every(Boolean)

const status = useMemo(() => {
if (isCancelled) {
return (
<InternAlert borderLess type="danger">
Événement annulée.
</InternAlert>
)
} else if (isPassed) {
return <InternAlert borderLess>Événement passée.</InternAlert>
} else if (payload.isCompleted) {
return (
<InternAlert borderLess type="info">
Événement complet.
</InternAlert>
)
}
return null
}, [isCancelled, isPassed, payload.isCompleted])

return (
<VoxCard {...props}>
<VoxCard.Content>
<VoxCard.Chip event>{payload.tag}</VoxCard.Chip>
{status}
<VoxCard.Title>{payload.title}</VoxCard.Title>
{payload.image ? <VoxCard.Image image={payload.image} /> : null}
<VoxCard.Date {...payload.date} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/events/EventFeedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useSuspensePaginatedEvents } from '@/services/events/hook'
import { isFullEvent, isPartialEvent, RestItemEvent, RestPublicItemEvent } from '@/services/events/schema'
import { useScrollToTop } from '@react-navigation/native'
import { ChevronDown, Filter } from '@tamagui/lucide-icons'
import { isPast } from 'date-fns'
import { router } from 'expo-router'
import { getToken, Spinner, useMedia, XStack, YStack } from 'tamagui'
import { useDebounce } from 'use-debounce'
Expand All @@ -26,7 +27,7 @@ const splitEvents = (events: RestItemEvent[] | RestPublicItemEvent[]) => {
const incomming: typeof events = []
const past: typeof events = []
events.forEach((event) => {
if (new Date(event.begin_at) < new Date()) {
if (isPast(event.finish_at)) {
past.push(event)
} else {
incomming.push(event)
Expand Down

0 comments on commit 815375f

Please sign in to comment.