Skip to content

Commit b09836c

Browse files
D-K-PTrigger.dev RepoOps
authored andcommitted
feat(webapp): request a shared Slack support channel invite from the side menu and org settings
Mono-RevId: 1e0e0cdaf197355e3a2099c773e6439852d867d7
1 parent 814f262 commit b09836c

13 files changed

Lines changed: 493 additions & 17 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function SlackColorIcon({ className }: { className?: string }) {
2+
return (
3+
<svg className={className} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4+
<path
5+
fill="#E01E5A"
6+
d="M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zm1.271 0a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313z"
7+
/>
8+
<path
9+
fill="#36C5F0"
10+
d="M8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zm0 1.271a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312z"
11+
/>
12+
<path
13+
fill="#2EB67D"
14+
d="M18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zm-1.27 0a2.528 2.528 0 0 1-2.522 2.521 2.527 2.527 0 0 1-2.521-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.522 2.522v6.312z"
15+
/>
16+
<path
17+
fill="#ECB22E"
18+
d="M15.165 18.956a2.528 2.528 0 0 1 2.522 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.521-2.522v-2.522h2.521zm0-1.27a2.527 2.527 0 0 1-2.521-2.522 2.528 2.528 0 0 1 2.521-2.521h6.313A2.528 2.528 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.522h-6.313z"
19+
/>
20+
</svg>
21+
);
22+
}
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
import { CheckCircleIcon } from "@heroicons/react/20/solid";
2+
import { DialogClose } from "@radix-ui/react-dialog";
3+
import { Form, useFetcher, useLocation } from "@remix-run/react";
4+
import { type ReactNode, useState } from "react";
5+
import { SlackColorIcon } from "~/assets/icons/SlackColorIcon";
6+
import { slackConnectHiddenItemId, slackConnectState } from "~/components/slackConnectState";
7+
import { Feedback } from "~/components/Feedback";
8+
import { SideMenuItemButton } from "~/components/navigation/SideMenuItem";
9+
import { Button, LinkButton } from "~/components/primitives/Buttons";
10+
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from "~/components/primitives/Dialog";
11+
import { FormButtons } from "~/components/primitives/FormButtons";
12+
import { Paragraph } from "~/components/primitives/Paragraph";
13+
import { PermissionButton } from "~/components/primitives/PermissionButton";
14+
import { SettingsHeader, SettingsRow } from "~/components/primitives/SettingsLayout";
15+
import { TextLink } from "~/components/primitives/TextLink";
16+
import { SimpleTooltip } from "~/components/primitives/Tooltip";
17+
import { useFeatureFlags } from "~/hooks/useFeatureFlags";
18+
import { useCanManageBillingLimits, useOrganization } from "~/hooks/useOrganizations";
19+
import { useShowSelfServe } from "~/hooks/useShowSelfServe";
20+
import { useUser } from "~/hooks/useUser";
21+
import { useCurrentPlan } from "~/routes/_app.orgs.$organizationSlug/route";
22+
import {
23+
accountPath,
24+
sideMenuPreferencesPath,
25+
slackSupportInvitePath,
26+
v3BillingPath,
27+
} from "~/utils/pathBuilder";
28+
29+
const TITLE = "Talk to us on Slack";
30+
const DESCRIPTION = "Get support from the Trigger.dev team in a private Slack Connect channel.";
31+
const CHANNEL = "a private Slack Connect channel with the Trigger.dev team";
32+
33+
function useSlackConnect() {
34+
const featureFlags = useFeatureFlags();
35+
return slackConnectState({
36+
support: useCurrentPlan()?.v3Subscription?.plan?.limits.support,
37+
hasAccess: featureFlags.hasSlackSupportAccess === true,
38+
connected: featureFlags.hasSlackSupportChannel === true,
39+
});
40+
}
41+
42+
/** Bottom of the side menu, until the org has its channel or the user dismisses it. */
43+
export function SlackConnectSideMenuItem({ isCollapsed = false }: { isCollapsed?: boolean }) {
44+
const { offer, connected } = useSlackConnect();
45+
const itemId = slackConnectHiddenItemId(useOrganization().id);
46+
const hidden = useUser().dashboardPreferences.sideMenu?.hiddenItems?.[itemId] === true;
47+
const fetcher = useFetcher();
48+
49+
if (!offer || connected || hidden || fetcher.state !== "idle") return null;
50+
51+
const dismiss = () =>
52+
fetcher.submit(
53+
{
54+
customization: JSON.stringify({
55+
hiddenItems: { [itemId]: true },
56+
knownItemIds: [itemId],
57+
}),
58+
},
59+
{ method: "POST", action: sideMenuPreferencesPath() }
60+
);
61+
62+
return (
63+
<div className="border-t border-grid-bright p-1">
64+
<SlackConnectDialog
65+
trigger={
66+
<SideMenuItemButton
67+
icon={SlackColorIcon}
68+
// Brand logos have no internal padding, so they render one step smaller (as in the org menu).
69+
iconClassName="size-4 ml-0.5"
70+
name={TITLE}
71+
/>
72+
}
73+
onDismiss={dismiss}
74+
tooltip={isCollapsed}
75+
/>
76+
</div>
77+
);
78+
}
79+
80+
/** Org settings section. Always there with billing, whatever the side menu shows. */
81+
export function SlackConnectSettingsSection() {
82+
const { offer, connected } = useSlackConnect();
83+
const organization = useOrganization();
84+
const showSelfServe = useShowSelfServe();
85+
if (!offer) return null;
86+
// Free plans that can upgrade go straight to Billing; the modal would only repeat the row.
87+
const upgrade = offer === "upgrade" && showSelfServe;
88+
89+
const action = connected ? (
90+
<div className="flex items-center gap-3">
91+
<span className="flex items-center gap-1 text-xs text-success">
92+
<CheckCircleIcon className="size-3.5" />
93+
Connected
94+
</span>
95+
{/* Teammates who joined later still need their own invite. A downgraded org can't send one. */}
96+
{offer === "invite" ? (
97+
<SlackConnectDialog trigger={<Button variant="secondary/small">Invite me</Button>} />
98+
) : null}
99+
</div>
100+
) : upgrade ? (
101+
<LinkButton variant="secondary/small" to={v3BillingPath(organization)}>
102+
Upgrade
103+
</LinkButton>
104+
) : (
105+
<SlackConnectDialog trigger={<Button variant="secondary/small">Set up</Button>} />
106+
);
107+
108+
return (
109+
<div>
110+
<SettingsHeader title="Support" />
111+
<SettingsRow
112+
action={action}
113+
icon={<SlackColorIcon className="size-6 shrink-0" />}
114+
title={TITLE}
115+
description={
116+
connected
117+
? `Your team has ${CHANNEL}.`
118+
: offer === "upgrade"
119+
? `${DESCRIPTION} Included on Pro.`
120+
: DESCRIPTION
121+
}
122+
/>
123+
</div>
124+
);
125+
}
126+
127+
function SlackConnectDialog({
128+
trigger,
129+
onDismiss,
130+
tooltip = false,
131+
}: {
132+
trigger: ReactNode;
133+
onDismiss?: () => void;
134+
/** Collapsed side menu: the label is hidden, so show TITLE on hover like the other items. */
135+
tooltip?: boolean;
136+
}) {
137+
const [open, setOpen] = useState(false);
138+
const organization = useOrganization();
139+
const user = useUser();
140+
const location = useLocation();
141+
const showSelfServe = useShowSelfServe();
142+
const canManageBillingLimits = useCanManageBillingLimits();
143+
const { offer, connected } = useSlackConnect();
144+
145+
const email = <span className="text-text-bright">{user.email}</span>;
146+
const body =
147+
offer === "invite" ? (
148+
connected ? (
149+
<>
150+
Your team already has {CHANNEL}. We'll send an invite to join it to {email}.
151+
</>
152+
) : (
153+
<>
154+
Your plan includes {CHANNEL} for support. We'll send an invite to {email}.
155+
</>
156+
)
157+
) : showSelfServe ? (
158+
`Upgrade to Pro for ${CHANNEL}.`
159+
) : (
160+
`Pro plans include ${CHANNEL}. Ask us and we'll add it to your plan.`
161+
);
162+
163+
const confirmButton =
164+
offer === "invite" ? (
165+
<Form
166+
method="post"
167+
action={slackSupportInvitePath(organization)}
168+
onSubmit={() => setOpen(false)}
169+
>
170+
<input type="hidden" name="redirectPath" value={`${location.pathname}${location.search}`} />
171+
<PermissionButton
172+
type="submit"
173+
variant="primary/medium"
174+
hasPermission={canManageBillingLimits}
175+
noPermissionTooltip="You don't have permission to request a Slack invite"
176+
>
177+
Send invite
178+
</PermissionButton>
179+
</Form>
180+
) : showSelfServe ? (
181+
<LinkButton variant="primary/medium" to={v3BillingPath(organization)}>
182+
Upgrade
183+
</LinkButton>
184+
) : (
185+
<Feedback
186+
button={<Button variant="primary/medium">Request more…</Button>}
187+
defaultValue="help"
188+
/>
189+
);
190+
191+
return (
192+
<Dialog open={open} onOpenChange={setOpen}>
193+
{tooltip ? (
194+
<SimpleTooltip
195+
button={<DialogTrigger asChild>{trigger}</DialogTrigger>}
196+
content={TITLE}
197+
side="right"
198+
sideOffset={8}
199+
asChild
200+
tabbable
201+
disableHoverableContent
202+
/>
203+
) : (
204+
<DialogTrigger asChild>{trigger}</DialogTrigger>
205+
)}
206+
<DialogContent>
207+
<DialogHeader>
208+
<span className="flex items-center gap-2">
209+
<SlackColorIcon className="size-5" />
210+
Slack support
211+
</span>
212+
</DialogHeader>
213+
<div className="flex flex-col gap-3 pt-3">
214+
<Paragraph>{body}</Paragraph>
215+
{offer === "invite" && (
216+
// GitHub sign-ups often have a personal or noreply email; the invite can't be redirected once sent.
217+
<Paragraph variant="small/dimmed">
218+
Not the right email? <TextLink to={accountPath()}>Change it in your account</TextLink>{" "}
219+
first.
220+
</Paragraph>
221+
)}
222+
<FormButtons
223+
confirmButton={confirmButton}
224+
cancelButton={
225+
onDismiss ? (
226+
<Button variant="secondary/medium" onClick={onDismiss}>
227+
Don't show again
228+
</Button>
229+
) : (
230+
<DialogClose asChild>
231+
<Button variant="secondary/medium">Cancel</Button>
232+
</DialogClose>
233+
)
234+
}
235+
/>
236+
</div>
237+
</DialogContent>
238+
</Dialog>
239+
);
240+
}

‎apps/webapp/app/components/navigation/SideMenu.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
organizationTeamPath,
9292
organizationVercelIntegrationPath,
9393
v3BillingLimitsPath,
94+
sideMenuPreferencesPath,
9495
v3BillingPath,
9596
v3PrivateConnectionsPath,
9697
v3EnvironmentPath,
@@ -145,6 +146,7 @@ import {
145146
} from "./favoritePages";
146147
import { FavoriteMenuItem } from "./FavoritesSection";
147148
import { HelpAndFeedback } from "./HelpAndFeedbackPopover";
149+
import { SlackConnectSideMenuItem } from "~/components/SlackConnect";
148150
import { NotificationPanel } from "./NotificationPanel";
149151
import { SideMenuHeader } from "./SideMenuHeader";
150152
import { SideMenuItem, SideMenuLabel } from "./SideMenuItem";
@@ -382,7 +384,7 @@ export function SideMenu({
382384
customizeSubmitSeenRef.current = false;
383385
customizationFetcher.submit(
384386
{ customization: JSON.stringify(payload) },
385-
{ method: "POST", action: "/resources/preferences/sidemenu" }
387+
{ method: "POST", action: sideMenuPreferencesPath() }
386388
);
387389
};
388390
useEffect(() => {
@@ -470,7 +472,7 @@ export function SideMenu({
470472
}
471473
preferencesFetcher.submit(formData, {
472474
method: "POST",
473-
action: "/resources/preferences/sidemenu",
475+
action: sideMenuPreferencesPath(),
474476
});
475477
pendingPreferencesRef.current = {};
476478
}, 500);
@@ -508,7 +510,7 @@ export function SideMenu({
508510
}
509511
preferencesFetcher.submit(formData, {
510512
method: "POST",
511-
action: "/resources/preferences/sidemenu",
513+
action: sideMenuPreferencesPath(),
512514
});
513515
pendingPreferencesRef.current = {};
514516
};
@@ -1053,6 +1055,7 @@ export function SideMenu({
10531055
hasIncident={incidentStatus.hasIncident}
10541056
isManagedCloud={incidentStatus.isManagedCloud}
10551057
/>
1058+
<SlackConnectSideMenuItem isCollapsed={isCollapsed} />
10561059
<motion.div
10571060
layout
10581061
transition={{ duration: 0.2, ease: "easeInOut" }}

‎apps/webapp/app/components/navigation/useReorderableList.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useFetcher } from "@remix-run/react";
22
import { type Ref, useCallback, useEffect, useMemo, useRef, useState } from "react";
33
import type { Layout } from "react-grid-layout";
4+
import { sideMenuPreferencesPath } from "~/utils/pathBuilder";
45

56
/**
67
* Generic hook for managing a reorderable list in the side menu.
@@ -95,7 +96,7 @@ export function useReorderableList<T>({
9596
formData.append("itemOrder", JSON.stringify(newOrder));
9697
orderFetcher.submit(formData, {
9798
method: "POST",
98-
action: "/resources/preferences/sidemenu",
99+
action: sideMenuPreferencesPath(),
99100
});
100101
}
101102
},

‎apps/webapp/app/components/primitives/SettingsLayout.tsx‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const SETTINGS_ROW_TITLE_GAP = "space-y-0.5";
138138

139139
/**
140140
* A single settings row: title + description on the left, action on the right.
141+
* An `icon` sits before the title group, centred on it.
141142
*
142143
* Pass `title`/`description` for the common case, or `children` to supply
143144
* custom left-hand content (the built-in title group is skipped when `children`
@@ -147,6 +148,7 @@ export function SettingsRow({
147148
title,
148149
description,
149150
action,
151+
icon,
150152
htmlFor,
151153
children,
152154
className,
@@ -158,6 +160,7 @@ export function SettingsRow({
158160
title?: ReactNode;
159161
description?: ReactNode;
160162
action?: ReactNode;
163+
icon?: ReactNode;
161164
htmlFor?: string;
162165
children?: ReactNode;
163166
className?: string;
@@ -166,6 +169,17 @@ export function SettingsRow({
166169
align?: "center" | "start" | "end";
167170
bordered?: boolean;
168171
}) {
172+
const titleGroup = (
173+
<div className={cn("flex-1", SETTINGS_ROW_TITLE_GAP)}>
174+
{title ? (
175+
<SettingsRowTitle htmlFor={htmlFor} className={titleClassName}>
176+
{title}
177+
</SettingsRowTitle>
178+
) : null}
179+
{description ? <SettingsRowDescription>{description}</SettingsRowDescription> : null}
180+
</div>
181+
);
182+
169183
return (
170184
<div
171185
className={cn(
@@ -176,16 +190,15 @@ export function SettingsRow({
176190
className
177191
)}
178192
>
179-
{children ?? (
180-
<div className={cn("flex-1", SETTINGS_ROW_TITLE_GAP)}>
181-
{title ? (
182-
<SettingsRowTitle htmlFor={htmlFor} className={titleClassName}>
183-
{title}
184-
</SettingsRowTitle>
185-
) : null}
186-
{description ? <SettingsRowDescription>{description}</SettingsRowDescription> : null}
187-
</div>
188-
)}
193+
{children ??
194+
(icon ? (
195+
<div className="flex flex-1 items-center gap-3">
196+
{icon}
197+
{titleGroup}
198+
</div>
199+
) : (
200+
titleGroup
201+
))}
189202
{action ? <div className="flex flex-none items-center">{action}</div> : null}
190203
</div>
191204
);

0 commit comments

Comments
 (0)