mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-11 18:58:45 -06:00
fix: ensure survey.endings is always an array to prevent TypeError
Fixes FORMBRICKS-JE - Added default empty array for survey.endings in transformPrismaSurvey - Added defensive checks in progress-bar component and utils - Fixed migration to handle null endings - Prevents 'TypeError: e is not iterable' when survey.endings is null/undefined
This commit is contained in:
@@ -30,6 +30,7 @@ export const transformPrismaSurvey = <T extends TSurvey | TJsEnvironmentStateSur
|
||||
displayPercentage: Number(surveyPrisma.displayPercentage) || null,
|
||||
segment,
|
||||
customHeadScriptsMode: surveyPrisma.customHeadScriptsMode,
|
||||
endings: surveyPrisma.endings || [],
|
||||
} as T;
|
||||
|
||||
return transformedSurvey;
|
||||
|
||||
@@ -62,7 +62,7 @@ export const removeEmptyImageAndVideoUrlsFromElements: MigrationScript = {
|
||||
delete cleanedWelcomeCard.videoUrl;
|
||||
}
|
||||
|
||||
const cleanedEndings = survey.endings.map((ending) => {
|
||||
const cleanedEndings = (survey.endings || []).map((ending) => {
|
||||
const cleanedEnding = { ...ending };
|
||||
if (cleanedEnding.imageUrl === "") {
|
||||
delete cleanedEnding.imageUrl;
|
||||
|
||||
@@ -13,7 +13,7 @@ export function ProgressBar({ survey, blockId }: ProgressBarProps) {
|
||||
[survey.blocks, blockId]
|
||||
);
|
||||
|
||||
const endingCardIds = useMemo(() => survey.endings.map((ending) => ending.id), [survey.endings]);
|
||||
const endingCardIds = useMemo(() => (survey.endings || []).map((ending) => ending.id), [survey.endings]);
|
||||
|
||||
const calculateProgress = useCallback(
|
||||
(blockIndex: number) => {
|
||||
|
||||
@@ -87,7 +87,7 @@ export const calculateElementIdx = (
|
||||
const currentQuestion = questions[currentQustionIdx];
|
||||
const middleIdx = Math.floor(totalCards / 2);
|
||||
const possibleNextBlockIds = getPossibleNextBlocks(survey.blocks, currentQuestion);
|
||||
const endingCardIds = survey.endings.map((ending) => ending.id);
|
||||
const endingCardIds = (survey.endings || []).map((ending) => ending.id);
|
||||
|
||||
// Convert block IDs to element IDs (get first element of each block)
|
||||
const possibleNextQuestionIds = possibleNextBlockIds
|
||||
|
||||
Reference in New Issue
Block a user