Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Add 'Lifecycle Status' computed property to events
Dave Earley33003d9bb770
diff --git a/backend/app/DomainObjects/EventDomainObject.php b/backend/app/DomainObjects/EventDomainObject.phpindex fd08ff1b4..b7f599611 100644--- a/backend/app/DomainObjects/EventDomainObject.php+++ b/backend/app/DomainObjects/EventDomainObject.php@@ -2,12 +2,14 @@namespace HiEvents\DomainObjects;-use HiEvents\Helper\Url;-use Illuminate\Support\Collection;-use Illuminate\Support\Str;+use Carbon\Carbon;use HiEvents\DomainObjects\Interfaces\IsSortable;use HiEvents\DomainObjects\SortingAndFiltering\AllowedSorts;+use HiEvents\DomainObjects\Status\EventLifecycleStatus;use HiEvents\Helper\StringHelper;+use HiEvents\Helper\Url;+use Illuminate\Support\Collection;+use Illuminate\Support\Str;class EventDomainObject extends Generated\EventDomainObjectAbstract implements IsSortable{@@ -134,4 +136,58 @@ class EventDomainObject extends Generated\EventDomainObjectAbstract implements Ireturn StringHelper::previewFromHtml($this->getDescription());}++ public function isEventInPast(): bool+ {+ if ($this->getEndDate() === null) {+ return false;+ }+ $endDate = Carbon::parse($this->getEndDate());+ $endDate->setTimezone($this->getTimezone());++ return $endDate->isPast();+ }++ public function isEventInFuture(): bool+ {+ if ($this->getStartDate() === null) {+ return false;+ }+ $startDate = Carbon::parse($this->getStartDate());+ $startDate->setTimezone($this->getTimezone());++ return $startDate->isFuture();+ }++ public function isEventOngoing(): bool+ {+ $startDate = Carbon::parse($this->getStartDate());+ $startDate->setTimezone($this->getTimezone());++ if ($this->getEndDate() === null) {+ return $startDate->isPast();+ }++ $endDate = Carbon::parse($this->getEndDate());+ $endDate->setTimezone($this->getTimezone());++ return $startDate->isPast() && $endDate->isFuture();+ }++ public function getLifecycleStatus(): string+ {+ if ($this->isEventInPast()) {+ return EventLifecycleStatus::ENDED->name;+ }++ if ($this->isEventInFuture()) {+ return EventLifecycleStatus::UPCOMING->name;+ }++ if ($this->isEventOngoing()) {+ return EventLifecycleStatus::ONGOING->name;+ }++ return EventLifecycleStatus::ENDED->name;+ }}diff --git a/backend/app/DomainObjects/Status/EventLifecycleStatus.php b/backend/app/DomainObjects/Status/EventLifecycleStatus.phpnew file mode 100644index 000000000..5b9439b08--- /dev/null+++ b/backend/app/DomainObjects/Status/EventLifecycleStatus.php@@ -0,0 +1,14 @@+<?php++namespace HiEvents\DomainObjects\Status;++use HiEvents\DomainObjects\Enums\BaseEnum;++enum EventLifecycleStatus+{+ use BaseEnum;++ case UPCOMING;+ case ENDED;+ case ONGOING;+}diff --git a/backend/app/Resources/Event/EventResource.php b/backend/app/Resources/Event/EventResource.phpindex f05928e48..970cf3e74 100644--- a/backend/app/Resources/Event/EventResource.php+++ b/backend/app/Resources/Event/EventResource.php@@ -23,6 +23,7 @@ class EventResource extends BaseResource'start_date' => $this->getStartDate(),'end_date' => $this->getEndDate(),'status' => $this->getStatus(),+ 'lifecycle_status' => $this->getLifeCycleStatus(),'currency' => $this->getCurrency(),'timezone' => $this->getTimezone(),'slug' => $this->getSlug(),diff --git a/backend/app/Resources/Event/EventResourcePublic.php b/backend/app/Resources/Event/EventResourcePublic.phpindex 0795c1b93..1b83db2c9 100644--- a/backend/app/Resources/Event/EventResourcePublic.php+++ b/backend/app/Resources/Event/EventResourcePublic.php@@ -26,6 +26,7 @@ class EventResourcePublic extends BaseResource'currency' => $this->getCurrency(),'slug' => $this->getSlug(),'status' => $this->getStatus(),+ 'lifecycle_status' => $this->getLifecycleStatus(),'timezone' => $this->getTimezone(),'location_details' => $this->when((bool)$this->getLocationDetails(), fn() => $this->getLocationDetails()),diff --git a/frontend/src/components/common/EventCard/index.tsx b/frontend/src/components/common/EventCard/index.tsxindex c802bbf1e..39bf56e1b 100644--- a/frontend/src/components/common/EventCard/index.tsx+++ b/frontend/src/components/common/EventCard/index.tsx@@ -1,12 +1,21 @@-import {Badge, Button, Group, Menu, Text,} from '@mantine/core';+import {Button, Group, Menu, Text,} from '@mantine/core';import {Event} from "../../../types.ts";import classes from "./EventCard.module.scss";import {Card} from "../Card";import {NavLink, useNavigate} from "react-router-dom";-import {IconCalendarEvent, IconDotsVertical, IconEye, IconMap, IconSettings, IconUser,} from "@tabler/icons-react";+import {+ IconCalendarEvent,+ IconDotsVertical,+ IconEye,+ IconMap,+ IconQrcode,+ IconSettings,+ IconUser,+} from "@tabler/icons-react";import {relativeDate} from "../../../utilites/dates.ts";import {t} from "@lingui/macro"import {eventHomepagePath} from "../../../utilites/urlHelper.ts";+import {EventStatusBadge} from "../EventStatusBadge";interface EventCardProps {event: Event;@@ -19,9 +28,7 @@ export function EventCard({event}: EventCardProps) {<><Card className={classes.card}><div className={classes.body}>- <Badge color={event?.status === 'LIVE' ? 'green' : 'gray'}>- {event?.status}- </Badge>+ {event && <EventStatusBadge event={event}/>}<Text className={classes.title} mt="xs" mb="md"><NavLink to={`/manage/event/${event.id}`}>{event.title}@@ -74,12 +81,16 @@ export function EventCard({event}: EventCardProps) {</Menu.Target><Menu.Dropdown>- <Menu.Item leftSection={<IconEye size={14}/>} onClick={() => window.location.href = eventHomepagePath(event)}>+ <Menu.Item leftSection={<IconEye size={14}/>}+ onClick={() => window.location.href = eventHomepagePath(event)}>{t`View event page`}</Menu.Item><Menu.Item onClick={() => navigate(`/manage/event/${event.id}`)}leftSection={<IconSettings size={14}/>}>{t`Manage event`}</Menu.Item>+ <Menu.Item onClick={() => navigate(`/manage/event/${event.id}/check-in`)}+ leftSection={<IconQrcode size={14}/>}+ >{t`Check-in`}</Menu.Item></Menu.Dropdown></Menu>diff --git a/frontend/src/components/common/EventStatusBadge/index.tsx b/frontend/src/components/common/EventStatusBadge/index.tsxnew file mode 100644index 000000000..4bb6f285e--- /dev/null+++ b/frontend/src/components/common/EventStatusBadge/index.tsx@@ -0,0 +1,35 @@+import {Event} from "../../../types.ts";+import {Badge} from "@mantine/core";+import {t} from "@lingui/macro";++interface EventLifecycleStatusLabelProps {+ event: Event;+ showLifecycleStatus?: boolean;+}++export const EventStatusBadge = ({event, showLifecycleStatus = true}: EventLifecycleStatusLabelProps) => {+ const getLifecycleStatus = (() => {+ switch (event.lifecycle_status) {+ case 'ENDED':+ return t`Ended`;+ case 'UPCOMING':+ return t`Upcoming`;+ case 'ONGOING':+ return t`Ongoing`;+ default:+ return undefined;+ }+ })();++ return (+ <>+ <Badge color={event?.status === 'LIVE' ? 'green' : 'gray'}>+ {event.status} {showLifecycleStatus && (+ <>+ • {getLifecycleStatus}+ </>+ )}+ </Badge>+ </>+ );+}\ No newline at end of filediff --git a/frontend/src/components/layouts/Event/index.tsx b/frontend/src/components/layouts/Event/index.tsxindex 9e4d853de..3507d363a 100644--- a/frontend/src/components/layouts/Event/index.tsx+++ b/frontend/src/components/layouts/Event/index.tsx@@ -30,6 +30,7 @@ import {showError, showSuccess} from "../../../utilites/notifications.tsx";import {Tooltip} from "../../common/Tooltip";import {confirmationDialog} from "../../../utilites/confirmationDialog.tsx";import {useGetEventSettings} from "../../../queries/useGetEventSettings.ts";+import {EventStatusBadge} from "../../common/EventStatusBadge";const EventLayout = () => {const data = [@@ -148,10 +149,11 @@ const EventLayout = () => {: t`Event is not visible to the public`}><UnstyledButton onClick={handleStatusToggle}>- <Badge color={event?.status === 'LIVE' ? 'green' : 'gray'}- ml={10}>- {event?.status}- </Badge>+ {event && (+ <div style={{marginLeft: '10px'}}>+ <EventStatusBadge event={event}/>+ </div>+ )}</UnstyledButton></Tooltip>)}diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex a3d27ba0a..021078621 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -131,12 +131,14 @@ export interface Event {id?: IdParam;title: string;slug: string;- status?: string;+ status?: 'DRAFT' | 'LIVE' | 'PAUSED';start_date: string;end_date?: string;description?: string;description_preview?: string;+ lifecycle_status?: 'ONGOING' | 'UPCOMING' | 'ENDED';+settings?: EventSettings;tickets?: Ticket[],images?: Image[],