Skip to content

Commit

Permalink
fix: validation UI (formbricks#3137)
Browse files Browse the repository at this point in the history
Co-authored-by: Dhruwang <[email protected]>
  • Loading branch information
pandeymangg and Dhruwang authored Sep 12, 2024
1 parent 426a0a3 commit 1e2fe7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ export const SurveyMenuBar = ({
(invalidLanguage: string) => getLanguageLabel(invalidLanguage) ?? invalidLanguage
);

toast.error(`${currentError.message} ${invalidLanguageLabels.join(", ")}`);
const messageSplit = currentError.message.split("-fLang-")[0];

toast.error(`${messageSplit} ${invalidLanguageLabels.join(", ")}`);
} else {
toast.error(currentError.message);
}
Expand Down
12 changes: 10 additions & 2 deletions packages/types/surveys/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ export const validateQuestionLabels = (
const messageField = FIELD_TO_LABEL_MAP[field] ? FIELD_TO_LABEL_MAP[field] : field;
const messageSuffix = isDefaultOnly ? " is missing" : " is missing for the following languages: ";

const message = isDefaultOnly
? `${messagePrefix}${messageField} in question ${String(questionIndex + 1)}${messageSuffix}`
: `${messagePrefix}${messageField} in question ${String(questionIndex + 1)}${messageSuffix} -fLang- ${invalidLanguageCodes.join()}`;

if (invalidLanguageCodes.length) {
return {
code: z.ZodIssueCode.custom,
message: `${messagePrefix}${messageField} in question ${String(questionIndex + 1)}${messageSuffix} ${invalidLanguageCodes.join()}`,
message,
path: ["questions", questionIndex, field],
params: isDefaultOnly ? undefined : { invalidLanguageCodes },
};
Expand Down Expand Up @@ -134,10 +138,14 @@ export const validateCardFieldsForAllLanguages = (
const messageField = FIELD_TO_LABEL_MAP[field] ? FIELD_TO_LABEL_MAP[field] : field;
const messageSuffix = isDefaultOnly ? " is missing" : " is missing for the following languages: ";

const message = isDefaultOnly
? `${messagePrefix}${messageField} on the ${cardTypeLabel}${messageSuffix}`
: `${messagePrefix}${messageField} on the ${cardTypeLabel}${messageSuffix} -fLang- ${invalidLanguageCodes.join()}`;

if (invalidLanguageCodes.length) {
return {
code: z.ZodIssueCode.custom,
message: `${messagePrefix}${messageField} on the ${cardTypeLabel} ${messageSuffix} ${invalidLanguageCodes.join()}`,
message,
path,
params: isDefaultOnly ? undefined : { invalidLanguageCodes },
};
Expand Down

0 comments on commit 1e2fe7b

Please sign in to comment.