@@ -16,6 +16,7 @@ import { useOrganization } from "~/hooks/useOrganizations";
1616import { useShowSelfServe } from "~/hooks/useShowSelfServe" ;
1717import { logger } from "~/services/logger.server" ;
1818import { getCurrentPlan } from "~/services/platform.v3.server" ;
19+ import { isSupportChannelEnabled } from "~/services/supportChannelFlag.server" ;
1920import { dashboardAction , dashboardLoader } from "~/services/routeBuilders/dashboardBuilder" ;
2021import { getUserId } from "~/services/session.server" ;
2122import {
@@ -59,6 +60,12 @@ export const loader = dashboardLoader(
5960 throw new Response ( "Not Found" , { status : 404 } ) ;
6061 }
6162
63+ // Flag off means the feature does not exist yet, so 404 rather than render
64+ // an upsell for something nobody can buy.
65+ if ( ! ( await isSupportChannelEnabled ( organizationId ) ) ) {
66+ throw new Response ( "Not Found" , { status : 404 } ) ;
67+ }
68+
6269 const supportChannel = await prisma . organizationSupportChannel . findFirst ( {
6370 where : { organizationId } ,
6471 } ) ;
@@ -89,6 +96,10 @@ export const action = dashboardAction(
8996 throw new Response ( "Not Found" , { status : 404 } ) ;
9097 }
9198
99+ if ( ! ( await isSupportChannelEnabled ( organizationId ) ) ) {
100+ throw new Response ( "Not Found" , { status : 404 } ) ;
101+ }
102+
92103 const formData = await request . formData ( ) ;
93104 const result = ActionSchema . safeParse ( { intent : formData . get ( "intent" ) } ) ;
94105 if ( ! result . success ) {
@@ -100,6 +111,16 @@ export const action = dashboardAction(
100111 return json ( { error : "Upgrade required" } , { status : 403 } ) ;
101112 }
102113
114+ // A live channel already covers this org. Without this an out-of-band POST
115+ // would flip the row back to PROVISIONING and re-send the Slack invite.
116+ const existing = await prisma . organizationSupportChannel . findFirst ( {
117+ where : { organizationId } ,
118+ select : { status : true } ,
119+ } ) ;
120+ if ( existing ?. status === "INVITED" || existing ?. status === "LINKED" ) {
121+ return redirect ( organizationSupportPath ( { slug : params . organizationSlug } ) ) ;
122+ }
123+
103124 try {
104125 await enqueueProvisionSupportChannel ( { organizationId } ) ;
105126 } catch ( error ) {
0 commit comments