@@ -33,7 +33,7 @@ const feedbackType = z.union(
3333export const schema = z . object ( {
3434 path : z . string ( ) ,
3535 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 " ) ,
3737} ) ;
3838
3939export async function action ( { request } : ActionFunctionArgs ) {
@@ -46,52 +46,8 @@ export async function action({ request }: ActionFunctionArgs) {
4646 return json ( submission ) ;
4747 }
4848
49+ const title = feedbackTypeLabel [ submission . value . feedbackType as FeedbackType ] ;
4950 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 ] ;
9551 await sendToPlain ( {
9652 userId : user . id ,
9753 email : user . email ,
@@ -128,6 +84,7 @@ export async function action({ request }: ActionFunctionArgs) {
12884 "Thanks for your feedback! We'll get back to you soon."
12985 ) ;
13086 } catch ( e ) {
131- return json ( e , { status : 400 } ) ;
87+ submission . error . message = e instanceof Error ? e . message : "Unknown error" ;
88+ return json ( submission ) ;
13289 }
13390}
0 commit comments