cal/packages/lib/convertToNewDurationType.ts

28 lines
927 B
TypeScript
Raw Normal View History

Minimum booking notice will allow hours and days (#5217) * minimum booking notice allows hours and days * Fixed error with Prisma not updating properly and input changing value to minutes autmatically * fix type error * Update apps/web/components/v2/eventtype/EventLimitsTab.tsx Co-authored-by: Peer Richelsen <peer@cal.com> * moved minimumBookingNotice to clientside, removed migration from prisma, changed DurationField to regular InputField * Update packages/lib/convertMinimumBookingNoticeToMinutes.ts Co-authored-by: alannnc <alannnc@gmail.com> * added MINUTES_IN_HOUR, MINUTES_IN_DAY, and HOURS_IN_DAY as exportable consts * Fix some comparison, mobile styles and const usages * minimumBookingNotice values will never be floats * fixed issue with minbookingnotice not updating properly in prisma * Removed console.logs, converted minimumBookingNoticeType to ref, removed unreliable accessing of array * remove yarn lockfile * Revert "remove yarn lockfile" This reverts commit fefc24c80269f5445c8eb7a640e2816d7d8b0407. * Revert "Revert "remove yarn lockfile"" This reverts commit c8cc4d3c0eddb2c91d077d2277ad5ea10315ec95. * Replaced currentDurationType export with state passed down from parent * Improvements for duration notice type logic * Undo adding submodule updates * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> * Update packages/lib/findDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * remove passing in as object * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Delete convertMinimumBookingNoticeToMinutes.ts * Syntax fix Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: alannnc <alannnc@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com>
2022-11-14 06:12:28 -03:00
export const MINUTES_IN_HOUR = 60;
export const MINUTES_IN_DAY = 1440;
export const HOURS_IN_DAY = 24;
export type DurationType = "minutes" | "hours" | "days";
export default function convertToNewDurationType(
prevType: DurationType,
newType: DurationType,
prevValue: number
) {
/** Convert `prevValue` from `prevType` to `newType` */
const newDurationTypeMap = {
minutes_minutes: () => prevValue,
minutes_hours: () => prevValue / MINUTES_IN_HOUR,
minutes_days: () => prevValue / MINUTES_IN_DAY,
hours_minutes: () => prevValue * MINUTES_IN_HOUR,
Minimum booking notice will allow hours and days (#5217) * minimum booking notice allows hours and days * Fixed error with Prisma not updating properly and input changing value to minutes autmatically * fix type error * Update apps/web/components/v2/eventtype/EventLimitsTab.tsx Co-authored-by: Peer Richelsen <peer@cal.com> * moved minimumBookingNotice to clientside, removed migration from prisma, changed DurationField to regular InputField * Update packages/lib/convertMinimumBookingNoticeToMinutes.ts Co-authored-by: alannnc <alannnc@gmail.com> * added MINUTES_IN_HOUR, MINUTES_IN_DAY, and HOURS_IN_DAY as exportable consts * Fix some comparison, mobile styles and const usages * minimumBookingNotice values will never be floats * fixed issue with minbookingnotice not updating properly in prisma * Removed console.logs, converted minimumBookingNoticeType to ref, removed unreliable accessing of array * remove yarn lockfile * Revert "remove yarn lockfile" This reverts commit fefc24c80269f5445c8eb7a640e2816d7d8b0407. * Revert "Revert "remove yarn lockfile"" This reverts commit c8cc4d3c0eddb2c91d077d2277ad5ea10315ec95. * Replaced currentDurationType export with state passed down from parent * Improvements for duration notice type logic * Undo adding submodule updates * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> * Update packages/lib/findDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * remove passing in as object * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Delete convertMinimumBookingNoticeToMinutes.ts * Syntax fix Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: alannnc <alannnc@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com>
2022-11-14 06:12:28 -03:00
hours_hours: () => prevValue,
hours_days: () => prevValue * HOURS_IN_DAY,
days_minutes: () => prevValue * MINUTES_IN_DAY,
days_hours: () => prevValue * HOURS_IN_DAY,
Minimum booking notice will allow hours and days (#5217) * minimum booking notice allows hours and days * Fixed error with Prisma not updating properly and input changing value to minutes autmatically * fix type error * Update apps/web/components/v2/eventtype/EventLimitsTab.tsx Co-authored-by: Peer Richelsen <peer@cal.com> * moved minimumBookingNotice to clientside, removed migration from prisma, changed DurationField to regular InputField * Update packages/lib/convertMinimumBookingNoticeToMinutes.ts Co-authored-by: alannnc <alannnc@gmail.com> * added MINUTES_IN_HOUR, MINUTES_IN_DAY, and HOURS_IN_DAY as exportable consts * Fix some comparison, mobile styles and const usages * minimumBookingNotice values will never be floats * fixed issue with minbookingnotice not updating properly in prisma * Removed console.logs, converted minimumBookingNoticeType to ref, removed unreliable accessing of array * remove yarn lockfile * Revert "remove yarn lockfile" This reverts commit fefc24c80269f5445c8eb7a640e2816d7d8b0407. * Revert "Revert "remove yarn lockfile"" This reverts commit c8cc4d3c0eddb2c91d077d2277ad5ea10315ec95. * Replaced currentDurationType export with state passed down from parent * Improvements for duration notice type logic * Undo adding submodule updates * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> * Update packages/lib/findDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Update apps/web/components/eventtype/EventLimitsTab.tsx Co-authored-by: Omar López <zomars@me.com> * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * remove passing in as object * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López <zomars@me.com> * Update packages/lib/convertToNewDurationType.ts Co-authored-by: Omar López <zomars@me.com> * Delete convertMinimumBookingNoticeToMinutes.ts * Syntax fix Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: alannnc <alannnc@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com>
2022-11-14 06:12:28 -03:00
days_days: () => prevValue,
};
const getNewValue = newDurationTypeMap[`${prevType}_${newType}`];
const newValue = getNewValue();
return Math.ceil(newValue);
}