diff --git a/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx b/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx index ca200b5c4..511dd8325 100644 --- a/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx +++ b/apps/web/src/components/forms/poll-options-form/month-calendar/month-calendar.tsx @@ -150,6 +150,7 @@ const MonthCalendar: React.FunctionComponent = ({ : { type: "timeSlot", start: formatDateWithoutTz(selectedDate), + duration, end: formatDateWithoutTz( dayjs(selectedDate) .add(duration, "minutes") @@ -225,6 +226,7 @@ const MonthCalendar: React.FunctionComponent = ({ return { type: "timeSlot", start: formatDateWithoutTz(startDate), + duration: duration, end: formatDateWithoutTz(endDate), }; }), @@ -346,6 +348,7 @@ const MonthCalendar: React.FunctionComponent = ({ { type: "timeSlot", start: startTime, + duration, end: formatDateWithoutTz( dayjs(new Date(startTime)) .add(duration, "minutes") @@ -382,6 +385,7 @@ const MonthCalendar: React.FunctionComponent = ({ startTime: option.start.substring( option.start.indexOf("T"), ), + duration: option.duration, endTime: option.end.substring( option.end.indexOf("T"), ), @@ -392,10 +396,15 @@ const MonthCalendar: React.FunctionComponent = ({ Object.keys(optionsByDay).forEach( (dateString) => { times.forEach((time) => { + const start = + dateString + time.startTime; newOptions.push({ type: "timeSlot", - start: dateString + time.startTime, - end: dateString + time.endTime, + start: start, + duration, + end: dayjs(start) + .add(duration, "minutes") + .format("YYYY-MM-DDTHH:mm"), }); }); }, diff --git a/apps/web/src/components/forms/poll-options-form/types.ts b/apps/web/src/components/forms/poll-options-form/types.ts index efcaf6804..510b45bce 100644 --- a/apps/web/src/components/forms/poll-options-form/types.ts +++ b/apps/web/src/components/forms/poll-options-form/types.ts @@ -6,6 +6,7 @@ export type DateOption = { export type TimeOption = { type: "timeSlot"; start: string; + duration: number; end: string; }; diff --git a/apps/web/src/components/forms/poll-options-form/week-calendar.tsx b/apps/web/src/components/forms/poll-options-form/week-calendar.tsx index b917af0a9..e4a0b1523 100644 --- a/apps/web/src/components/forms/poll-options-form/week-calendar.tsx +++ b/apps/web/src/components/forms/poll-options-form/week-calendar.tsx @@ -157,6 +157,7 @@ const WeekCalendar: React.FunctionComponent = ({ const newEvent: DateTimeOption = { type: "timeSlot", start: formatDateWithoutTz(startDate), + duration: dayjs(endDate).diff(endDate, "minutes"), end: formatDateWithoutTz(endDate), }; diff --git a/apps/web/src/pages/poll/[urlId]/edit-options.tsx b/apps/web/src/pages/poll/[urlId]/edit-options.tsx index 0410b69c8..4412dbaf8 100644 --- a/apps/web/src/pages/poll/[urlId]/edit-options.tsx +++ b/apps/web/src/pages/poll/[urlId]/edit-options.tsx @@ -67,6 +67,7 @@ const Page: NextPageWithLayout = () => { ? { type: "timeSlot", start: start.format("YYYY-MM-DDTHH:mm:ss"), + duration: option.duration, end: start .add(option.duration, "minute") .format("YYYY-MM-DDTHH:mm:ss"), diff --git a/apps/web/src/utils/date-time-utils.ts b/apps/web/src/utils/date-time-utils.ts index 3410f4128..0c8821030 100644 --- a/apps/web/src/utils/date-time-utils.ts +++ b/apps/web/src/utils/date-time-utils.ts @@ -40,8 +40,6 @@ export interface ParsedTimeSlotOption { export type ParsedDateTimeOpton = ParsedDateOption | ParsedTimeSlotOption; -const isTimeSlot = (value: string) => value.indexOf("/") !== -1; - export const getDuration = (startTime: dayjs.Dayjs, endTime: dayjs.Dayjs) => { const hours = Math.floor(endTime.diff(startTime, "hours")); const minutes = Math.floor(endTime.diff(startTime, "minute") - hours * 60); @@ -157,19 +155,3 @@ export const expectTimeOption = (d: DateTimeOption): TimeOption => { } return d; }; - -export const parseValue = (value: string): DateTimeOption => { - if (isTimeSlot(value)) { - const [start, end] = value.split("/"); - return { - type: "timeSlot", - start, - end, - }; - } else { - return { - type: "date", - date: value, - }; - } -};