diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index b8b484ef04..bd7307b197 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -3734,6 +3734,11 @@ "completed_onboarding": "Completed onboarding", "salesforce_on_cancel_write_to_event": "On cancelled booking, write to event record instead of deleting event", "salesforce_on_every_cancellation": "On every cancellation", + "salesforce_rr_skip_field_rules": "Field rules for round robin skip", + "salesforce_rr_skip_field_rule_ignore": "Ignore", + "salesforce_rr_skip_field_rule_must_include": "Must include", + "salesforce_field_name_placeholder": "Field name (e.g., Industry)", + "add_new_rule": "Add new rule", "report_issue": "Report issue", "report_issue_description": "You can submit a ticket on GitHub or upgrade your plan to receive real-time support with developer conferences", "open_issue": "Open Issue", diff --git a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx index a12c8d5e78..0c9d81d7a3 100644 --- a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx +++ b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx @@ -17,7 +17,8 @@ import { Section } from "@calcom/ui/components/section"; import { showToast } from "@calcom/ui/components/toast"; import { SalesforceRecordEnum } from "../lib/enums"; -import type { appDataSchema } from "../zod"; +import type { appDataSchema, RRSkipFieldRule } from "../zod"; +import FieldRulesSettings from "./components/FieldRulesSettings"; import WriteToObjectSettings, { BookingActionEnum } from "./components/WriteToObjectSettings"; const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType, onAppInstallSuccess }) { @@ -46,6 +47,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ const roundRobinSkipFallbackToLeadOwner = getAppData("roundRobinSkipFallbackToLeadOwner") ?? false; const onCancelWriteToEventRecord = getAppData("onCancelWriteToEventRecord") ?? false; const onCancelWriteToEventRecordFields = getAppData("onCancelWriteToEventRecordFields") ?? {}; + const rrSkipFieldRules = (getAppData("rrSkipFieldRules") ?? []) as RRSkipFieldRule[]; const { t } = useLocale(); @@ -435,6 +437,10 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ + setAppData("rrSkipFieldRules", rules)} + /> ) : null} diff --git a/packages/app-store/salesforce/components/components/FieldRulesSettings.tsx b/packages/app-store/salesforce/components/components/FieldRulesSettings.tsx new file mode 100644 index 0000000000..7184e44f3b --- /dev/null +++ b/packages/app-store/salesforce/components/components/FieldRulesSettings.tsx @@ -0,0 +1,238 @@ +import { useState } from "react"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { Button } from "@calcom/ui/components/button"; +import { InputField } from "@calcom/ui/components/form"; +import { Select } from "@calcom/ui/components/form"; +import { Section } from "@calcom/ui/components/section"; + +import type { RRSkipFieldRule } from "../../zod"; +import { RRSkipFieldRuleActionEnum } from "../../zod"; + +type FieldRuleAction = (typeof RRSkipFieldRuleActionEnum)[keyof typeof RRSkipFieldRuleActionEnum]; + +const FieldRulesSettings = ({ + fieldRules, + updateFieldRules, +}: { + fieldRules: RRSkipFieldRule[]; + updateFieldRules: (rules: RRSkipFieldRule[]) => void; +}) => { + const { t } = useLocale(); + + const actionOptions = [ + { label: t("salesforce_rr_skip_field_rule_ignore"), value: RRSkipFieldRuleActionEnum.IGNORE }, + { label: t("salesforce_rr_skip_field_rule_must_include"), value: RRSkipFieldRuleActionEnum.MUST_INCLUDE }, + ]; + + const [newRule, setNewRule] = useState<{ field: string; value: string; action: FieldRuleAction }>({ + field: "", + value: "", + action: RRSkipFieldRuleActionEnum.IGNORE, + }); + + const [editingIndex, setEditingIndex] = useState(null); + const [editingRule, setEditingRule] = useState<{ + field: string; + value: string; + action: FieldRuleAction; + } | null>(null); + + const startEditing = (index: number) => { + const rule = fieldRules[index]; + setEditingIndex(index); + setEditingRule({ field: rule.field, value: rule.value, action: rule.action }); + }; + + const cancelEditing = () => { + setEditingIndex(null); + setEditingRule(null); + }; + + const saveEditing = () => { + if (editingIndex === null || !editingRule) return; + if (!editingRule.field.trim() || !editingRule.value.trim()) return; + + const newRules = [...fieldRules]; + newRules[editingIndex] = { + field: editingRule.field.trim(), + value: editingRule.value.trim(), + action: editingRule.action, + }; + updateFieldRules(newRules); + cancelEditing(); + }; + + return ( + + + <> + + +
+
{t("field_name")}
+
{t("value")}
+
{t("action")}
+
+
+ + {fieldRules.map((rule, index) => { + const isEditing = editingIndex === index; + return ( +
+
+ {isEditing ? ( + + setEditingRule((prev) => (prev ? { ...prev, field: e.target.value } : null)) + } + size="sm" + className="w-full" + /> + ) : ( + + )} +
+
+ {isEditing ? ( + + setEditingRule((prev) => (prev ? { ...prev, value: e.target.value } : null)) + } + size="sm" + className="w-full" + /> + ) : ( + + )} +
+
+ {isEditing ? ( + opt.value === rule.action)} + isDisabled={true} + /> + )} +
+
+ {isEditing ? ( + <> +
+
+ ); + })} +
+
+ setNewRule({ ...newRule, field: e.target.value })} + /> +
+
+ setNewRule({ ...newRule, value: e.target.value })} + /> +
+
+