Scheduling infrastructure for absolutely everyone.
fix: availability creation and expand/collapse settings (#882)
Mihai Cf27b0b3cad2c
diff --git a/lib/core/i18n/i18n.utils.ts b/lib/core/i18n/i18n.utils.tsindex c9c97633213..9de04f1d82d 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.tsindex 900d924a0e8..a535e0c096b 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.jsindex b6e79cc608b..d88f3fa2ce4 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.tsindex 569d3e69ba6..9fd454f0fc2 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].tsxindex 3564359c2fd..ec6ed7fa0a5 100644--- a/pages/event-types/[type].tsx+++ b/pages/event-types/[type].tsx@@ -136,7 +136,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {const titleRef = useRef<HTMLInputElement>(null);const eventNameRef = useRef<HTMLInputElement>(null);- const isAdvancedSettingsVisible = !!eventNameRef.current;+ const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false);useEffect(() => {setSelectedTimeZone(eventType.timeZone || "");@@ -150,7 +150,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {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<typeof getServerSideProps>) => {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<typeof getServerSideProps>) => {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<typeof getServerSideProps>) => {<Disclosure>{({ open }) => (<>- <Disclosure.Button className="flex w-full">- <ChevronRightIcon- className={`${open ? "transform rotate-90" : ""} w-5 h-5 text-neutral-500 ml-auto`}- />- <span className="text-sm font-medium text-neutral-700">- {t("show_advanced_settings")}- </span>- </Disclosure.Button>+ <div onClick={() => setAdvancedSettingsVisible(!advancedSettingsVisible)}>+ <Disclosure.Button className="flex w-full">+ <ChevronRightIcon+ className={`${+ open ? "transform rotate-90" : ""+ } w-5 h-5 text-neutral-500 ml-auto`}+ />+ <span className="text-sm font-medium text-neutral-700">+ {t("show_advanced_settings")}+ </span>+ </Disclosure.Button>+ </div><Disclosure.Panel className="space-y-6"><div className="items-center block sm:flex"><div className="mb-4 min-w-48 sm:mb-0">@@ -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.jsonnew file mode 100644index 00000000000..0967ef424bc--- /dev/null+++ b/public/static/locales/pt-BR/common.json@@ -0,0 +1 @@+{}