Skip to content

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 ⭐️

Add options to filters by upcoming, ended and archived

Dave Earley07afc670df09
diff --git a/backend/app/DomainObjects/EventDomainObject.php b/backend/app/DomainObjects/EventDomainObject.php
index af764deb6..a4ac36913 100644
--- a/backend/app/DomainObjects/EventDomainObject.php
+++ b/backend/app/DomainObjects/EventDomainObject.php
@@ -3,6 +3,7 @@
namespace HiEvents\DomainObjects;
use Carbon\Carbon;
+use HiEvents\DomainObjects\Interfaces\IsFilterable;
use HiEvents\DomainObjects\Interfaces\IsSortable;
use HiEvents\DomainObjects\SortingAndFiltering\AllowedSorts;
use HiEvents\DomainObjects\Status\EventLifecycleStatus;
@@ -11,7 +12,7 @@ use HiEvents\Helper\Url;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
-class EventDomainObject extends Generated\EventDomainObjectAbstract implements IsSortable
+class EventDomainObject extends Generated\EventDomainObjectAbstract implements IsSortable, IsFilterable
{
private ?Collection $tickets = null;
@@ -25,6 +26,19 @@ class EventDomainObject extends Generated\EventDomainObjectAbstract implements I
private ?OrganizerDomainObject $organizer = null;
+ public static function getAllowedFilterFields(): array
+ {
+ return [
+ self::TITLE,
+ self::START_DATE,
+ self::END_DATE,
+ self::CREATED_AT,
+ self::UPDATED_AT,
+ self::STATUS,
+ self::ORGANIZER_ID,
+ ];
+ }
+
public static function getAllowedSorts(): AllowedSorts
{
return new AllowedSorts(
diff --git a/backend/app/DomainObjects/Interfaces/IsFilterable.php b/backend/app/DomainObjects/Interfaces/IsFilterable.php
index b4c347bb8..63f094209 100644
--- a/backend/app/DomainObjects/Interfaces/IsFilterable.php
+++ b/backend/app/DomainObjects/Interfaces/IsFilterable.php
@@ -5,7 +5,7 @@ namespace HiEvents\DomainObjects\Interfaces;
interface IsFilterable
{
/**
- * @return array<string, string>
+ * @return array<string>
*/
public static function getAllowedFilterFields(): array;
}
diff --git a/backend/app/DomainObjects/Status/EventStatus.php b/backend/app/DomainObjects/Status/EventStatus.php
index c4c25976f..45d723eb9 100644
--- a/backend/app/DomainObjects/Status/EventStatus.php
+++ b/backend/app/DomainObjects/Status/EventStatus.php
@@ -10,5 +10,5 @@ enum EventStatus
case DRAFT;
case LIVE;
- case PAUSED;
+ case ARCHIVED;
}
diff --git a/backend/app/Http/Actions/Events/GetEventsAction.php b/backend/app/Http/Actions/Events/GetEventsAction.php
index 746a33cea..469e31325 100644
--- a/backend/app/Http/Actions/Events/GetEventsAction.php
+++ b/backend/app/Http/Actions/Events/GetEventsAction.php
@@ -29,7 +29,7 @@ class GetEventsAction extends BaseAction
$events = $this->getEventsHandler->handle(
GetEventsDTO::fromArray([
'accountId' => $this->getAuthenticatedAccountId(),
- 'queryParams' => QueryParamsDTO::fromArray($request->query->all()),
+ 'queryParams' => $this->getPaginationQueryParams($request),
]),
);
diff --git a/backend/app/Http/DTO/FilterFieldDTO.php b/backend/app/Http/DTO/FilterFieldDTO.php
new file mode 100644
index 000000000..6457b5743
--- /dev/null
+++ b/backend/app/Http/DTO/FilterFieldDTO.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace HiEvents\Http\DTO;
+
+use HiEvents\DataTransferObjects\BaseDTO;
+
+class FilterFieldDTO extends BaseDTO
+{
+ public function __construct(
+ public readonly ?string $field = null,
+ public readonly ?string $operator = null,
+ public readonly ?string $value = null,
+ )
+ {
+ }
+}
diff --git a/backend/app/Http/DTO/QueryParamsDTO.php b/backend/app/Http/DTO/QueryParamsDTO.php
index 308748dbf..713766a42 100644
--- a/backend/app/Http/DTO/QueryParamsDTO.php
+++ b/backend/app/Http/DTO/QueryParamsDTO.php
@@ -3,18 +3,46 @@
namespace HiEvents\Http\DTO;
use HiEvents\DataTransferObjects\BaseDTO;
+use Illuminate\Support\Collection;
class QueryParamsDTO extends BaseDTO
{
public function __construct(
- public readonly ?int $page = 1,
- public readonly ?int $per_page = 25,
- public readonly ?string $sort_by = 'id',
- public readonly ?string $sort_direction = 'desc',
- public readonly ?string $query = null,
- public readonly ?array $filter_fields = null,
- public readonly ?array $includes = null,
+ public readonly ?int $page = 1,
+ public readonly ?int $per_page = 25,
+ public readonly ?string $sort_by = 'id',
+ public readonly ?string $sort_direction = 'desc',
+ public readonly ?string $query = null,
+ /** @var Collection<FilterFieldDTO> */
+ public readonly ?Collection $filter_fields = null,
+ public readonly ?array $includes = null,
+ public readonly ?Collection $query_params = null,
)
{
}
+
+ public static function fromArray(array $data): self
+ {
+ $filterFields = collect();
+ foreach ($data['filter_fields'] ?? [] as $field => $conditions) {
+ foreach ($conditions as $operator => $value) {
+ $filterFields->push(new FilterFieldDTO(
+ field: $field,
+ operator: $operator,
+ value: $value,
+ ));
+ }
+ }
+
+ return new self(
+ page: $data['page'] ?? 1,
+ per_page: $data['per_page'] ?? 25,
+ sort_by: $data['sort_by'] ?? 'id',
+ sort_direction: $data['sort_direction'] ?? 'desc',
+ query: $data['query'] ?? null,
+ filter_fields: $filterFields,
+ includes: $data['includes'] ?? null,
+ query_params: collect($data),
+ );
+ }
}
diff --git a/backend/app/Repository/Eloquent/BaseRepository.php b/backend/app/Repository/Eloquent/BaseRepository.php
index b0cde250c..0c20fed9c 100644
--- a/backend/app/Repository/Eloquent/BaseRepository.php
+++ b/backend/app/Repository/Eloquent/BaseRepository.php
@@ -6,6 +6,11 @@ namespace HiEvents\Repository\Eloquent;
use BadMethodCallException;
use Carbon\Carbon;
+use HiEvents\DomainObjects\Interfaces\DomainObjectInterface;
+use HiEvents\Http\DTO\QueryParamsDTO;
+use HiEvents\Models\BaseModel;
+use HiEvents\Repository\Eloquent\Value\Relationship;
+use HiEvents\Repository\Interfaces\RepositoryInterface;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\Eloquent\Builder;
@@ -15,10 +20,6 @@ use Illuminate\Foundation\Application;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
-use HiEvents\DomainObjects\Interfaces\DomainObjectInterface;
-use HiEvents\Models\BaseModel;
-use HiEvents\Repository\Eloquent\Value\Relationship;
-use HiEvents\Repository\Interfaces\RepositoryInterface;
/**
* @template T
@@ -333,6 +334,39 @@ abstract class BaseRepository implements RepositoryInterface
return $this->hydrateDomainObjectFromModel($model, $domainObjectOverride);
}
+ protected function applyFilterFields(QueryParamsDTO $params, array $allowedFilterFields = []): void
+ {
+ if ($params->filter_fields && $params->filter_fields->isNotEmpty()) {
+ $params->filter_fields->each(function ($filterField) use ($allowedFilterFields) {
+ if (!in_array($filterField->field, $allowedFilterFields, true)) {
+ return;
+ }
+
+ $isNull = $filterField->value === 'null';
+
+ $operatorMapping = [
+ 'eq' => $isNull ? 'IS' : '=',
+ 'ne' => $isNull ? 'IS NOT' : '!=',
+ 'lt' => '<',
+ 'lte' => '<=',
+ 'gt' => '>',
+ 'gte' => '>=',
+ 'like' => 'LIKE',
+ ];
+
+ $operator = $operatorMapping[$filterField->operator] ?? throw new BadMethodCallException(
+ sprintf('Operator %s is not supported', $filterField->operator)
+ );
+
+ $this->model = $this->model->where(
+ column: $filterField->field,
+ operator: $operator,
+ value: $isNull ? null : $filterField->value,
+ );
+ });
+ }
+ }
+
protected function resetModel(): void
{
$model = $this->getModel();
@@ -357,9 +391,9 @@ abstract class BaseRepository implements RepositoryInterface
* @todo use hydrate method from AbstractDomainObject
*/
private function hydrateDomainObjectFromModel(
- Model $model,
- string $domainObjectOverride = null,
- ?array $relationships = null,
+ Model $model,
+ string $domainObjectOverride = null,
+ ?array $relationships = null,
): DomainObjectInterface
{
/** @var DomainObjectInterface $object */
diff --git a/backend/app/Repository/Eloquent/EventRepository.php b/backend/app/Repository/Eloquent/EventRepository.php
index 6ed407fee..f11c154a3 100644
--- a/backend/app/Repository/Eloquent/EventRepository.php
+++ b/backend/app/Repository/Eloquent/EventRepository.php
@@ -6,13 +6,12 @@ namespace HiEvents\Repository\Eloquent;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\Generated\EventDomainObjectAbstract;
-use HiEvents\DomainObjects\Status\OrderStatus;
+use HiEvents\DomainObjects\Status\EventStatus;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\Event;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
class EventRepository extends BaseRepository implements EventRepositoryInterface
{
@@ -35,6 +34,24 @@ class EventRepository extends BaseRepository implements EventRepositoryInterface
};
}
+ $upcomingEventsFilter = $params->query_params->get('eventsStatus') === 'upcoming';
+
+ if (!empty($params->filter_fields) && !$upcomingEventsFilter) {
+ $this->applyFilterFields($params, EventDomainObject::getAllowedFilterFields());
+ }
+
+ // Apply custom filter for upcoming events, as it keeps things less complex on the front-end
+ if ($upcomingEventsFilter) {
+ $where[] = static function (Builder $builder) {
+ $builder
+ ->where(EventDomainObjectAbstract::STATUS, '!=', EventStatus::ARCHIVED->getName())
+ ->where(function ($query) {
+ $query->whereNull(EventDomainObjectAbstract::END_DATE)
+ ->orWhere(EventDomainObjectAbstract::END_DATE, '>=', now());
+ });
+ };
+ }
+
$this->model = $this->model->orderBy(
$params->sort_by ?? EventDomainObject::getDefaultSort(),
$params->sort_direction ?? EventDomainObject::getDefaultSortDirection(),
diff --git a/backend/app/Services/Handlers/Event/GetEventsHandler.php b/backend/app/Services/Handlers/Event/GetEventsHandler.php
index 75bd572a7..fe79ada05 100644
--- a/backend/app/Services/Handlers/Event/GetEventsHandler.php
+++ b/backend/app/Services/Handlers/Event/GetEventsHandler.php
@@ -9,6 +9,7 @@ use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
use HiEvents\Services\Handlers\Event\DTO\GetEventsDTO;
use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Facades\DB;
class GetEventsHandler
@@ -28,7 +29,7 @@ class GetEventsHandler
))
->findEvents(
where: [
- 'account_id' => $dto->accountId
+ 'account_id' => $dto->accountId,
],
params: $dto->queryParams
);
diff --git a/frontend/src/components/common/ActionMenu/index.tsx b/frontend/src/components/common/ActionMenu/index.tsx
index 1cda6ba76..805227028 100644
--- a/frontend/src/components/common/ActionMenu/index.tsx
+++ b/frontend/src/components/common/ActionMenu/index.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import {Button, Group, Menu} from '@mantine/core';
import {IconDotsVertical} from '@tabler/icons-react';
-interface MenuItem {
+export interface MenuItem {
label: string;
icon: React.ReactNode;
onClick: () => void;
@@ -16,17 +16,21 @@ export interface ActionMenuItemsGroup {
showDividerAbove?: boolean;
}
- interface ActionMenuProps {
+interface ActionMenuProps {
itemsGroups: ActionMenuItemsGroup[];
+ target?: React.ReactNode;
}
-export const ActionMenu: React.FC<ActionMenuProps> = ({itemsGroups}) => {
+export const ActionMenu: React.FC<ActionMenuProps> = ({
+ itemsGroups,
+ target = <IconDotsVertical/>
+ }) => {
return (
<Group wrap={'nowrap'} gap={0} justify={'flex-end'}>
<Menu shadow="md" width={200}>
<Menu.Target>
<Button variant={'transparent'}>
- <IconDotsVertical/>
+ {target}
</Button>
</Menu.Target>
diff --git a/frontend/src/components/common/EventCard/index.tsx b/frontend/src/components/common/EventCard/index.tsx
index 21722f771..0f85f9ef9 100644
--- a/frontend/src/components/common/EventCard/index.tsx
+++ b/frontend/src/components/common/EventCard/index.tsx
@@ -1,4 +1,4 @@
-import {Button, Group, Menu, Text,} from '@mantine/core';
+import {ActionIcon, Button, Group, Text,} from '@mantine/core';
import {Event, IdParam} from "../../../types.ts";
import classes from "./EventCard.module.scss";
import {Card} from "../Card";
@@ -20,6 +20,10 @@ import {EventStatusBadge} from "../EventStatusBadge";
import {useDisclosure} from "@mantine/hooks";
import {DuplicateEventModal} from "../../modals/DuplicateEventModal";
import {useState} from "react";
+import {ActionMenu, MenuItem} from '../ActionMenu/index.tsx';
+import {confirmationDialog} from "../../../utilites/confirmationDialog.tsx";
+import {showError, showSuccess} from "../../../utilites/notifications.tsx";
+import {useUpdateEventStatus} from "../../../mutations/useUpdateEventStatus.ts";
interface EventCardProps {
event: Event;
@@ -29,12 +33,33 @@ export function EventCard({event}: EventCardProps) {
const navigate = useNavigate();
const [isDuplicateModalOpen, duplicateModal] = useDisclosure(false);
const [eventId, setEventId] = useState<IdParam>();
+ const statusToggleMutation = useUpdateEventStatus();
const handleDuplicate = (event: Event) => {
setEventId(() => event.id);
duplicateModal.open();
}
+ const handleStatusToggle = (event: Event) => () => {
+ const message = event?.status !== 'ARCHIVED'
+ ? t`Are you sure you want to archive this event?`
+ : t`Are you sure you want to restore this event? It will be restored as a draft event.`;
+
+ confirmationDialog(message, () => {
+ statusToggleMutation.mutate({
+ eventId: event.id,
+ status: event?.status === 'ARCHIVED' ? 'DRAFT' : 'ARCHIVED'
+ }, {
+ onSuccess: () => {
+ showSuccess(t`Event status updated`);
+ },
+ onError: (error: any) => {
+ showError(error?.response?.data?.message || t`Event status update failed. Please try again later`);
+ }
+ });
+ })
+ }
+
return (
<>
<Card className={classes.card}>
@@ -79,41 +104,55 @@ export function EventCard({event}: EventCardProps) {
</div>
</div>
<div className={classes.actions}>
- <Menu shadow="md" width={200}>
- <Menu.Target>
+ <ActionMenu
+ itemsGroups={[
+ {
+ label: '',
+ items: [
+ {
+ label: t`View event page`,
+ icon: <IconEye size={14}/>,
+ onClick: () => window.location.href = eventHomepagePath(event),
+ },
+ {
+ label: t`Manage event`,
+ icon: <IconSettings size={14}/>,
+ onClick: () => navigate(`/manage/event/${event.id}`),
+ },
+ ((event.lifecycle_status === 'UPCOMING' || event.lifecycle_status === 'ONGOING')
+ && event.status === 'LIVE') && {
+ label: t`Check-in`,
+ icon: <IconQrcode size={14}/>,
+ onClick: () => navigate(`/manage/event/${event.id}/check-in`),
+ visible: true,
+ },
+ {
+ label: t`Duplicate event`,
+ icon: <IconCopy size={14}/>,
+ onClick: () => handleDuplicate(event),
+ },
+ {
+ label: event?.status === 'ARCHIVED' ? t`Restore event` : t`Archive event`,
+ icon: <IconCopy size={14}/>,
+ onClick: handleStatusToggle(event)
+ },
+ ].filter(Boolean) as MenuItem[],
+ },
+ ]}
+ target={
<div>
- <Button className={classes.desktopButton} size={"xs"} variant={"transparent"}>
+ <ActionIcon className={classes.desktopButton} size={"md"} variant={"transparent"}>
<IconDotsVertical/>
- </Button>
+ </ActionIcon>
<Button className={classes.mobileButton} variant={"light"}>
{t`Manage`}
</Button>
</div>
- </Menu.Target>
-
- <Menu.Dropdown>
- <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>
-
- {(event.lifecycle_status === 'UPCOMING' || event.lifecycle_status === 'ONGOING') && (
- <Menu.Item onClick={() => navigate(`/manage/event/${event.id}/check-in`)}
- leftSection={<IconQrcode size={14}/>}
- >{t`Check-in`}</Menu.Item>
- )}
-
- <Menu.Item onClick={() => handleDuplicate(event)}
- leftSection={<IconCopy size={14}/>}
- >{t`Duplicate event`}</Menu.Item>
- </Menu.Dropdown>
- </Menu>
+ }
+ />
</div>
</Card>
{isDuplicateModalOpen && <DuplicateEventModal eventId={eventId} onClose={duplicateModal.close}/>}
</>
);
-}
\ No newline at end of file
+}
diff --git a/frontend/src/components/layouts/CheckIn/index.tsx b/frontend/src/components/layouts/CheckIn/index.tsx
index 52f7d182f..a066b8bd1 100644
--- a/frontend/src/components/layouts/CheckIn/index.tsx
+++ b/frontend/src/components/layouts/CheckIn/index.tsx
@@ -39,7 +39,7 @@ const CheckIn = () => {
query: searchQueryDebounced,
perPage: 100,
filterFields: {
- status: ['ACTIVE'],
+ status: {operator: 'eq', value: 'ACTIVE'},
},
};
const attendeesQuery = useGetCheckInListAttendees(
diff --git a/frontend/src/components/layouts/Event/index.tsx b/frontend/src/components/layouts/Event/index.tsx
index 60703fe34..9ca43851e 100644
--- a/frontend/src/components/layouts/Event/index.tsx
+++ b/frontend/src/components/layouts/Event/index.tsx
@@ -1,7 +1,6 @@
import {Badge, Breadcrumbs, Burger, Button, UnstyledButton, VisuallyHidden} from '@mantine/core';
import {NavLink, Outlet, useParams} from "react-router-dom";
import {
- IconAffiliate,
IconChevronLeft,
IconChevronRight,
IconDashboard,
@@ -16,8 +15,8 @@ import {
IconStar,
IconTicket,
IconUserQuestion,
- IconUsers, IconUsersGroup,
- IconWebhook
+ IconUsers,
+ IconUsersGroup
} from "@tabler/icons-react";
import {useState} from "react";
import classes from './Event.module.scss';
@@ -109,7 +108,6 @@ const EventLayout = () => {
})
}
-
return (
<div id={'event-manage-container'} className={`${classes.container} ${sidebarOpen ? classes.closed : ''}`}>
<div className={`${classes.topBar}`}>
@@ -133,9 +131,9 @@ const EventLayout = () => {
)}
{isEventFetched && (
- <NavLink to={`/manage/event/${event?.id}`}>
- <Truncate length={15} text={event?.title} showTooltip={false}/>
- </NavLink>
+ <NavLink to={`/manage/event/${event?.id}`}>
+ <Truncate length={15} text={event?.title} showTooltip={false}/>
+ </NavLink>
)}
{!isEventFetched && <span>... </span>}
diff --git a/frontend/src/components/routes/events/Dashboard/index.tsx b/frontend/src/components/routes/events/Dashboard/index.tsx
index f3ef3e906..e29265c53 100644
--- a/frontend/src/components/routes/events/Dashboard/index.tsx
+++ b/frontend/src/components/routes/events/Dashboard/index.tsx
@@ -1,9 +1,9 @@
-import {Event, QueryFilters} from "../../../../types.ts";
+import {Event, EventStatus, QueryFilterOperator, QueryFilters} from "../../../../types.ts";
import {useGetEvents} from "../../../../queries/useGetEvents.ts";
import {EventCard} from "../../../common/EventCard";
import {t} from "@lingui/macro";
import {SearchBarWrapper} from "../../../common/SearchBar";
-import {Button, Menu, Skeleton} from "@mantine/core";
+import {Button, Group, Menu, Skeleton} from "@mantine/core";
import {IconCalendarPlus, IconChevronDown, IconPlus, IconUserPlus} from "@tabler/icons-react";
import {ToolBar} from "../../../common/ToolBar";
import {Pagination} from "../../../common/Pagination";
@@ -11,7 +11,7 @@ import {useFilterQueryParamSync} from "../../../../hooks/useFilterQueryParamSync
import {useDisclosure} from "@mantine/hooks";
import {CreateEventModal} from "../../../modals/CreateEventModal";
import {useGetOrganizers} from "../../../../queries/useGetOrganizers.ts";
-import {Navigate} from "react-router-dom";
+import {Navigate, useNavigate, useParams} from "react-router-dom";
import {NoResultsSplash} from "../../../common/NoResultsSplash";
import {CreateOrganizerModal} from "../../../modals/CreateOrganizerModal";
import classes from "./Dashboard.module.scss";
@@ -26,7 +26,50 @@ const DashboardSkeleton = () => {
);
}
+export const getEventQueryFilters = (searchParams: Partial<QueryFilters>) => {
+ const {eventsState, organizerId} = useParams();
+ let filter = {};
+ if (eventsState === 'upcoming' || !eventsState) {
+ filter = {
+ additionalParams: {
+ eventsStatus: 'upcoming',
+ },
+ filterFields: {}
+ };
+ } else if (eventsState === 'ended') {
+ filter = {
+ filterFields: {
+ end_date: {operator: QueryFilterOperator.LessThanOrEquals, value: 'now'},
+ status: {operator: QueryFilterOperator.NotEquals, value: EventStatus.ARCHIVED},
+ }
+ };
+ } else if (eventsState === 'archived') {
+ filter = {
+ filterFields: {
+ status: {operator: QueryFilterOperator.Equals, value: EventStatus.ARCHIVED},
+ }
+ };
+ }
+
+ if (organizerId) {
+ // add the organizer filter on top of the other filters
+ filter = {
+ ...filter,
+ filterFields: {
+ organizer_id: {operator: QueryFilterOperator.Equals, value: organizerId},
+ ...filter.filterFields
+ }
+ }
+ }
+
+ return {
+ ...searchParams,
+ ...filter,
+ };
+}
+
export function Dashboard() {
+ const {eventsState} = useParams();
const [searchParams, setSearchParams] = useFilterQueryParamSync();
const [createModalOpen, {open: openCreateModal, close: closeCreateModal}] = useDisclosure(false);
const [createOrganizerModalOpen, {
@@ -37,19 +80,30 @@ export function Dashboard() {
data: eventData,
isFetched: isEventsFetched,
isFetching: isEventsFetching,
- } = useGetEvents(searchParams as QueryFilters);
+ } = useGetEvents(getEventQueryFilters(searchParams) as QueryFilters);
const organizersQuery = useGetOrganizers();
const pagination = eventData?.meta;
const events = eventData?.data;
const organizers = organizersQuery?.data?.data;
+ const navigate = useNavigate();
if (organizersQuery.isFetched && organizers?.length === 0) {
return <Navigate to={'/welcome'}/>
}
+ const getHeading = () => {
+ if (eventsState === 'upcoming' || !eventsState) {
+ return t`Upcoming Events`;
+ } else if (eventsState === 'ended') {
+ return t`Ended Events`;
+ } else if (eventsState === 'archived') {
+ return t`Archived Events`;
+ }
+ }
+
return (
<div className={classes.eventsContainer}>
- <h1>{t`All Events`}</h1>
+ <h1>{getHeading()}</h1>
<ToolBar searchComponent={() => (
<SearchBarWrapper
@@ -104,6 +158,28 @@ export function Dashboard() {
</>
</ToolBar>
+ <Group mt={10} mb={15}>
+ <Button
+ size={'compact-sm'}
+ variant={eventsState === 'upcoming' || !eventsState ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/events' + window.location.search)}
+ >
+ {t`Upcoming`}
+ </Button>
+ <Button size={'compact-sm'}
+ variant={eventsState === 'ended' ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/events/ended' + window.location.search)}
+ >
+ {t`Ended`}
+ </Button>
+ <Button size={'compact-sm'}
+ variant={eventsState === 'archived' ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/events/archived' + window.location.search)}
+ >
+ {t`Archived`}
+ </Button>
+ </Group>
+
{events?.length === 0 && isEventsFetched && (
<NoResultsSplash
heading={t`No events to show`}
@@ -144,4 +220,4 @@ export function Dashboard() {
);
}
-export default Dashboard;
\ No newline at end of file
+export default Dashboard;
diff --git a/frontend/src/components/routes/organizer/OrganizerDashboard/index.tsx b/frontend/src/components/routes/organizer/OrganizerDashboard/index.tsx
index abcf1bf0f..11549cb25 100644
--- a/frontend/src/components/routes/organizer/OrganizerDashboard/index.tsx
+++ b/frontend/src/components/routes/organizer/OrganizerDashboard/index.tsx
@@ -1,11 +1,11 @@
import {useFilterQueryParamSync} from "../../../../hooks/useFilterQueryParamSync.ts";
import {useDisclosure} from "@mantine/hooks";
import {Event, QueryFilters} from "../../../../types.ts";
-import {NavLink, useParams} from "react-router-dom";
+import {NavLink, useNavigate, useParams} from "react-router-dom";
import {t, Trans} from "@lingui/macro";
import {ToolBar} from "../../../common/ToolBar";
import {SearchBarWrapper} from "../../../common/SearchBar";
-import {Button, Skeleton} from "@mantine/core";
+import {Button, Group, Skeleton} from "@mantine/core";
import {IconArrowLeft, IconCalendarPlus, IconPencil, IconPlus} from "@tabler/icons-react";
import {EventCard} from "../../../common/EventCard";
import {Pagination} from "../../../common/Pagination";
@@ -15,19 +15,22 @@ import {useGetOrganizerEvents} from "../../../../queries/useGetOrganizerEvents.t
import {NoResultsSplash} from "../../../common/NoResultsSplash";
import classes from './OrganizerDashboard.module.scss';
import {EditOrganizerModal} from "../../../modals/EditOrganizerModal";
+import {getEventQueryFilters} from "../../events/Dashboard";
+import {useGetEvents} from "../../../../queries/useGetEvents.ts";
const OrganizerDashboard = () => {
- const {organizerId} = useParams();
+
+ const {organizerId, eventsState} = useParams();
const [searchParams, setSearchParams] = useFilterQueryParamSync();
const [createModalOpen, {open: openCreateModal, close: closeCreateModal}] = useDisclosure(false);
const [editModalOpen, {open: openEditModal, close: closeEditModal}] = useDisclosure(false);
- const {data: eventsData, isFetched: isEventsFetched} = useGetOrganizerEvents(
- organizerId,
- searchParams as QueryFilters
+ const {data: eventsData, isFetched: isEventsFetched} = useGetEvents(
+ getEventQueryFilters(searchParams) as QueryFilters
);
const pagination = eventsData?.meta;
const events = eventsData?.data;
- const {data: organizer, isFetched: isOrganizerFetched} = useGetOrganizer(organizerId)
+ const {data: organizer, isFetched: isOrganizerFetched} = useGetOrganizer(organizerId);
+ const navigate = useNavigate();
return (
<>
@@ -51,7 +54,6 @@ const OrganizerDashboard = () => {
</Button>
</div>
-
<h1 style={{marginTop: '15px'}}>
{isOrganizerFetched && (
<Trans>
@@ -83,6 +85,28 @@ const OrganizerDashboard = () => {
</>
</ToolBar>
+ <Group mt={10} mb={15}>
+ <Button
+ size={'compact-sm'}
+ variant={eventsState === 'upcoming' || !eventsState ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/organizer/' + organizerId + '/events/upcoming' + window.location.search)}
+ >
+ {t`Upcoming`}
+ </Button>
+ <Button size={'compact-sm'}
+ variant={eventsState === 'ended' ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/organizer/' + organizerId + '/events/ended' + window.location.search)}
+ >
+ {t`Ended`}
+ </Button>
+ <Button size={'compact-sm'}
+ variant={eventsState === 'archived' ? 'light' : 'transparent'}
+ onClick={() => navigate('/manage/organizer/' + organizerId + '/events/archived' + window.location.search)}
+ >
+ {t`Archived`}
+ </Button>
+ </Group>
+
{events?.length === 0 && isEventsFetched && (
<NoResultsSplash
heading={t`No events for this organizer`}
@@ -122,4 +146,4 @@ const OrganizerDashboard = () => {
);
}
-export default OrganizerDashboard;
\ No newline at end of file
+export default OrganizerDashboard;
diff --git a/frontend/src/hooks/useFilterQueryParamSync.ts b/frontend/src/hooks/useFilterQueryParamSync.ts
index c85ffc9a0..749cbb261 100644
--- a/frontend/src/hooks/useFilterQueryParamSync.ts
+++ b/frontend/src/hooks/useFilterQueryParamSync.ts
@@ -1,6 +1,6 @@
import {useCallback, useEffect, useState} from 'react';
import {useSearchParams} from 'react-router-dom';
-import {QueryFilters} from "../types.ts";
+import {QueryFilterFields, QueryFilters} from "../types.ts";
const debounce = (func: (newParams: any) => void, delay: number) => {
let timerId: ReturnType<typeof setTimeout> | undefined;
@@ -8,40 +8,71 @@ const debounce = (func: (newParams: any) => void, delay: number) => {
if (timerId) {
clearTimeout(timerId);
}
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
timerId = setTimeout(() => func(...args), delay);
};
};
-export const useFilterQueryParamSync = (): [Partial<QueryFilters>, (updates: Partial<QueryFilters>) => void] => {
+export const useFilterQueryParamSync = (): [Partial<QueryFilters>, (updates: Partial<QueryFilters>, replace?: boolean) => void] => {
const [searchParams, setSearchParams] = useSearchParams();
const [queryParams, setQueryParams] = useState<Partial<QueryFilters>>({});
useEffect(() => {
const parsedParams: Partial<QueryFilters> = {};
searchParams.forEach((value, key) => {
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- parsedParams[key as keyof QueryFilters] = value;
+ if (key.startsWith('filterFields[')) {
+ const match = key.match(/^filterFields\[(.+)\]\[(.+)\]$/);
+ if (match) {
+ const [_, fieldName, operator] = match;
+ // @ts-ignore
+ parsedParams.filterFields = {
+ ...parsedParams.filterFields,
+ [fieldName]: {operator, value},
+ };
+ }
+ } else {
+ // @ts-ignore
+ parsedParams[key as keyof QueryFilters] = value;
+ }
});
setQueryParams(parsedParams);
}, [searchParams]);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- const debouncedSetSearchParams = useCallback(debounce((newParams: URLSearchParams) => {
- setSearchParams(newParams);
- }, 300), [setSearchParams]);
+ const debouncedSetSearchParams = useCallback(
+ debounce((newParams: URLSearchParams) => {
+ setSearchParams(newParams);
+ }, 300),
+ [setSearchParams]
+ );
- const updateSearchParam = useCallback((updates: Partial<QueryFilters>) => {
- debouncedSetSearchParams((prevParams: URLSearchParams) => {
- const updatedParams = new URLSearchParams(prevParams);
- Object.entries(updates).forEach(([key, value]) => {
- updatedParams.set(key, String(value));
+ const updateSearchParam = useCallback(
+ (updates: Partial<QueryFilters>, replace: boolean = false) => {
+ debouncedSetSearchParams((prevParams: URLSearchParams) => {
+ const updatedParams = replace ? new URLSearchParams() : new URLSearchParams(prevParams);
+
+ Object.entries(updates).forEach(([key, value]) => {
+ if (key === 'filterFields' && typeof value === 'object') {
+ Object.entries(value as QueryFilterFields).forEach(([field, condition]) => {
+ if (Array.isArray(condition)) {
+ condition.forEach((cond) => {
+ const paramKey = `filterFields[${field}][${cond.operator}]`;
+ updatedParams.set(paramKey, String(cond.value));
+ });
+ } else if (condition) {
+ const paramKey = `filterFields[${field}][${condition.operator}]`;
+ updatedParams.set(paramKey, String(condition.value));
+ }
+ });
+ } else {
+ updatedParams.set(key, String(value));
+ }
+ });
+
+ return updatedParams;
});
- return updatedParams;
- });
- }, [debouncedSetSearchParams]);
+ },
+ [debouncedSetSearchParams]
+ );
return [queryParams, updateSearchParam];
};
diff --git a/frontend/src/mutations/useUpdateEventStatus.ts b/frontend/src/mutations/useUpdateEventStatus.ts
index 4cf62ef5b..9bbc50f04 100644
--- a/frontend/src/mutations/useUpdateEventStatus.ts
+++ b/frontend/src/mutations/useUpdateEventStatus.ts
@@ -2,6 +2,7 @@ import {eventsClient} from "../api/event.client.ts";
import {useMutation, useQueryClient} from "@tanstack/react-query";
import {IdParam} from "../types.ts";
import {GET_EVENT_QUERY_KEY} from "../queries/useGetEvent.ts";
+import {GET_EVENTS_QUERY_KEY} from "../queries/useGetEvents.ts";
export const useUpdateEventStatus = () => {
const queryClient = useQueryClient();
@@ -14,7 +15,8 @@ export const useUpdateEventStatus = () => {
{
onSuccess: (_, variables) => {
queryClient.invalidateQueries([GET_EVENT_QUERY_KEY, variables.eventId]);
+ queryClient.invalidateQueries([GET_EVENTS_QUERY_KEY]);
}
}
)
-}
\ No newline at end of file
+}
diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx
index 0d4212db7..2b0c6a20f 100644
--- a/frontend/src/router.tsx
+++ b/frontend/src/router.tsx
@@ -80,14 +80,14 @@ export const router: RouteObject[] = [
},
children: [
{
- path: "events",
+ path: "events/:eventsState?",
async lazy() {
const Dashboard = await import("./components/routes/events/Dashboard");
return {Component: Dashboard.default};
- }
+ },
},
{
- path: "organizer/:organizerId",
+ path: "organizer/:organizerId/events?/:eventsState?",
async lazy() {
const OrganizerDashboard = await import("./components/routes/organizer/OrganizerDashboard");
return {Component: OrganizerDashboard.default};
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 99e1e9f57..e4ab59d6e 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -139,12 +139,25 @@ export interface EventDuplicatePayload extends EventBase {
duplicate_settings: boolean;
}
+export enum EventStatus {
+ DRAFT = 'DRAFT',
+ LIVE = 'LIVE',
+ PAUSED = 'PAUSED',
+ ARCHIVED = 'ARCHIVED'
+}
+
+export enum EventLifecycleStatus {
+ ONGOING = 'ONGOING',
+ UPCOMING = 'UPCOMING',
+ ENDED = 'ENDED'
+}
+
export interface Event extends EventBase {
id?: IdParam;
slug: string;
- status?: 'DRAFT' | 'LIVE' | 'PAUSED';
+ status?: EventStatus;
description_preview?: string;
- lifecycle_status?: 'ONGOING' | 'UPCOMING' | 'ENDED';
+ lifecycle_status?: EventLifecycleStatus;
settings?: EventSettings;
tickets?: Ticket[];
images?: Image[];
@@ -437,7 +450,9 @@ export interface CheckInList {
}[];
}
-export type CheckInListRequest = Omit<CheckInList, 'event_id' | 'short_id' | 'id' | 'tickets' | 'total_attendees' | 'checked_in_attendees' | 'is_expired' | 'is_active'> & {
+export type CheckInListRequest =
+ Omit<CheckInList, 'event_id' | 'short_id' | 'id' | 'tickets' | 'total_attendees' | 'checked_in_attendees' | 'is_expired' | 'is_active'>
+ & {
ticket_ids: IdParam[];
};
@@ -492,17 +507,36 @@ export enum QuestionBelongsToType {
ORDER = 'ORDER',
}
+export enum QueryFilterOperator {
+ Equals = 'eq',
+ NotEquals = 'ne',
+ GreaterThan = 'gt',
+ GreaterThanOrEquals = 'gte',
+ LessThan = 'lt',
+ LessThanOrEquals = 'lte',
+ Like = 'like',
+ NotLike = 'not_like',
+}
+
+export type QueryFilterValue = string | number | boolean;
+
+export type QueryFilterCondition = {
+ operator: QueryFilterOperator;
+ value: QueryFilterValue;
+};
+
export type QueryFilterFields = {
- [key: string]: string | string[] | number | number[] | boolean | boolean[] | undefined;
+ [key: string]: QueryFilterCondition | QueryFilterCondition[] | undefined;
}
export interface QueryFilters {
- pageNumber: number;
+ pageNumber?: number;
perPage?: number;
query?: string;
sortBy?: string;
sortDirection?: string;
filterFields?: QueryFilterFields;
+ additionalParams?: Record<string, any>;
}
export interface GenericModalProps {
diff --git a/frontend/src/utilites/queryParamsHelper.ts b/frontend/src/utilites/queryParamsHelper.ts
index d0b0a2597..aadfd8fef 100644
--- a/frontend/src/utilites/queryParamsHelper.ts
+++ b/frontend/src/utilites/queryParamsHelper.ts
@@ -1,4 +1,4 @@
-import {QueryFilterFields, QueryFilters} from "../types.ts";
+import {QueryFilterCondition, QueryFilters} from "../types.ts";
export const queryParamsHelper = {
PER_PAGE_PARAM: "per_page",
@@ -28,7 +28,7 @@ export const queryParamsHelper = {
* @example "?per_page=10&page=1"
*/
buildQueryString: (
- {pageNumber, perPage, query, sortBy, sortDirection, filterFields = {}}: QueryFilters
+ {pageNumber, perPage, query, sortBy, sortDirection, filterFields = {}, additionalParams = {}}: QueryFilters
): string => {
const baseParams: any = {
[queryParamsHelper.PAGE_PARAM]: pageNumber ||
@@ -47,12 +47,27 @@ export const queryParamsHelper = {
queryParamsHelper.getParam(queryParamsHelper.SORT_DIRECTION_PARAM, ''),
};
- const filterParams = Object.entries(filterFields).reduce<QueryFilterFields>((acc, [key, value]) => {
- acc[`filter_fields[${key}]`] = value;
+ const filterParams = Object.entries(filterFields).reduce<Record<string, string>>((acc, [key, value]) => {
+ if (Array.isArray(value)) {
+ value.forEach((condition: QueryFilterCondition) => {
+ const paramKey = `filter_fields[${key}][${condition.operator}]`;
+ acc[paramKey] = String(condition.value);
+ });
+ } else if (typeof value === 'object' && value !== null) {
+ const condition = value as QueryFilterCondition;
+ const paramKey = `filter_fields[${key}][${condition.operator}]`;
+ acc[paramKey] = String(condition.value);
+ }
return acc;
}, {});
- const combinedParams = { ...baseParams, ...filterParams };
+ const additionalParamsProcessed = Object.entries(additionalParams).reduce<Record<string, string>>((acc, [key, value]) => {
+ acc[key] = String(value);
+ return acc;
+ }, {});
+
+ const combinedParams = {...baseParams, ...filterParams, ...additionalParamsProcessed};
- return '?' + new URLSearchParams(combinedParams).toString(); }
+ return '?' + new URLSearchParams(combinedParams).toString();
+ }
};