Scheduling infrastructure for absolutely everyone.
feat: Salesforce - handle picklist field type (#20342)
Joe Au-Yeungf24e8d12f05a
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex bab3543d5ce..9a727851b95 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -3036,5 +3036,6 @@"tip_username_plus": "Tip: You can a '+' between usernames: cal.com/anna+brian to make a dynamic group meeting","user_has_no_team_yet": "You don't have a team yet","no_team_members": "You don't have team members yet",+ "picklist": "Picklist","ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"}\ No newline at end of filediff --git a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsxindex 0085a4d12fd..9f6dbcba8e4 100644--- a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx+++ b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx@@ -8,9 +8,9 @@ import type { EventTypeAppCardComponent } from "@calcom/app-store/types";import { WEBAPP_URL } from "@calcom/lib/constants";import { useLocale } from "@calcom/lib/hooks/useLocale";import { SchedulingType } from "@calcom/prisma/enums";-import { InputField } from "@calcom/ui/components/form";import { Alert } from "@calcom/ui/components/alert";import { Button } from "@calcom/ui/components/button";+import { InputField } from "@calcom/ui/components/form";import { Select } from "@calcom/ui/components/form";import { Switch } from "@calcom/ui/components/form";import { showToast } from "@calcom/ui/components/toast";@@ -63,6 +63,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({{ label: t("date"), value: SalesforceFieldType.DATE },{ label: t("phone").charAt(0).toUpperCase() + t("phone").slice(1), value: SalesforceFieldType.PHONE },{ label: t("custom"), value: SalesforceFieldType.CUSTOM },+ { label: t("picklist"), value: SalesforceFieldType.PICKLIST },];const [writeToPersonObjectFieldType, setWriteToPersonObjectFieldType] = useState(fieldTypeOptions[0]);diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.tsindex bd517e48ec3..8f22c3a2fc9 100644--- a/packages/app-store/salesforce/lib/CrmService.ts+++ b/packages/app-store/salesforce/lib/CrmService.ts@@ -1151,6 +1151,18 @@ export default class SalesforceCRMService implements CRM {writeOnRecordBody[field.name] = dateValue;continue;}+ } else if (field.type === SalesforceFieldType.PICKLIST) {+ const picklistValue = await this.getPicklistFieldValue({+ fieldConfigValue: fieldConfig.value,+ salesforceField: field,+ calEventResponses,+ bookingUid,+ contactId,+ });+ if (picklistValue) {+ writeOnRecordBody[field.name] = picklistValue;+ continue;+ }}}@@ -1294,6 +1306,49 @@ export default class SalesforceCRMService implements CRM {return null;}+ private async getPicklistFieldValue({+ fieldConfigValue,+ salesforceField,+ calEventResponses,+ bookingUid,+ contactId,+ }: {+ fieldConfigValue: string;+ salesforceField: Field;+ calEventResponses?: CalEventResponses | null;+ bookingUid?: string | null;+ contactId: string;+ }) {+ const log = logger.getSubLogger({ prefix: [`[getPicklistFieldValue] ${contactId}`] });++ const picklistOptions = salesforceField.picklistValues;+ if (!picklistOptions || !picklistOptions.length) {+ log.warn(`No picklist values found for field ${salesforceField.name}`);+ return null;+ }++ // Get the text value from the field+ const fieldTextValue = await this.getTextFieldValue({+ fieldValue: fieldConfigValue,+ fieldLength: salesforceField.length,+ calEventResponses,+ bookingUid,+ });++ if (!fieldTextValue) {+ log.warn(`No text value found for field ${salesforceField.name}`);+ return null;+ }+ // Get the picklist value from the field+ const picklistValue = picklistOptions.find((option) => option.active && option.value === fieldTextValue);+ if (!picklistValue) {+ log.warn(`No picklist value found for field ${salesforceField.name} and value ${fieldTextValue}`);+ return null;+ }++ return picklistValue.value;+ }+private async fetchPersonRecord(contactId: string,existingFields: Field[],diff --git a/packages/app-store/salesforce/lib/enums.ts b/packages/app-store/salesforce/lib/enums.tsindex 9d66ba306b6..7839e23fbdb 100644--- a/packages/app-store/salesforce/lib/enums.ts+++ b/packages/app-store/salesforce/lib/enums.ts@@ -14,6 +14,7 @@ export enum SalesforceFieldType {TEXT = "string",PHONE = "phone",CUSTOM = "custom",+ PICKLIST = "picklist",}export enum DateFieldTypeData {