5
5
XMarkIcon ,
6
6
} from "@heroicons/react/20/solid" ;
7
7
import { ArrowDownCircleIcon , XCircleIcon } from "@heroicons/react/24/outline" ;
8
- import { Form , useFetcher , useLocation , useNavigation } from "@remix-run/react" ;
8
+ import { Form , useLocation , useNavigation } from "@remix-run/react" ;
9
9
import { ActionFunctionArgs } from "@remix-run/server-runtime" ;
10
10
import { PlainClient , uiComponent } from "@team-plain/typescript-sdk" ;
11
11
import { GitHubLightIcon } from "@trigger.dev/companyicons" ;
@@ -17,7 +17,7 @@ import {
17
17
SetPlanBody ,
18
18
SubscriptionResult ,
19
19
} from "@trigger.dev/platform/v3" ;
20
- import { useState } from "react" ;
20
+ import React , { useState } from "react" ;
21
21
import { inspect } from "util" ;
22
22
import { z } from "zod" ;
23
23
import { DefinitionTip } from "~/components/DefinitionTooltip" ;
@@ -44,7 +44,6 @@ import { logger } from "~/services/logger.server";
44
44
import { setPlan } from "~/services/platform.v3.server" ;
45
45
import { requireUser } from "~/services/session.server" ;
46
46
import { cn } from "~/utils/cn" ;
47
- import React from "react" ;
48
47
49
48
const Params = z . object ( {
50
49
organizationSlug : z . string ( ) ,
@@ -68,8 +67,15 @@ export async function action({ request, params }: ActionFunctionArgs) {
68
67
const user = await requireUser ( request ) ;
69
68
70
69
const formData = await request . formData ( ) ;
70
+
71
+ // Log the form data for debugging
72
+ console . log ( "Form data:" , Object . fromEntries ( formData ) ) ;
73
+
71
74
const form = schema . parse ( Object . fromEntries ( formData ) ) ;
72
75
76
+ // Log the parsed form data
77
+ console . log ( "Parsed form data:" , form ) ;
78
+
73
79
const organization = await prisma . organization . findUnique ( {
74
80
where : { slug : organizationSlug } ,
75
81
} ) ;
@@ -82,6 +88,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
82
88
83
89
switch ( form . type ) {
84
90
case "free" : {
91
+ console . log ( "Entering free case" ) ;
85
92
try {
86
93
if ( ! env . PLAIN_API_KEY ) {
87
94
console . error ( "PLAIN_API_KEY is not set" ) ;
@@ -122,7 +129,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
122
129
colors : true ,
123
130
} )
124
131
) ;
125
- throw new Error ( upsertCustomerRes . error . message ) ;
132
+ throw redirectWithErrorMessage ( form . callerPath , request , upsertCustomerRes . error . message ) ;
126
133
}
127
134
128
135
const formData = await request . formData ( ) ;
@@ -145,8 +152,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
145
152
? [
146
153
uiComponent . spacer ( { size : "L" } ) ,
147
154
uiComponent . text ( {
148
- size : "S " ,
149
- color : "ERROR " ,
155
+ size : "L " ,
156
+ color : "NORMAL " ,
150
157
text : "Reasons:" ,
151
158
} ) ,
152
159
uiComponent . text ( {
@@ -158,8 +165,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
158
165
? [
159
166
uiComponent . spacer ( { size : "L" } ) ,
160
167
uiComponent . text ( {
161
- size : "S " ,
162
- color : "ERROR " ,
168
+ size : "L " ,
169
+ color : "NORMAL " ,
163
170
text : "Comment:" ,
164
171
} ) ,
165
172
uiComponent . text ( {
@@ -178,10 +185,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
178
185
colors : true ,
179
186
} )
180
187
) ;
181
- throw new Error ( createThreadRes . error . message ) ;
188
+ throw redirectWithErrorMessage ( form . callerPath , request , createThreadRes . error . message ) ;
182
189
}
183
190
}
184
191
} catch ( e ) {
192
+ console . error ( "Error in free case:" , e ) ;
185
193
logger . error ( "Failed to submit to Plain the unsubscribe reason" , { error : e } ) ;
186
194
}
187
195
payload = {
@@ -201,8 +209,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
201
209
} ;
202
210
break ;
203
211
}
212
+ default : {
213
+ console . error ( "Invalid form type:" , form . type ) ;
214
+ throw new Error ( "Invalid form type" ) ;
215
+ }
204
216
}
205
217
218
+ console . log ( "Final payload:" , payload ) ;
206
219
return setPlan ( organization , request , form . callerPath , payload ) ;
207
220
}
208
221
@@ -414,7 +427,7 @@ export function TierFree({
414
427
) : (
415
428
< >
416
429
{ subscription ?. plan ?. type !== "free" && subscription ?. canceledAt === undefined ? (
417
- < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } >
430
+ < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } key = "cancel" >
418
431
< DialogTrigger asChild >
419
432
< Button variant = "tertiary/large" fullWidth className = "text-md font-medium" >
420
433
{ `Downgrade to ${ plan . title } ` }
@@ -482,6 +495,7 @@ export function TierFree({
482
495
LeadingIcon = {
483
496
isLoading && "submitting" ? ( ) => < Spinner color = "white" /> : undefined
484
497
}
498
+ type = "submit"
485
499
form = "subscribe"
486
500
>
487
501
Downgrade plan
@@ -569,7 +583,7 @@ export function TierHobby({
569
583
subscription . plan . type !== "free" &&
570
584
subscription . canceledAt === undefined &&
571
585
subscription . plan . code !== plan . code ? (
572
- < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } >
586
+ < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } key = "downgrade" >
573
587
< DialogTrigger asChild >
574
588
< Button variant = "tertiary/large" fullWidth className = "text-md font-medium" >
575
589
{ `Downgrade to ${ plan . title } ` }
@@ -608,6 +622,7 @@ export function TierHobby({
608
622
variant = { isHighlighted ? "primary/large" : "tertiary/large" }
609
623
fullWidth
610
624
className = "text-md font-medium"
625
+ form = "subscribe-hobby"
611
626
disabled = {
612
627
isLoading ||
613
628
( subscription ?. plan ?. code === plan . code && subscription . canceledAt === undefined )
@@ -667,14 +682,15 @@ export function TierPro({
667
682
< TierLimit href = "https://trigger.dev/pricing#computePricing" >
668
683
${ plan . limits . includedUsage / 100 } usage included
669
684
</ TierLimit >
670
- < Form action = { formAction } method = "post" id = "subscribe" >
685
+ < Form action = { formAction } method = "post" id = "subscribe-pro " >
671
686
< div className = "py-6" >
672
687
< input type = "hidden" name = "type" value = "paid" />
673
688
< input type = "hidden" name = "planCode" value = { plan . code } />
674
689
< input type = "hidden" name = "callerPath" value = { location . pathname } />
675
690
< Button
676
691
variant = "tertiary/large"
677
692
fullWidth
693
+ form = "subscribe-pro"
678
694
className = "text-md font-medium"
679
695
disabled = {
680
696
isLoading ||
0 commit comments