Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Salesforce choose how to save attendees & other options #17009

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,12 @@
"month_to_date": "month to date",
"year_to_date": "year to date",
"custom_range": "custom range",
"salesforce_create_record_as": "On booking, add events on and new attendees as:",
"salesforce_lead": "Lead",
"salesforce_contact_under_account": "Contact under an account",
"salesforce_skip_entry_creation": "Skip creating {{entry}} record if they do not exist in Salesforce",
"salesforce_if_account_does_not_exist": "If the contact does not exist under an account, create new lead from attendee",
"salesforce_create_new_contact_under_account": "Create a new contact under an account based on email domain of attendee and existing contacts",
"mass_assign_attributes": "Mass assign attributes",
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
}
6 changes: 3 additions & 3 deletions packages/app-store/_utils/getCrm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import appStore from "..";

type Class<I, Args extends any[] = any[]> = new (...args: Args) => I;

type CrmClass = Class<CRM, [CredentialPayload]>;
type CrmClass = Class<CRM, [CredentialPayload, any]>;

const log = logger.getSubLogger({ prefix: ["CrmManager"] });
export const getCrm = async (credential: CredentialPayload) => {
export const getCrm = async (credential: CredentialPayload, appOptions: any) => {
if (!credential || !credential.key) return null;
const { type: crmType } = credential;

Expand All @@ -26,7 +26,7 @@ export const getCrm = async (credential: CredentialPayload) => {

if (crmApp && "lib" in crmApp && "CrmService" in crmApp.lib) {
const CrmService = crmApp.lib.CrmService as CrmClass;
return new CrmService(credential);
return new CrmService(credential, appOptions);
}
};

Expand Down
4 changes: 4 additions & 0 deletions packages/app-store/closecom/lib/CrmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,8 @@ export default class CloseComCRMService implements CRM {

return contacts;
}

getAppOptions() {
console.log("No options implemented");
}
}
4 changes: 4 additions & 0 deletions packages/app-store/hubspot/lib/CrmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,8 @@ export default class HubspotCalendarService implements CRM {
};
});
}

getAppOptions() {
console.log("No options implemented");
}
}
4 changes: 4 additions & 0 deletions packages/app-store/pipedrive-crm/lib/CrmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,8 @@ export default class PipedriveCrmService implements CRM {
async listCalendars(_event?: CalendarEvent): Promise<IntegrationCalendar[]> {
return Promise.resolve([]);
}

getAppOptions() {
console.log("No options implemented");
}
}
107 changes: 82 additions & 25 deletions packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { usePathname } from "next/navigation";
import { useState } from "react";

import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext";
import AppCard from "@calcom/app-store/_components/AppCard";
Expand All @@ -7,8 +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 { Switch, Alert } from "@calcom/ui";
import { Switch, Alert, Select } from "@calcom/ui";

import { SalesforceRecordEnum } from "../lib/recordEnum";
import type { appDataSchema } from "../zod";

const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType }) {
Expand All @@ -18,8 +20,20 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
const { enabled, updateEnabled } = useIsAppEnabled(app);
const isRoundRobinLeadSkipEnabled = getAppData("roundRobinLeadSkip");
const isSkipContactCreationEnabled = getAppData("skipContactCreation");
const createLeadIfAccountNull = getAppData("createLeadIfAccountNull");
const createNewContactUnderAccount = getAppData("createNewContactUnderAccount");
const createEventOn = getAppData("createEventOn") ?? SalesforceRecordEnum.CONTACT;
const { t } = useLocale();

const recordOptions = [
{ label: t("contact"), value: SalesforceRecordEnum.CONTACT },
{ label: t("salesforce_lead"), value: SalesforceRecordEnum.LEAD },
{ label: t("salesforce_contact_under_account"), value: SalesforceRecordEnum.ACCOUNT },
];
const [createEventOnSelectedOption, setCreateEventOnSelectedOption] = useState(
recordOptions.find((option) => option.value === createEventOn) ?? recordOptions[0]
);

return (
<AppCard
returnTo={`${WEBAPP_URL}${pathname}?tabName=apps`}
Expand All @@ -31,34 +45,77 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
switchChecked={enabled}
hideSettingsIcon>
<>
<div>
<Switch
label={t("skip_contact_creation", { appName: "Salesforce" })}
labelOnLeading
checked={isSkipContactCreationEnabled}
onCheckedChange={(checked) => {
setAppData("skipContactCreation", checked);
}}
/>
</div>
</>
{eventType.schedulingType === SchedulingType.ROUND_ROBIN ? (
<div className="mt-4">
<Switch
label={t("skip_rr_assignment_label")}
labelOnLeading
checked={isRoundRobinLeadSkipEnabled}
onCheckedChange={(checked) => {
setAppData("roundRobinLeadSkip", checked);
if (checked) {
// temporary solution, enabled should always be already set
setAppData("enabled", checked);
<div className="mb-4 ml-2">
<label className="text-emphasis mb-2 align-text-top text-sm font-medium">
{t("salesforce_create_record_as")}
</label>
<Select
className="mt-2 w-60"
options={recordOptions}
value={createEventOnSelectedOption}
onChange={(e) => {
if (e) {
setCreateEventOnSelectedOption(e);
setAppData("createEventOn", e.value);
}
}}
/>
<Alert className="mt-2" severity="neutral" title={t("skip_rr_description")} />
</div>
) : null}
{createEventOnSelectedOption.value === SalesforceRecordEnum.CONTACT ? (
<div>
<Switch
label={t("skip_contact_creation", { appName: "Salesforce" })}
labelOnLeading
checked={isSkipContactCreationEnabled}
onCheckedChange={(checked) => {
setAppData("skipContactCreation", checked);
}}
/>
</div>
) : null}
{createEventOnSelectedOption.value === SalesforceRecordEnum.ACCOUNT ? (
<>
<div className="mb-4">
<Switch
label={t("salesforce_create_new_contact_under_account")}
labelOnLeading
checked={createNewContactUnderAccount}
onCheckedChange={(checked) => {
setAppData("createNewContactUnderAccount", checked);
}}
/>
</div>
<div>
<Switch
label={t("salesforce_if_account_does_not_exist")}
labelOnLeading
checked={createLeadIfAccountNull}
onCheckedChange={(checked) => {
setAppData("createLeadIfAccountNull", checked);
}}
/>
</div>
</>
) : null}

{eventType.schedulingType === SchedulingType.ROUND_ROBIN ? (
<div className="mt-4">
<Switch
label={t("skip_rr_assignment_label")}
labelOnLeading
checked={isRoundRobinLeadSkipEnabled}
onCheckedChange={(checked) => {
setAppData("roundRobinLeadSkip", checked);
if (checked) {
// temporary solution, enabled should always be already set
setAppData("enabled", checked);
}
}}
/>
<Alert className="mt-2" severity="neutral" title={t("skip_rr_description")} />
</div>
) : null}
</>
</AppCard>
);
};
Expand Down
Loading
Loading