Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -148,6 +148,14 @@ export function EventCreatorAdminPage() {
setShowSpinner(false);
}
}, [id, t, form]);
const startDt = form.watch('start_dt');
const visibilityFromDt = form.watch('visibility_from_dt');

useEffect(() => {
if (startDt && visibilityFromDt) {
form.trigger('visibility_from_dt');
}
}, [startDt, visibilityFromDt, form]);

// ================================== //
// Creation Steps //
Expand Down Expand Up @@ -475,7 +483,13 @@ export function EventCreatorAdminPage() {
title_en: 'Summary',
customIcon: 'ic:outline-remove-red-eye',
validate: (data) => {
return !!data.visibility_from_dt;
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 @@ -25,34 +25,45 @@ const event_custom_ticket = z.object({
name_en: z.string().min(1),
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,
});
// 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 (data.visibility_from_dt && data.start_dt) {
return new Date(data.visibility_from_dt) <= new Date(data.start_dt);
}
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>;