@@ -67,6 +67,8 @@ export class FeedbackForm {
67
67
@Prop ( { mutable : true } ) placeholder : string ;
68
68
@Prop ( ) fontFamily : string = 'Calibri' ; // Default font family doesnt work when initialvalue has font
69
69
@Prop ( ) fontSize : string ; // Default font size prop
70
+ @State ( ) uploadedFile : File | null = null ;
71
+
70
72
@Element ( ) el : HTMLElement ;
71
73
72
74
@Event ( ) valueChange : EventEmitter < string > ;
@@ -83,9 +85,13 @@ export class FeedbackForm {
83
85
} ,
84
86
} ;
85
87
//https://fluid.libertymutual.com/fluid/fluid-file-upload.html
86
- fileListUpdated ( event ) {
87
- console . log ( event . detail ) ;
88
+ fileListUpdated ( event : CustomEvent ) {
89
+ console . log ( 'uploaded file' + event . detail ) ;
90
+ const files = event . detail ;
91
+ if ( files && files . length > 0 ) {
92
+ this . uploadedFile = files [ 0 ] ; // Store the first uploaded file
88
93
}
94
+ }
89
95
//https://fluid-components.libertymutual.com/fluid/fluid-file-upload.html
90
96
uploadClicked ( event ) {
91
97
console . log ( event . detail ) ;
@@ -317,7 +323,7 @@ export class FeedbackForm {
317
323
}
318
324
//Before performing any operations- GET or SET- ensure that the this.editor instance is available
319
325
//send email also without backend
320
- async getContentFromEditor ( ) {
326
+ async sendEmail ( ) {
321
327
if ( this . editor ) {
322
328
// Access properties or methods of the TinyMCE editor instance
323
329
this . editorContent = this . editor . getContent ( ) ;
@@ -348,6 +354,16 @@ export class FeedbackForm {
348
354
alert ( 'Please fill out first 3 fields before submitting.' ) ;
349
355
return ;
350
356
}
357
+ if ( ! this . uploadedFile ) {
358
+ console . error ( "No file uploaded." ) ;
359
+ return ;
360
+ }
361
+
362
+ const formData = new FormData ( ) ;
363
+ formData . append ( 'file' , this . uploadedFile ) ;
364
+ formData . append ( 'name' , this . userName ) ;
365
+ formData . append ( 'email' , this . userEmail ) ;
366
+ formData . append ( 'message' , this . editorContent ) ;
351
367
// Call EmailJS to send the email (Browser based or client based)
352
368
//Emailjs dashboard: https://dashboard.emailjs.com/sign-up
353
369
//templateParams is this.editorContent
@@ -357,7 +373,8 @@ export class FeedbackForm {
357
373
'template_szeawas' , // Template ID from EmailJS dashboard
358
374
{ user_name : this . userName ,
359
375
user_email : this . userEmail ,
360
- content : this . editorContent } , // Template parameters (the content of the email)
376
+ content : this . editorContent ,
377
+ file : this . uploadedFile } , // Template parameters (the content of the email)
361
378
{
362
379
publicKey : 'IRGsyXDXq7ZJHMbzF' ,
363
380
} // Your user ID from EmailJS: YOUR_PUBLIC_KEY
@@ -447,12 +464,11 @@ export class FeedbackForm {
447
464
aria-placeholder = { this . placeholder } > </ div >
448
465
</ label >
449
466
< fluid-file-upload
450
- uploadControlConfig = "uploadControlConfig"
451
- fileListUpdated = "fileListUpdated($event)"
467
+ onFileListUpdated = { ( event ) => this . fileListUpdated ( event ) }
452
468
uploadClicked = "uploadClicked($event)"
453
469
showFileList = "false" >
454
470
</ fluid-file-upload >
455
- < button onClick = { ( ) => this . getContentFromEditor ( ) } > Submit</ button >
471
+ < button onClick = { ( ) => this . sendEmail ( ) } > Submit</ button >
456
472
< button onClick = { ( ) => this . setContentInEditor ( '' ) } > Clear Content</ button >
457
473
</ div >
458
474
) ;
0 commit comments