diff --git a/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.module.scss b/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.module.scss index 8369434ec..39683bbdd 100644 --- a/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.module.scss +++ b/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.module.scss @@ -74,6 +74,39 @@ margin-top: 1.5em; } +.field_label_row { + @include flex-row; + align-items: baseline; + justify-content: space-between; + gap: 0.5em; +} + +.mode_switch_row { + @include flex-row; + align-items: center; + gap: 0.5em; + margin-bottom: 0.25em; +} + +.mode_label { + font-size: 0.82em; + color: $grey-3; + transition: color 0.15s; +} + +.mode_label_active { + font-size: 0.82em; + font-weight: 600; + transition: color 0.15s; +} + +.conversion_hint { + display: block; + font-size: 0.78em; + color: $grey-3; + margin-top: 0.2em; +} + .preview { @include flex-row-center; align-items: center; diff --git a/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.tsx b/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.tsx index eb42ad5ba..20baa8584 100644 --- a/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.tsx +++ b/frontend/src/PagesAdmin/EventCreatorAdminPage/EventCreatorAdminPage.tsx @@ -20,6 +20,7 @@ import { ImageCard, Input, Textarea, + ToggleSwitch, } from '~/Components'; import type { DropdownOption } from '~/Components/Dropdown/Dropdown'; import { ImagePicker } from '~/Components/ImagePicker/ImagePicker'; @@ -149,6 +150,29 @@ export function EventCreatorAdminPage() { } }, [id, t, form]); + // ================================== // + // Duration / End-time mode // + // ================================== // + + const [durationMode, setDurationMode] = useState(true); + + const watchStartDt = form.watch('start_dt'); + const watchDuration = form.watch('duration'); + const watchEndDt = form.watch('end_dt'); + + useEffect(() => { + if (durationMode && watchStartDt && watchDuration > 0) { + const start = new Date(watchStartDt); + const end = new Date(start.getTime() + watchDuration * 60_000); + form.setValue('end_dt', utcTimestampToLocal(end.toISOString(), false)); + } else if (!durationMode && watchStartDt && watchEndDt) { + const start = new Date(watchStartDt); + const end = new Date(watchEndDt); + const diffMin = Math.round((end.getTime() - start.getTime()) / 60_000); + form.setValue('duration', Math.max(0, diffMin)); + } + }, [watchStartDt, watchDuration, watchEndDt, durationMode, form]); + // ================================== // // Creation Steps // // ================================== // @@ -284,7 +308,8 @@ export function EventCreatorAdminPage() { title_nb: 'Dato og informasjon', title_en: 'Date & info', validate: (data) => { - return !!(data.start_dt && data.duration > 0 && data.category && data.host && data.location); + const timeValid = durationMode ? !!(data.start_dt && data.duration > 0) : !!(data.start_dt && data.end_dt); + return timeValid && !!(data.category && data.host && data.location); }, template: ( <> @@ -305,26 +330,57 @@ export function EventCreatorAdminPage() { )} /> - ( - - - {t(KEY.recruitment_duration)} ({t(KEY.common_minutes)}) - - - field.onChange(Number.parseInt(e.target.value) || 0)} - /> - - - - )} - /> + {durationMode ? ( + ( + +
+ + {t(KEY.recruitment_duration)} ({t(KEY.common_minutes)}) + +
+ {t(KEY.recruitment_duration)} + setDurationMode((prev) => !prev)} /> + {t(KEY.end_time)} +
+
+ + field.onChange(Number.parseInt(e.target.value) || 0)} + /> + + +
+ )} + /> + ) : ( + ( + +
+ {t(KEY.end_time)} +
+ {t(KEY.recruitment_duration)} + setDurationMode((prev) => !prev)} /> + {t(KEY.end_time)} +
+
+ + + + +
+ )} + /> + )}
= { ...values, visibility_to_dt: computedEndDt ? computedEndDt.toISOString() : '',