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:
parent
0ef6d8b452
commit
a404ca847c
5 changed files with 41 additions and 10 deletions
25
lib/event.ts
25
lib/event.ts
|
@ -1,8 +1,19 @@
|
||||||
export function getEventName(
|
import { TFunction } from "next-i18next";
|
||||||
name: string | string[] | undefined,
|
|
||||||
eventTitle: string,
|
type EventNameObjectType = {
|
||||||
eventNameTemplate: string | null
|
attendeeName: string;
|
||||||
) {
|
eventType: string;
|
||||||
if (!name || !(typeof name === "string")) name = ""; // If name is not set or is not of proper type
|
eventName?: string | null;
|
||||||
return eventNameTemplate ? eventNameTemplate.replace("{USER}", name) : eventTitle + " with " + name;
|
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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 seed = `${users[0].username}:${dayjs(req.body.start).utc().format()}:${new Date().getTime()}`;
|
||||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
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 = {
|
const evt: CalendarEvent = {
|
||||||
type: eventType.title,
|
type: eventType.title,
|
||||||
title: getEventName(reqBody.name, eventType.title, eventType.eventName),
|
title: getEventName(eventNameObject),
|
||||||
description: reqBody.notes,
|
description: reqBody.notes,
|
||||||
startTime: reqBody.start,
|
startTime: reqBody.start,
|
||||||
endTime: reqBody.end,
|
endTime: reqBody.end,
|
||||||
|
@ -488,6 +496,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const eventTrigger = rescheduleUid ? "BOOKING_RESCHEDULED" : "BOOKING_CREATED";
|
const eventTrigger = rescheduleUid ? "BOOKING_RESCHEDULED" : "BOOKING_CREATED";
|
||||||
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
|
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
|
||||||
const subscriberUrls = await getSubscriberUrls(user.id, eventTrigger);
|
const subscriberUrls = await getSubscriberUrls(user.id, eventTrigger);
|
||||||
|
console.log("evt:", evt);
|
||||||
const promises = subscriberUrls.map((url) =>
|
const promises = subscriberUrls.map((url) =>
|
||||||
sendPayload(eventTrigger, new Date().toISOString(), url, evt).catch((e) => {
|
sendPayload(eventTrigger, new Date().toISOString(), url, evt).catch((e) => {
|
||||||
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${url}`, e);
|
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${url}`, e);
|
||||||
|
|
|
@ -39,7 +39,17 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
|
||||||
setIs24h(!!localStorage.getItem("timeOption.is24hClock"));
|
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 {
|
function eventLink(): string {
|
||||||
const optional: { location?: string } = {};
|
const optional: { location?: string } = {};
|
||||||
|
|
|
@ -89,7 +89,7 @@ describe("webhooks", () => {
|
||||||
"timeZone": "[redacted/dynamic]",
|
"timeZone": "[redacted/dynamic]",
|
||||||
},
|
},
|
||||||
"startTime": "[redacted/dynamic]",
|
"startTime": "[redacted/dynamic]",
|
||||||
"title": "30min with Test Testson",
|
"title": "30min between Pro Example and Test Testson",
|
||||||
"type": "30min",
|
"type": "30min",
|
||||||
"uid": "[redacted/dynamic]",
|
"uid": "[redacted/dynamic]",
|
||||||
},
|
},
|
||||||
|
|
|
@ -222,6 +222,7 @@
|
||||||
"no_meeting_found_description": "This meeting does not exist. Contact the meeting owner for an updated link.",
|
"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": "No {{status}} bookings, yet",
|
||||||
"no_status_bookings_yet_description": "You have no {{status}} bookings. {{description}}",
|
"no_status_bookings_yet_description": "You have no {{status}} bookings. {{description}}",
|
||||||
|
"event_between_users": "{{eventName}} between {{host}} and {{attendeeName}}",
|
||||||
"bookings": "Bookings",
|
"bookings": "Bookings",
|
||||||
"bookings_description": "See upcoming and past events booked through your event type links.",
|
"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.",
|
"upcoming_bookings": "As soon as someone books a time with you it will show up here.",
|
||||||
|
|
Loading…
Reference in a new issue