The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Trim HubSpot stage IDs so surrounding whitespace still matches
Kiran K5d21af90fd4d
diff --git a/apps/web/lib/integrations/hubspot/schema.ts b/apps/web/lib/integrations/hubspot/schema.tsindex d421b34050..efdbc2c615 100644--- a/apps/web/lib/integrations/hubspot/schema.ts+++ b/apps/web/lib/integrations/hubspot/schema.ts@@ -25,18 +25,21 @@ export const hubSpotSettingsSchema = z.object({),leadLifecycleStageId: z.string()+ .trim().nullish().describe("The ID of the contact lifecycle stage that represents a lead. Applicable only if leadTrackingTrigger is 'lifecycleStageReached'.",),leadDealStageId: z.string()+ .trim().nullish().describe("The ID of the deal stage that represents a lead. Applicable only if leadTriggerEvent is 'dealStageReached'.",),closedWonDealStageId: z.string()+ .trim().nullish().default("closedwon").describe("The ID of the deal stage that represents a closed won deal."),diff --git a/apps/web/lib/integrations/hubspot/ui/settings.tsx b/apps/web/lib/integrations/hubspot/ui/settings.tsxindex 0144ac616e..3ff84afd1f 100644--- a/apps/web/lib/integrations/hubspot/ui/settings.tsx+++ b/apps/web/lib/integrations/hubspot/ui/settings.tsx@@ -141,7 +141,9 @@ export const HubSpotSettings = ({autoComplete="off"name="leadLifecycleStageId"value={leadLifecycleStageId ?? ""}- onChange={(e) => setLeadLifecycleStageId(e.target.value)}+ onChange={(e) =>+ setLeadLifecycleStageId(e.target.value.trim())+ }/></div></div>@@ -165,7 +167,7 @@ export const HubSpotSettings = ({autoComplete="off"name="leadDealStageId"value={leadDealStageId ?? ""}- onChange={(e) => setLeadDealStageId(e.target.value)}+ onChange={(e) => setLeadDealStageId(e.target.value.trim())}/></div></div>@@ -188,7 +190,7 @@ export const HubSpotSettings = ({autoComplete="off"name="closedWonDealStageId"value={closedWonDealStageId ?? ""}- onChange={(e) => setClosedWonDealStageId(e.target.value)}+ onChange={(e) => setClosedWonDealStageId(e.target.value.trim())}/></div></div>diff --git a/apps/web/tests/misc/hubspot-event-action.test.ts b/apps/web/tests/misc/hubspot-event-action.test.tsindex 8d18c87764..566afcd5ef 100644--- a/apps/web/tests/misc/hubspot-event-action.test.ts+++ b/apps/web/tests/misc/hubspot-event-action.test.ts@@ -195,6 +195,18 @@ describe("getHubSpotEventAction", () => {).toBe("trackSale");});+ it("matches the closed won stage when the saved id has surrounding whitespace", () => {+ const parsed = settings({ closedWonDealStageId: " closedwon " });++ expect(parsed.closedWonDealStageId).toBe("closedwon");+ expect(+ getHubSpotEventAction({+ event: dealStageChanged("closedwon"),+ settings: parsed,+ }),+ ).toBe("trackSale");+ });+it("uses a custom closed won stage ID instead of the default", () => {const custom = settings({ closedWonDealStageId: "12345" });@@ -273,6 +285,36 @@ describe("getHubSpotEventAction", () => {).toBe("trackLead");});+ it("matches the lead deal stage when the saved id has surrounding whitespace", () => {+ const parsed = settings({+ leadTriggerEvent: "dealStageReached",+ leadDealStageId: " appointmentscheduled ",+ });++ expect(parsed.leadDealStageId).toBe("appointmentscheduled");+ expect(+ getHubSpotEventAction({+ event: dealStageChanged("appointmentscheduled"),+ settings: parsed,+ }),+ ).toBe("trackLead");+ });++ it("does not treat a whitespace-only lead deal stage id as configured", () => {+ const parsed = settings({+ leadTriggerEvent: "dealStageReached",+ leadDealStageId: " ",+ });++ expect(parsed.leadDealStageId).toBe("");+ expect(+ getHubSpotEventAction({+ event: dealStageChanged("appointmentscheduled"),+ settings: parsed,+ }),+ ).toBe("skip");+ });+it("skips when the deal moves to a different stage", () => {expect(getHubSpotEventAction({