mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-10 00:40:21 -06:00
fix: mls missing language toggle (#3143)
Co-authored-by: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6ab2560432
commit
59ebde49cf
@@ -4,7 +4,7 @@ import * as Collapsible from "@radix-ui/react-collapsible";
|
||||
import { ArrowUpRight, Languages } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import type { FC } from "react";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { cn } from "@formbricks/lib/cn";
|
||||
import { addMultiLanguageLabels, extractLanguageCodes } from "@formbricks/lib/i18n/utils";
|
||||
import type { TLanguage, TProduct } from "@formbricks/types/product";
|
||||
@@ -59,10 +59,9 @@ export const MultiLanguageCard: FC<MultiLanguageCardProps> = ({
|
||||
onConfirm: () => {},
|
||||
});
|
||||
|
||||
const [defaultLanguage, setDefaultLanguage] = useState(
|
||||
localSurvey.languages.find((language) => {
|
||||
return language.default;
|
||||
})?.language
|
||||
const defaultLanguage = useMemo(
|
||||
() => localSurvey.languages.find((language) => language.default)?.language,
|
||||
[localSurvey.languages]
|
||||
);
|
||||
|
||||
const setOpen = (open: boolean) => {
|
||||
@@ -73,6 +72,12 @@ export const MultiLanguageCard: FC<MultiLanguageCardProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (localSurvey.languages.length === 0) {
|
||||
setIsMultiLanguageActivated(false);
|
||||
}
|
||||
}, [localSurvey.languages]);
|
||||
|
||||
const updateSurveyTranslations = (survey: TSurvey, updatedLanguages: TSurveyLanguage[]) => {
|
||||
const translatedSurveyResult = addMultiLanguageLabels(survey, extractLanguageCodes(updatedLanguages));
|
||||
|
||||
@@ -132,7 +137,6 @@ export const MultiLanguageCard: FC<MultiLanguageCardProps> = ({
|
||||
});
|
||||
}
|
||||
|
||||
setDefaultLanguage(language);
|
||||
setConfirmationModalInfo({ ...confirmationModalInfo, open: false });
|
||||
updateSurvey({ languages: newLanguages });
|
||||
}
|
||||
@@ -150,7 +154,6 @@ export const MultiLanguageCard: FC<MultiLanguageCardProps> = ({
|
||||
onConfirm: () => {
|
||||
updateSurveyTranslations(localSurvey, []);
|
||||
setIsMultiLanguageActivated(false);
|
||||
setDefaultLanguage(undefined);
|
||||
setConfirmationModalInfo({ ...confirmationModalInfo, open: false });
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user