Skip to content

Commit 55ce0fe

Browse files
committed
Merge branch 'main' of https://github.com/NotePlan/plugins
2 parents bf1feca + 62fcafc commit 55ce0fe

File tree

7 files changed

+771
-593
lines changed

7 files changed

+771
-593
lines changed

dwertheimer.Forms/src/components/FormBrowserView.jsx

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,17 @@ export function FormBrowserView({
526526
const handleSave = useCallback(
527527
(formValues: Object, windowId?: string) => {
528528
logDebug('FormBrowserView', 'Form submitted:', formValues)
529+
530+
// Clear any previous errors before submitting
531+
dispatch('UPDATE_DATA', {
532+
...data,
533+
pluginData: {
534+
...pluginData,
535+
formSubmissionError: '',
536+
aiAnalysisResult: '',
537+
},
538+
})
539+
529540
// Send to plugin for processing
530541
// Include keepOpenOnSubmit flag so the plugin knows not to close the window
531542
if (requestFromPlugin) {
@@ -537,6 +548,60 @@ export function FormBrowserView({
537548
})
538549
.then((responseData) => {
539550
logDebug('FormBrowserView', 'Form submission response:', responseData)
551+
552+
// Check if the response indicates success or failure
553+
// The responseData may be the data object from a successful response, or it may contain error info
554+
if (responseData && typeof responseData === 'object') {
555+
// Check for error indicators in the response (from pluginData)
556+
const pluginDataFromResponse = responseData.pluginData || {}
557+
const hasError = pluginDataFromResponse.formSubmissionError || pluginDataFromResponse.aiAnalysisResult || responseData.formSubmissionError || responseData.aiAnalysisResult
558+
if (hasError) {
559+
// Extract error message
560+
let errorMessage = 'Form submission failed.'
561+
const formError = pluginDataFromResponse.formSubmissionError || responseData.formSubmissionError
562+
const aiError = pluginDataFromResponse.aiAnalysisResult || responseData.aiAnalysisResult
563+
564+
if (formError) {
565+
errorMessage = formError
566+
} else if (aiError) {
567+
// Extract a brief summary from AI analysis
568+
const aiMsg = aiError
569+
const firstLine = aiMsg.split('\n')[0] || aiMsg.substring(0, 200)
570+
errorMessage = `Template error: ${firstLine}`
571+
}
572+
573+
logError('FormBrowserView', `Form submission failed: ${errorMessage}`)
574+
575+
// Update pluginData with error so FormErrorBanner can display it
576+
dispatch('UPDATE_DATA', {
577+
...data,
578+
pluginData: {
579+
...pluginData,
580+
formSubmissionError: formError || errorMessage,
581+
aiAnalysisResult: aiError || '',
582+
},
583+
})
584+
585+
dispatch('SHOW_TOAST', {
586+
type: 'ERROR',
587+
msg: errorMessage,
588+
timeout: 10000, // Longer timeout for error messages
589+
})
590+
// Don't reset form on error - keep it open so user can fix and retry
591+
return
592+
}
593+
}
594+
595+
// Clear any errors on successful submission
596+
dispatch('UPDATE_DATA', {
597+
...data,
598+
pluginData: {
599+
...pluginData,
600+
formSubmissionError: '',
601+
aiAnalysisResult: '',
602+
},
603+
})
604+
540605
// Show success toast with note information
541606
let successMessage = 'Your form has been submitted successfully.'
542607
if (responseData?.noteTitle) {
@@ -568,16 +633,27 @@ export function FormBrowserView({
568633
logError('FormBrowserView', `Error submitting form: ${error.message}`)
569634
// On error, show Toast notification but don't close the window
570635
// The window should stay open so user can fix and retry
636+
const errorMessage = error.message || 'An error occurred while submitting the form'
637+
638+
// Update pluginData with error so FormErrorBanner can display it
639+
dispatch('UPDATE_DATA', {
640+
...data,
641+
pluginData: {
642+
...pluginData,
643+
formSubmissionError: errorMessage,
644+
},
645+
})
646+
571647
dispatch('SHOW_TOAST', {
572648
type: 'ERROR',
573-
msg: error.message || 'An error occurred while submitting the form',
574-
timeout: 5000,
649+
msg: errorMessage,
650+
timeout: 10000, // Longer timeout for error messages
575651
})
576652
// Don't reset form on error - let user see what they entered
577653
})
578654
}
579655
},
580-
[selectedTemplate, requestFromPlugin, handleCancel, dispatch],
656+
[selectedTemplate, requestFromPlugin, handleCancel, dispatch, data, pluginData],
581657
)
582658

583659

0 commit comments

Comments
 (0)