Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ export function EventCreatorAdminPage() {
}
}, [id, t, form]);

// Watch for changes to date fields and trigger validation
Comment thread
leaesc marked this conversation as resolved.
Outdated
const startDt = form.watch('start_dt');
const visibilityFromDt = form.watch('visibility_from_dt');

useEffect(() => {
// Trigger validation on visibility_from_dt whenever either date changes
Comment thread
eilifhl marked this conversation as resolved.
Outdated
if (startDt && visibilityFromDt) {
form.trigger('visibility_from_dt');
}
}, [startDt, visibilityFromDt, form]);

// ================================== //
// Creation Steps //
// ================================== //
Expand Down Expand Up @@ -475,7 +486,14 @@ export function EventCreatorAdminPage() {
title_en: 'Summary',
customIcon: 'ic:outline-remove-red-eye',
validate: (data) => {
return !!data.visibility_from_dt;
// Check that publication date exists and is before event start
Comment thread
eilifhl marked this conversation as resolved.
Outdated
if (!data.visibility_from_dt) {
return false;
}
if (data.start_dt && new Date(data.visibility_from_dt) > new Date(data.start_dt)) {
return false;
}
return true;
},
template: (
<FormField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,48 @@ const event_custom_ticket = z.object({
price: z.number().min(0),
});

export const eventSchema = z.object({
// text and description
title_nb: EVENT_TITLE,
title_en: EVENT_TITLE,
description_long_nb: EVENT_DESCRIPTION_LONG,
description_long_en: EVENT_DESCRIPTION_LONG,
description_short_nb: EVENT_DESCRIPTION_SHORT,
description_short_en: EVENT_DESCRIPTION_SHORT,
// Date and information
start_dt: EVENT_START_DT,
duration: EVENT_DURATION,
end_dt: EVENT_END_DT,
category: EVENT_CATEGORY,
host: EVENT_HOST,
location: EVENT_LOCATION,
capacity: EVENT_CAPACITY,
// Payment/registration
age_restriction: EVENT_AGE_RESTRICTION,
ticket_type: EVENT_TICKET_TYPE,
custom_tickets: z.array(event_custom_ticket).optional(),
registration_url: EVENT_REGISTRATION_URL,
billig_id: EVENT_BILLIG_ID,
// Graphics
image: OPTIONAL_IMAGE,
// Summary/Publication date
visibility_from_dt: EVENT_VISIBILITY_FROM_DT,
visibility_to_dt: EVENT_VISIBILITY_TO_DT,
});
export const eventSchema = z
Comment thread
eilifhl marked this conversation as resolved.
Outdated
.object({
// text and description
title_nb: EVENT_TITLE,
title_en: EVENT_TITLE,
description_long_nb: EVENT_DESCRIPTION_LONG,
description_long_en: EVENT_DESCRIPTION_LONG,
description_short_nb: EVENT_DESCRIPTION_SHORT,
description_short_en: EVENT_DESCRIPTION_SHORT,
// Date and information
start_dt: EVENT_START_DT,
duration: EVENT_DURATION,
end_dt: EVENT_END_DT,
category: EVENT_CATEGORY,
host: EVENT_HOST,
location: EVENT_LOCATION,
capacity: EVENT_CAPACITY,
// Payment/registration
age_restriction: EVENT_AGE_RESTRICTION,
ticket_type: EVENT_TICKET_TYPE,
custom_tickets: z.array(event_custom_ticket).optional(),
registration_url: EVENT_REGISTRATION_URL,
billig_id: EVENT_BILLIG_ID,
// Graphics
image: OPTIONAL_IMAGE,
// Summary/Publication date
visibility_from_dt: EVENT_VISIBILITY_FROM_DT,
visibility_to_dt: EVENT_VISIBILITY_TO_DT,
})
.refine(
(data) => {
// If visibility_from_dt and start_dt are both provided, check that publication date is before event start
Comment thread
eilifhl marked this conversation as resolved.
Outdated
if (data.visibility_from_dt && data.start_dt) {
return new Date(data.visibility_from_dt) <= new Date(data.start_dt);
}
// If either is missing, allow it (will be caught by individual field validation)
Comment thread
eilifhl marked this conversation as resolved.
Outdated
return true;
},
{
message: 'Publication date must be before event start date!',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can add tranlations to this message with new changes in master. See frontend/src/schema/event.ts in master for an example.

path: ['visibility_from_dt'], // Show error on the publication date field
},
);

export type EventFormType = z.infer<typeof eventSchema>;
Loading