Fix "User Added Question" Label in Email and Calendar Invite (#7559)
* Show label in email and calendar invite and send label as well as name in webhook * Make common code reusable --------- Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
6f8ea490d0
commit
ce8e1d52da
6 files changed
+75
-22
No files matched your search
@@ -4,6 +4,7 @@ import { v5 as uuidv5 } from "uuid";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { WEBAPP_URL } from "./constants";
|
||||
import getLabelValueMapFromResponses from "./getLabelValueMapFromResponses";
|
||||
|
||||
const translator = short();
|
||||
|
||||
@@ -72,17 +73,18 @@ ${calEvent.additionalNotes}
|
||||
};
|
||||
|
||||
export const getUserFieldsResponses = (calEvent: CalendarEvent) => {
|
||||
const responses = calEvent.userFieldsResponses || calEvent.customInputs;
|
||||
if (!responses) {
|
||||
const labelValueMap = getLabelValueMapFromResponses(calEvent);
|
||||
|
||||
if (!labelValueMap) {
|
||||
return "";
|
||||
}
|
||||
const responsesString = Object.keys(responses)
|
||||
const responsesString = Object.keys(labelValueMap)
|
||||
.map((key) => {
|
||||
if (!responses) return "";
|
||||
if (responses[key] !== "") {
|
||||
if (!labelValueMap) return "";
|
||||
if (labelValueMap[key] !== "") {
|
||||
return `
|
||||
${key}:
|
||||
${responses[key]}
|
||||
${labelValueMap[key]}
|
||||
`;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
export default function getLabelValueMapFromResponses(calEvent: CalendarEvent) {
|
||||
const { customInputs, userFieldsResponses } = calEvent;
|
||||
|
||||
let labelValueMap: Record<string, string | string[]> = {};
|
||||
if (userFieldsResponses) {
|
||||
for (const [, value] of Object.entries(userFieldsResponses)) {
|
||||
labelValueMap[value.label] = value.value;
|
||||
}
|
||||
} else {
|
||||
labelValueMap = customInputs as Record<string, string | string[]>;
|
||||
}
|
||||
return labelValueMap;
|
||||
}
|
||||
Reference in new issue
Block a user