Files
calendar/packages/lib/CalEventParser.ts
T
517cfde5b8 Feature/ Manage Booking Questions (#6560)
* WIP

* Create Booking Questions builder

* Renaming things

* wip

* wip

* Implement Add Guests and other fixes

* Fixes after testing

* Fix wrong status code 404

* Fixes

* Lint fixes

* Self review comments addressed

* More self review comments addressed

* Feedback from zomars

* BugFixes after testing

* More fixes discovered during review

* Update packages/lib/hooks/useHasPaidPlan.ts

Co-authored-by: Omar López <[email protected]>

* More fixes discovered during review

* Update packages/ui/components/form/inputs/Input.tsx

Co-authored-by: Omar López <[email protected]>

* More fixes discovered during review

* Update packages/features/bookings/lib/getBookingFields.ts

Co-authored-by: sean-brydon <[email protected]>

* More PR review fixes

* Hide label using labelSrOnly

* Fix Carinas feedback and implement 2 workflows thingy

* Misc fixes

* Fixes from Loom comments and PR

* Fix a lint errr

* Fix cancellation reason

* Fix regression in edit due to name conflict check

* Update packages/features/form-builder/FormBuilder.tsx

Co-authored-by: Carina Wollendorfer <[email protected]>

* Fix options not set when default value is used

* Restoring reqBody to avoid uneeded conflicts with main

* Type fix

* Update apps/web/components/booking/pages/BookingPage.tsx

Co-authored-by: Omar López <[email protected]>

* Update packages/features/form-builder/FormBuilder.tsx

Co-authored-by: Omar López <[email protected]>

* Update apps/web/components/booking/pages/BookingPage.tsx

Co-authored-by: Omar López <[email protected]>

* Apply suggestions from code review

Co-authored-by: Omar López <[email protected]>

* Show fields but mark them disabled

* Apply suggestions from code review

Co-authored-by: Omar López <[email protected]>

* More comments

* Fix booking success page crash when a booking doesnt have newly added required fields response

* Dark theme asterisk not visible

* Make location required in zodSchema as was there in production

* Linting

* Remove _metadata.ts files for apps that have config.json

* Revert "Remove _metadata.ts files for apps that have config.json"

This reverts commit d79bdd336cf312a30a8943af94c059947bd91ccd.

* Fix lint error

* Fix missing condition for samlSPConfig

* Delete unexpectedly added file

* yarn.lock change not required

* fix types

* Make checkboxes rounded

* Fix defaultLabel being stored as label due to SSR rendering

* Shaved 16kb from booking page

* Explicit types for profile

* Show payment value only if price is greater than 0

* Fix type error

* Add back inferred types as they are failing

* Fix duplicate label on number

---------

Co-authored-by: zomars <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Efraín Rochín <[email protected]>
2023-03-02 11:15:28 -07:00

225 lines
6.3 KiB
TypeScript

import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { WEBAPP_URL } from "./constants";
const translator = short();
// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description.
export const getWhat = (calEvent: CalendarEvent) => {
return `
${calEvent.organizer.language.translate("what")}:
${calEvent.type}
`;
};
export const getWhen = (calEvent: CalendarEvent) => {
return calEvent.seatsPerTimeSlot
? `
${calEvent.organizer.language.translate("organizer_timezone")}:
${calEvent.organizer.timeZone}
`
: `
${calEvent.organizer.language.translate("invitee_timezone")}:
${calEvent.attendees[0].timeZone}
`;
};
export const getWho = (calEvent: CalendarEvent) => {
if (calEvent.seatsPerTimeSlot && !calEvent.seatsShowAttendees) {
calEvent.attendees = [];
}
const attendees = calEvent.attendees
.map((attendee) => {
return `
${attendee?.name || calEvent.organizer.language.translate("guest")}
${attendee.email}
`;
})
.join("");
const organizer = `
${calEvent.organizer.name} - ${calEvent.organizer.language.translate("organizer")}
${calEvent.organizer.email}
`;
const teamMembers = calEvent.team?.members
? calEvent.team.members.map((member) => {
return `
${member.name} - ${calEvent.organizer.language.translate("team_member")}
${member.email}
`;
})
: [];
return `
${calEvent.organizer.language.translate("who")}:
${organizer + attendees + teamMembers.join("")}
`;
};
export const getAdditionalNotes = (calEvent: CalendarEvent) => {
if (!calEvent.additionalNotes) {
return "";
}
return `
${calEvent.organizer.language.translate("additional_notes")}:
${calEvent.additionalNotes}
`;
};
export const getUserFieldsResponses = (calEvent: CalendarEvent) => {
const responses = calEvent.userFieldsResponses || calEvent.customInputs;
if (!responses) {
return "";
}
const responsesString = Object.keys(responses)
.map((key) => {
if (!responses) return "";
if (responses[key] !== "") {
return `
${key}:
${responses[key]}
`;
}
})
.join("");
return responsesString;
};
export const getAppsStatus = (calEvent: CalendarEvent) => {
if (!calEvent.appsStatus) {
return "";
}
return `\n${calEvent.organizer.language.translate("apps_status")}
${calEvent.appsStatus.map((app) => {
return `\n- ${app.appName} ${
app.success >= 1 ? `✅ ${app.success > 1 ? `(x${app.success})` : ""}` : ""
}${
app.warnings && app.warnings.length >= 1 ? app.warnings.map((warning) => `\n - ${warning}`) : ""
} ${app.failures && app.failures >= 1 ? `❌ ${app.failures > 1 ? `(x${app.failures})` : ""}` : ""} ${
app.errors && app.errors.length >= 1 ? app.errors.map((error) => `\n - ${error}`) : ""
}`;
})}
`;
};
export const getDescription = (calEvent: CalendarEvent) => {
if (!calEvent.description) {
return "";
}
return `\n${calEvent.organizer.language.translate("description")}
${calEvent.description}
`;
};
export const getLocation = (calEvent: CalendarEvent) => {
const meetingUrl = getVideoCallUrl(calEvent);
if (meetingUrl) {
return meetingUrl;
}
const providerName = getProviderName(calEvent);
return providerName || calEvent.location || "";
};
export const getProviderName = (calEvent: CalendarEvent): string => {
// TODO: use getAppName from @calcom/app-store
if (calEvent.location && calEvent.location.includes("integrations:")) {
let location = calEvent.location.split(":")[1];
if (location === "daily") {
location = "Cal Video";
}
return location[0].toUpperCase() + location.slice(1);
}
// If location its a url, probably we should be validating it with a custom library
if (calEvent.location && /^https?:\/\//.test(calEvent.location)) {
return calEvent.location;
}
return "";
};
export const getUid = (calEvent: CalendarEvent): string => {
return calEvent.uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
};
export const getManageLink = (calEvent: CalendarEvent) => {
return `
${calEvent.organizer.language.translate("need_to_reschedule_or_cancel")}
${WEBAPP_URL + "/booking/" + getUid(calEvent) + "?changes=true"}
`;
};
export const getCancelLink = (calEvent: CalendarEvent): string => {
return (
WEBAPP_URL + `/booking/${getUid(calEvent)}?cancel=true&allRemainingBookings=${!!calEvent.recurringEvent}`
);
};
export const getRescheduleLink = (calEvent: CalendarEvent): string => {
return WEBAPP_URL + "/reschedule/" + getUid(calEvent);
};
export const getRichDescription = (calEvent: CalendarEvent /*, attendee?: Person*/) => {
return `
${getCancellationReason(calEvent)}
${getWhat(calEvent)}
${getWhen(calEvent)}
${getWho(calEvent)}
${calEvent.organizer.language.translate("where")}:
${getLocation(calEvent)}
${getDescription(calEvent)}
${getAdditionalNotes(calEvent)}
${getUserFieldsResponses(calEvent)}
${getAppsStatus(calEvent)}
${
// TODO: Only the original attendee can make changes to the event
// Guests cannot
getManageLink(calEvent)
}
${
calEvent.paymentInfo
? `
${calEvent.organizer.language.translate("pay_now")}:
${calEvent.paymentInfo.link}
`
: ""
}
`.trim();
};
export const getCancellationReason = (calEvent: CalendarEvent) => {
if (!calEvent.cancellationReason) return "";
return `
${calEvent.organizer.language.translate("cancellation_reason")}:
${calEvent.cancellationReason}
`;
};
export const isDailyVideoCall = (calEvent: CalendarEvent): boolean => {
return calEvent?.videoCallData?.type === "daily_video";
};
export const getPublicVideoCallUrl = (calEvent: CalendarEvent): string => {
return WEBAPP_URL + "/video/" + getUid(calEvent);
};
export const getVideoCallUrl = (calEvent: CalendarEvent): string => {
if (calEvent.videoCallData) {
if (isDailyVideoCall(calEvent)) {
return getPublicVideoCallUrl(calEvent);
}
return calEvent.videoCallData.url;
}
if (calEvent.additionalInformation?.hangoutLink) {
return calEvent.additionalInformation.hangoutLink;
}
return "";
};
export const getVideoCallPassword = (calEvent: CalendarEvent): string => {
return isDailyVideoCall(calEvent) ? "" : calEvent?.videoCallData?.password ?? "";
};