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
This commit is contained in:
Syed Ali Shahbaz 2021-11-08 16:34:12 +05:30 committed by GitHub
parent 0ef6d8b452
commit a404ca847c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 10 deletions

View file

@ -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,
});
}

View file

@ -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);

View file

@ -39,7 +39,17 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
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 } = {};

View file

@ -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]",
},

View file

@ -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.",