diff --git a/components/common/FeedbackForm.js b/components/common/FeedbackForm.js
index ad1c52fd..a0a4185d 100644
--- a/components/common/FeedbackForm.js
+++ b/components/common/FeedbackForm.js
@@ -58,7 +58,12 @@ const FeedbackForm = ({
const t = useTranslations();
const [sent, setSent] = useState(false);
- const onDismiss = () => setSent(false);
+ const [formEmptyError, setFormEmptyError] = useState(false);
+ const onDismiss = () => {
+ setSent(false);
+ setFormEmptyError(false);
+ };
+
const pathname = usePathname();
const searchParams = useSearchParams();
@@ -70,6 +75,26 @@ const FeedbackForm = ({
const onSubmit = (formData) => {
const { name, email, comment, ...additionalResponse } = formData;
+ const isCommentEmpty = !comment || comment.trim() === '';
+ const areAllAdditionalFieldsEmpty = Object.values(additionalResponse).every(
+ (value) => {
+ if (Array.isArray(value)) {
+ return value.length === 0;
+ }
+ return value === '' || value === null || value === undefined;
+ }
+ );
+
+ const isFormEffectivelyEmpty =
+ feedbackSetting !== 'required' &&
+ isCommentEmpty &&
+ areAllAdditionalFieldsEmpty;
+
+ if (isFormEffectivelyEmpty) {
+ setFormEmptyError(true);
+ return;
+ }
+
const data = {
name,
email: emailSetting !== 'excluded' ? email : undefined,
@@ -85,6 +110,7 @@ const FeedbackForm = ({
),
};
setSent(true);
+ setFormEmptyError(false);
createUserFeedback({ variables: { input: data } });
};
const renderAdditionalField = (field) => {
@@ -292,6 +318,16 @@ const FeedbackForm = ({
{t('feedback-error-content')}
)}
+ {formEmptyError && (
+
+ {t('form-effectively-empty-error')}
+
+ )}