From a404ca847c731f594087b2e2cc5834143c216adb Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Mon, 8 Nov 2021 16:34:12 +0530 Subject: [PATCH] updated event title message (#1132) * updated event title message * 4 arguments replaced by an object * translations * requested changes * further requested changes * test fix and other minor changes * lint fix --- lib/event.ts | 25 ++++++++++++++++++------- pages/api/book/event.ts | 11 ++++++++++- pages/success.tsx | 12 +++++++++++- playwright/integrations.test.ts | 2 +- public/static/locales/en/common.json | 1 + 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/event.ts b/lib/event.ts index 82b969d2..b261b627 100644 --- a/lib/event.ts +++ b/lib/event.ts @@ -1,8 +1,19 @@ -export function getEventName( - name: string | string[] | undefined, - eventTitle: string, - eventNameTemplate: string | null -) { - if (!name || !(typeof name === "string")) name = ""; // If name is not set or is not of proper type - return eventNameTemplate ? eventNameTemplate.replace("{USER}", name) : eventTitle + " with " + name; +import { TFunction } from "next-i18next"; + +type EventNameObjectType = { + attendeeName: string; + eventType: string; + eventName?: string | null; + host: string; + t: TFunction; +}; + +export function getEventName(eventNameObj: EventNameObjectType) { + return eventNameObj.eventName + ? eventNameObj.eventName.replace("{USER}", eventNameObj.attendeeName) + : eventNameObj.t("event_between_users", { + eventName: eventNameObj.eventType, + host: eventNameObj.host, + attendeeName: eventNameObj.attendeeName, + }); } diff --git a/pages/api/book/event.ts b/pages/api/book/event.ts index 893b689d..22204345 100644 --- a/pages/api/book/event.ts +++ b/pages/api/book/event.ts @@ -263,9 +263,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const seed = `${users[0].username}:${dayjs(req.body.start).utc().format()}:${new Date().getTime()}`; const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL)); + const eventNameObject = { + attendeeName: reqBody.name || "Nameless", + eventType: eventType.title, + eventName: eventType.eventName, + host: users[0].name || "Nameless", + t, + }; + const evt: CalendarEvent = { type: eventType.title, - title: getEventName(reqBody.name, eventType.title, eventType.eventName), + title: getEventName(eventNameObject), description: reqBody.notes, startTime: reqBody.start, endTime: reqBody.end, @@ -488,6 +496,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const eventTrigger = rescheduleUid ? "BOOKING_RESCHEDULED" : "BOOKING_CREATED"; // Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED const subscriberUrls = await getSubscriberUrls(user.id, eventTrigger); + console.log("evt:", evt); const promises = subscriberUrls.map((url) => sendPayload(eventTrigger, new Date().toISOString(), url, evt).catch((e) => { console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${url}`, e); diff --git a/pages/success.tsx b/pages/success.tsx index 094067f2..b0d6c177 100644 --- a/pages/success.tsx +++ b/pages/success.tsx @@ -39,7 +39,17 @@ export default function Success(props: inferSSRProps) setIs24h(!!localStorage.getItem("timeOption.is24hClock")); }, []); - const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); + const attendeeName = typeof name === "string" ? name : "Nameless"; + + const eventNameObject = { + attendeeName, + eventType: props.eventType.title, + eventName: props.eventType.eventName, + host: props.profile.name || "Nameless", + t, + }; + + const eventName = getEventName(eventNameObject); function eventLink(): string { const optional: { location?: string } = {}; diff --git a/playwright/integrations.test.ts b/playwright/integrations.test.ts index 5405742f..dbe280c3 100644 --- a/playwright/integrations.test.ts +++ b/playwright/integrations.test.ts @@ -89,7 +89,7 @@ describe("webhooks", () => { "timeZone": "[redacted/dynamic]", }, "startTime": "[redacted/dynamic]", - "title": "30min with Test Testson", + "title": "30min between Pro Example and Test Testson", "type": "30min", "uid": "[redacted/dynamic]", }, diff --git a/public/static/locales/en/common.json b/public/static/locales/en/common.json index 8f103ccd..fb8f9a0e 100644 --- a/public/static/locales/en/common.json +++ b/public/static/locales/en/common.json @@ -222,6 +222,7 @@ "no_meeting_found_description": "This meeting does not exist. Contact the meeting owner for an updated link.", "no_status_bookings_yet": "No {{status}} bookings, yet", "no_status_bookings_yet_description": "You have no {{status}} bookings. {{description}}", + "event_between_users": "{{eventName}} between {{host}} and {{attendeeName}}", "bookings": "Bookings", "bookings_description": "See upcoming and past events booked through your event type links.", "upcoming_bookings": "As soon as someone books a time with you it will show up here.",