From f27b0b3cad2c4bf7e9e02f894a705ff6e2dcd2ed Mon Sep 17 00:00:00 2001 From: Mihai C <34626017+mihaic195@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:17:25 +0300 Subject: [PATCH] fix: availability creation and expand/collapse settings (#882) * fix: availability creation and expand/collapse settings * additional fixes * Update pages/api/availability/eventtype.ts Co-authored-by: Alex Johansson * update branch * fix: more fixes Co-authored-by: Alex Johansson Co-authored-by: Bailey Pumfleet Co-authored-by: Mihai Colceriu --- lib/core/i18n/i18n.utils.ts | 1 + lib/types/event-type.ts | 4 +++ next-i18next.config.js | 2 +- pages/api/availability/eventtype.ts | 9 +++++ pages/event-types/[type].tsx | 45 ++++++++++++++++--------- public/static/locales/pt-BR/common.json | 1 + 6 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 public/static/locales/pt-BR/common.json diff --git a/lib/core/i18n/i18n.utils.ts b/lib/core/i18n/i18n.utils.ts index c9c97633..9de04f1d 100644 --- a/lib/core/i18n/i18n.utils.ts +++ b/lib/core/i18n/i18n.utils.ts @@ -73,6 +73,7 @@ export const localeLabels: localeType = { pt: "Portuguese", ro: "Romanian", nl: "Dutch", + "pt-BR": "Portuguese (Brazilian)", }; export type OptionType = { diff --git a/lib/types/event-type.ts b/lib/types/event-type.ts index 900d924a..a535e0c0 100644 --- a/lib/types/event-type.ts +++ b/lib/types/event-type.ts @@ -30,6 +30,10 @@ export type AdvancedOptions = { label: string; avatar: string; }[]; + availability?: { openingHours: OpeningHours[]; dateOverrides: DateOverride[] }; + customInputs?: EventTypeCustomInput[]; + timeZone: string; + hidden: boolean; }; export type EventTypeCustomInput = { diff --git a/next-i18next.config.js b/next-i18next.config.js index b6e79cc6..d88f3fa2 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -4,7 +4,7 @@ const path = require("path"); module.exports = { i18n: { defaultLocale: "en", - locales: ["en", "fr", "it", "ru", "es", "de", "pt", "ro", "nl"], + locales: ["en", "fr", "it", "ru", "es", "de", "pt", "ro", "nl", "pt-BR"], }, localePath: path.resolve("./public/static/locales"), }; diff --git a/pages/api/availability/eventtype.ts b/pages/api/availability/eventtype.ts index 569d3e69..9fd454f0 100644 --- a/pages/api/availability/eventtype.ts +++ b/pages/api/availability/eventtype.ts @@ -144,6 +144,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const openingHours = req.body.availability.openingHours || []; // const overrides = req.body.availability.dateOverrides || []; + const eventTypeId = +req.body.id; + if (eventTypeId) { + await prisma.availability.deleteMany({ + where: { + eventTypeId, + }, + }); + } + Promise.all( openingHours.map((schedule) => prisma.availability.create({ diff --git a/pages/event-types/[type].tsx b/pages/event-types/[type].tsx index 3564359c..ec6ed7fa 100644 --- a/pages/event-types/[type].tsx +++ b/pages/event-types/[type].tsx @@ -136,7 +136,7 @@ const EventTypePage = (props: inferSSRProps) => { const titleRef = useRef(null); const eventNameRef = useRef(null); - const isAdvancedSettingsVisible = !!eventNameRef.current; + const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false); useEffect(() => { setSelectedTimeZone(eventType.timeZone || ""); @@ -150,7 +150,7 @@ const EventTypePage = (props: inferSSRProps) => { const enteredTitle: string = titleRef.current!.value; const advancedPayload: AdvancedOptions = {}; - if (isAdvancedSettingsVisible) { + if (advancedSettingsVisible) { advancedPayload.eventName = eventNameRef.current.value; advancedPayload.periodType = periodType?.type; advancedPayload.periodDays = asNumberOrUndefined(formData.periodDays); @@ -166,6 +166,12 @@ const EventTypePage = (props: inferSSRProps) => { formData.price ? Math.round(parseFloat(asStringOrThrow(formData.price)) * 100) : /* otherwise */ 0; advancedPayload.currency = currency; + advancedPayload.availability = enteredAvailability || undefined; + advancedPayload.customInputs = customInputs; + advancedPayload.timeZone = selectedTimeZone; + advancedPayload.hidden = hidden; + advancedPayload.disableGuests = formData.disableGuests === "on"; + advancedPayload.requiresConfirmation = formData.requiresConfirmation === "on"; } const payload: EventTypeInput = { @@ -174,13 +180,7 @@ const EventTypePage = (props: inferSSRProps) => { slug: asStringOrThrow(formData.slug), description: asStringOrThrow(formData.description), length: asNumberOrThrow(formData.length), - requiresConfirmation: formData.requiresConfirmation === "on", - disableGuests: formData.disableGuests === "on", - hidden, locations, - customInputs, - timeZone: selectedTimeZone, - availability: enteredAvailability || undefined, ...advancedPayload, ...(team ? { @@ -620,14 +620,18 @@ const EventTypePage = (props: inferSSRProps) => { {({ open }) => ( <> - - - - {t("show_advanced_settings")} - - +
setAdvancedSettingsVisible(!advancedSettingsVisible)}> + + + + {t("show_advanced_settings")} + + +
@@ -1135,6 +1139,15 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => }, }, }, + { + team: { + members: { + some: { + userId: session.user.id, + }, + }, + }, + }, { userId: session.user.id, }, diff --git a/public/static/locales/pt-BR/common.json b/public/static/locales/pt-BR/common.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/public/static/locales/pt-BR/common.json @@ -0,0 +1 @@ +{}