@@ -33,7 +33,7 @@ const feedbackType = z.union(
33
33
export const schema = z . object ( {
34
34
path : z . string ( ) ,
35
35
feedbackType,
36
- message : z . string ( ) . min ( 1 , "Must be at least 1 character " ) ,
36
+ message : z . string ( ) . min ( 10 , "Must be at least 10 characters " ) ,
37
37
} ) ;
38
38
39
39
export async function action ( { request } : ActionFunctionArgs ) {
@@ -46,52 +46,8 @@ export async function action({ request }: ActionFunctionArgs) {
46
46
return json ( submission ) ;
47
47
}
48
48
49
+ const title = feedbackTypeLabel [ submission . value . feedbackType as FeedbackType ] ;
49
50
try {
50
- if ( ! env . PLAIN_API_KEY ) {
51
- console . error ( "PLAIN_API_KEY is not set" ) ;
52
- submission . error . message = "PLAIN_API_KEY is not set" ;
53
- return json ( submission ) ;
54
- }
55
-
56
- client = new PlainClient ( {
57
- apiKey : env . PLAIN_API_KEY ,
58
- } ) ;
59
-
60
- const upsertCustomerRes = await client . upsertCustomer ( {
61
- identifier : {
62
- emailAddress : user . email ,
63
- } ,
64
- onCreate : {
65
- externalId : user . id ,
66
- fullName : user . name ?? "" ,
67
- email : {
68
- email : user . email ,
69
- isVerified : true ,
70
- } ,
71
- } ,
72
- onUpdate : {
73
- externalId : { value : user . id } ,
74
- fullName : { value : user . name ?? "" } ,
75
- email : {
76
- email : user . email ,
77
- isVerified : true ,
78
- } ,
79
- } ,
80
- } ) ;
81
-
82
- if ( upsertCustomerRes . error ) {
83
- console . error (
84
- inspect ( upsertCustomerRes . error , {
85
- showHidden : false ,
86
- depth : null ,
87
- colors : true ,
88
- } )
89
- ) ;
90
- submission . error . message = upsertCustomerRes . error . message ;
91
- return json ( submission ) ;
92
- }
93
-
94
- const title = feedbackTypeLabel [ submission . value . feedbackType as FeedbackType ] ;
95
51
await sendToPlain ( {
96
52
userId : user . id ,
97
53
email : user . email ,
@@ -128,6 +84,7 @@ export async function action({ request }: ActionFunctionArgs) {
128
84
"Thanks for your feedback! We'll get back to you soon."
129
85
) ;
130
86
} catch ( e ) {
131
- return json ( e , { status : 400 } ) ;
87
+ submission . error . message = e instanceof Error ? e . message : "Unknown error" ;
88
+ return json ( submission ) ;
132
89
}
133
90
}
0 commit comments