Skip to content

Admin booking filter 2#151

Merged
zachchong merged 6 commits intomasterfrom
feature/admin-booking-filter
Jan 3, 2026
Merged

Admin booking filter 2#151
zachchong merged 6 commits intomasterfrom
feature/admin-booking-filter

Conversation

@Shum-ster
Copy link
Copy Markdown
Contributor

@Shum-ster Shum-ster commented Jan 3, 2026

  • Fix frontend test error
  • Status filter
  • Date range shortcuts

@Shum-ster Shum-ster requested a review from zachchong January 3, 2026 14:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the admin booking filter by adding a status filter dropdown and replacing the date input field with date range shortcuts. It also addresses a frontend test error.

  • Added status filter with "Approved", "Pending", and "Rejected" options
  • Replaced date input with dropdown shortcuts (Tomorrow, Next week, Last month, etc.)
  • Implemented date range filtering that filters bookings between selected date and today

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
frontend/src/custom-hooks/use-table-state-admin.ts Added FilterableItem interface, status filter logic, and date range filtering using date-fns interval functions
frontend/src/components/admin-search-bar/admin-search-bar.tsx Added status dropdown, replaced date input with date shortcut dropdown, implemented date change handler with preset calculations
frontend/src/components/admin-search-bar/admin-search-bar.module.scss Adjusted flex sizing for filter inputs to accommodate additional status filter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
interface FilterableItem {
title?: string;
venue?: {
name?: string;
} | null;
date?: string;
status?: string;
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FilterableItem interface defines a date property, but the actual booking data uses eventDateString as the property name (as seen in booking-admin-table.tsx where EVENT_DATE_STRING is populated). This mismatch will cause the date filtering to fail since item.date will be undefined. The interface should define eventDateString?: string; instead of date?: string;, or the filtering logic should check for the correct property name.

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +80
if (!item.date) return false;

const itemDate = parse(item.date, DATE_FORMAT, new Date());

const start = startOfDay(filterDate < today ? filterDate : today);
const end = endOfDay(filterDate > today ? filterDate : today);

return isWithinInterval(itemDate, { start, end });
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date filtering logic checks item.date, but the actual property name in the booking data is eventDateString (as defined in constants and used in the booking table). This will cause the filter to always return false for items, making the date filter non-functional. The code should check item.eventDateString instead.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +55
return data.filter((datum) => {
const item = datum;
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable item is assigned from datum without any transformation or purpose. This is redundant and adds no value. Either use datum directly throughout the filter function or remove this assignment.

Suggested change
return data.filter((datum) => {
const item = datum;
return data.filter((item) => {

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +180
const currentShortcutValue = useMemo(() => {
if (!filters.date) return "";
const today = new Date();
const target = filters.date;

if (target === format(addDays(today, 1), "yyyy-MM-dd")) return "tomorrow";
if (target === format(addDays(today, 3), "yyyy-MM-dd")) return "next3days";
if (target === format(addWeeks(today, 1), "yyyy-MM-dd")) return "nextweek";
if (target === format(addWeeks(today, 2), "yyyy-MM-dd")) return "next2weeks";
if (target === format(addMonths(today, 1), "yyyy-MM-dd")) return "nextmonth";
if (target === format(addMonths(today, 3), "yyyy-MM-dd")) return "next3months";
if (target === format(addYears(today, 1), "yyyy-MM-dd")) return "nextyear";
if (target === format(subDays(today, 1), "yyyy-MM-dd")) return "yesterday";
if (target === format(subDays(today, 3), "yyyy-MM-dd")) return "last3days";
if (target === format(subWeeks(today, 1), "yyyy-MM-dd")) return "lastweek";
if (target === format(subWeeks(today, 2), "yyyy-MM-dd")) return "last2weeks";
if (target === format(subMonths(today, 1), "yyyy-MM-dd")) return "lastmonth";
if (target === format(subMonths(today, 3), "yyyy-MM-dd")) return "last3months";
if (target === format(subYears(today, 1), "yyyy-MM-dd")) return "lastyear";

return "";
}, [filters.date]);
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The currentShortcutValue computation performs multiple date calculations and format operations on every render. While it's memoized with useMemo, the calculation itself is still expensive with 14 conditional branches. Consider extracting this logic into a helper function or simplifying by storing the shortcut value directly in state when a shortcut is selected, rather than reverse-engineering it from the date string.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +78
const today = new Date();

if (!item.date) return false;

const itemDate = parse(item.date, DATE_FORMAT, new Date());

const start = startOfDay(filterDate < today ? filterDate : today);
const end = endOfDay(filterDate > today ? filterDate : today);
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date range logic creates an interval from the earlier of filterDate or today to the later of the two. This means selecting "Tomorrow" filters bookings between today and tomorrow, while "Yesterday" filters bookings between yesterday and today. This range-based filtering behavior is not intuitive given the shortcut names like "Tomorrow" or "Yesterday" which suggest single-day filtering. Consider clarifying the intended behavior: if these shortcuts should filter for a specific day, use a single-day range instead; if they should filter for ranges, consider renaming the shortcuts to be more explicit (e.g., "Through Tomorrow", "Since Yesterday").

Suggested change
const today = new Date();
if (!item.date) return false;
const itemDate = parse(item.date, DATE_FORMAT, new Date());
const start = startOfDay(filterDate < today ? filterDate : today);
const end = endOfDay(filterDate > today ? filterDate : today);
if (!item.date) return false;
const itemDate = parse(item.date, DATE_FORMAT, new Date());
const start = startOfDay(filterDate);
const end = endOfDay(filterDate);

Copilot uses AI. Check for mistakes.
@zachchong zachchong merged commit 475b96f into master Jan 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants