Skip to content

Commit

Permalink
fix: fixed undefined issue for unapproved translations (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinayoob authored Nov 11, 2024
1 parent 07bc7c8 commit 3dfca53
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/Navbar/SettingsDrawer/TranslationSection.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import { useCallback, useMemo } from 'react';

import { Action } from '@reduxjs/toolkit';
Expand Down Expand Up @@ -67,19 +68,23 @@ const TranslationSection = () => {

const renderTranslations = useCallback(
(data: TranslationsResponse) => {
const availableTranslations = selectedTranslations.filter((selectedId) =>
data.translations.some((translation) => translation.id === selectedId),
);

const firstSelectedTranslation = data.translations.find(
(translation) => translation.id === selectedTranslations[0],
(translation) => translation.id === availableTranslations[0],
);

let selectedValueString = t('settings.no-translation-selected');
if (selectedTranslations.length === 1) selectedValueString = firstSelectedTranslation?.name;
if (selectedTranslations.length === 2) {
if (availableTranslations.length === 1) selectedValueString = firstSelectedTranslation?.name;
if (availableTranslations.length === 2) {
selectedValueString = t('settings.value-and-other', {
value: firstSelectedTranslation?.name,
othersCount: localizedSelectedTranslations,
});
}
if (selectedTranslations.length > 2) {
if (availableTranslations.length > 2) {
selectedValueString = t('settings.value-and-others', {
value: firstSelectedTranslation?.name,
othersCount: localizedSelectedTranslations,
Expand Down

0 comments on commit 3dfca53

Please sign in to comment.