Skip to content

Commit

Permalink
regression(i18n): Broken translations in Setup Wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Oct 24, 2024
1 parent dd03d94 commit 0029b60
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 69 deletions.
18 changes: 6 additions & 12 deletions apps/meteor/client/views/setupWizard/SetupWizardRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useBreakpoints } from '@rocket.chat/fuselage-hooks';
import { DarkModeProvider } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import React from 'react';
import { useTranslation, I18nextProvider } from 'react-i18next';

import ModalRegion from '../modal/ModalRegion';
import SetupWizardPage from './SetupWizardPage';
Expand All @@ -16,22 +15,17 @@ export const SetupWizardRoute = (): ReactElement | null => {
const isMobile = !breakpoints.includes('md');
useBodyPosition('relative', isMobile);

const { i18n } = useTranslation();

if (locked) {
return null;
}

return (
// FIXME: setting the defaultNS here is problematic for components/hooks expecting it to be 'core'
<I18nextProvider i18n={i18n} defaultNS='onboarding'>
<SetupWizardProvider>
<DarkModeProvider.default>
<SetupWizardPage />
<ModalRegion />
</DarkModeProvider.default>
</SetupWizardProvider>
</I18nextProvider>
<SetupWizardProvider>
<DarkModeProvider.default>
<SetupWizardPage />
<ModalRegion />
</DarkModeProvider.default>
</SetupWizardProvider>
);
};

Expand Down
24 changes: 13 additions & 11 deletions apps/meteor/client/views/setupWizard/steps/AdminInfoStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { escapeRegExp } from '@rocket.chat/string-helpers';
import { useSetting } from '@rocket.chat/ui-contexts';
import type { ReactElement, ComponentProps } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { I18nextProvider, useTranslation } from 'react-i18next';

import { useSetupWizardContext } from '../contexts/SetupWizardContext';

Expand All @@ -13,7 +13,7 @@ const hasBlockedName = (username: string): boolean =>
!!usernameBlackList.length && usernameBlackList.some((restrictedUsername) => restrictedUsername.test(escapeRegExp(username).trim()));

const AdminInfoStep = (): ReactElement => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const regexpForUsernameValidation = useSetting('UTF8_User_Names_Validation');
const usernameRegExp = new RegExp(`^${regexpForUsernameValidation}$`);

Expand All @@ -33,15 +33,17 @@ const AdminInfoStep = (): ReactElement => {
};

return (
<AdminInfoPage
validatePassword={(password): boolean => password.length > 0}
passwordRulesHint=''
validateUsername={validateUsername}
validateEmail={validateEmail}
currentStep={currentStep}
stepCount={maxSteps}
onSubmit={handleSubmit}
/>
<I18nextProvider i18n={i18n} defaultNS='onboarding'>
<AdminInfoPage
validatePassword={(password): boolean => password.length > 0}
passwordRulesHint=''
validateUsername={validateUsername}
validateEmail={validateEmail}
currentStep={currentStep}
stepCount={maxSteps}
onSubmit={handleSubmit}
/>
</I18nextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AwaitingConfirmationPage } from '@rocket.chat/onboarding-ui';
import { useToastMessageDispatch, useSettingSetValue, useEndpoint } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { I18nextProvider, useTranslation } from 'react-i18next';

import { useSetupWizardContext } from '../contexts/SetupWizardContext';

Expand All @@ -20,7 +20,7 @@ const CloudAccountConfirmation = (): ReactElement => {
const setShowSetupWizard = useSettingSetValue('Show_Setup_Wizard');
const cloudConfirmationPoll = useEndpoint('GET', '/v1/cloud.confirmationPoll');
const dispatchToastMessage = useToastMessageDispatch();
const { t } = useTranslation();
const { t, i18n } = useTranslation();

const getConfirmation = useCallback(async () => {
try {
Expand All @@ -47,14 +47,16 @@ const CloudAccountConfirmation = (): ReactElement => {
}, [getConfirmation, registrationData.interval]);

return (
<AwaitingConfirmationPage
currentStep={currentStep}
stepCount={maxSteps}
emailAddress={registrationData.cloudEmail}
securityCode={registrationData.user_code}
onResendEmailRequest={(): Promise<void> => registerServer({ email: registrationData.cloudEmail, resend: true })}
onChangeEmailRequest={(): void => goToStep(3)}
/>
<I18nextProvider i18n={i18n} defaultNS='onboarding'>
<AwaitingConfirmationPage
currentStep={currentStep}
stepCount={maxSteps}
emailAddress={registrationData.cloudEmail}
securityCode={registrationData.user_code}
onResendEmailRequest={(): Promise<void> => registerServer({ email: registrationData.cloudEmail, resend: true })}
onChangeEmailRequest={(): void => goToStep(3)}
/>
</I18nextProvider>
);
};

Expand Down
28 changes: 15 additions & 13 deletions apps/meteor/client/views/setupWizard/steps/OrganizationInfoStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRole } from '@rocket.chat/ui-contexts';
import type { TFunction } from 'i18next';
import type { ComponentProps, ReactElement } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { I18nextProvider, useTranslation } from 'react-i18next';

import { useSetupWizardContext } from '../contexts/SetupWizardContext';

Expand All @@ -28,7 +28,7 @@ const getSettingOptions = (
};

const OrganizationInfoStep = (): ReactElement => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const hasAdminRole = useRole('admin');

const {
Expand Down Expand Up @@ -61,17 +61,19 @@ const OrganizationInfoStep = (): ReactElement => {
};

return (
<OrganizationInfoPage
initialValues={organizationData}
onSubmit={handleSubmit}
onBackButtonClick={!hasAdminRole ? goToPreviousStep : undefined}
currentStep={currentStep}
stepCount={maxSteps}
organizationIndustryOptions={organizationIndustryOptions}
organizationSizeOptions={organizationSizeOptions}
countryOptions={countryOptions}
nextStep={skipCloudRegistration ? t('Register') : undefined}
/>
<I18nextProvider i18n={i18n} defaultNS='onboarding'>
<OrganizationInfoPage
initialValues={organizationData}
onSubmit={handleSubmit}
onBackButtonClick={!hasAdminRole ? goToPreviousStep : undefined}
currentStep={currentStep}
stepCount={maxSteps}
organizationIndustryOptions={organizationIndustryOptions}
organizationSizeOptions={organizationSizeOptions}
countryOptions={countryOptions}
nextStep={skipCloudRegistration ? t('Register') : undefined}
/>
</I18nextProvider>
);
};

Expand Down
20 changes: 11 additions & 9 deletions apps/meteor/client/views/setupWizard/steps/RegisterServerStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEndpoint, useMethod } from '@rocket.chat/ui-contexts';
import { useMutation, useQuery } from '@tanstack/react-query';
import type { ReactElement, ComponentProps } from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { I18nextProvider, useTranslation } from 'react-i18next';

import { useInvalidateLicense } from '../../../hooks/useLicense';
import { dispatchToastMessage } from '../../../lib/toast';
Expand All @@ -15,7 +15,7 @@ const SERVER_OPTIONS = {
};

const RegisterServerStep = (): ReactElement => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const { currentStep, goToNextStep, setSetupWizardData, registerServer, maxSteps, completeSetupWizard, saveAgreementData } =
useSetupWizardContext();
const [serverOption, setServerOption] = useState(SERVER_OPTIONS.REGISTERED);
Expand Down Expand Up @@ -82,13 +82,15 @@ const RegisterServerStep = (): ReactElement => {
}

return (
<RegisterServerPage
onClickRegisterOffline={(): void => setServerOption(SERVER_OPTIONS.OFFLINE)}
stepCount={maxSteps}
onSubmit={handleRegister}
currentStep={currentStep}
offline={isError || (!isLoading && offline)}
/>
<I18nextProvider i18n={i18n} defaultNS='onboarding'>
<RegisterServerPage
onClickRegisterOffline={(): void => setServerOption(SERVER_OPTIONS.OFFLINE)}
stepCount={maxSteps}
onSubmit={handleRegister}
currentStep={currentStep}
offline={isError || (!isLoading && offline)}
/>
</I18nextProvider>
);
};

Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8547,10 +8547,10 @@ __metadata:
"@rocket.chat/icons": "*"
"@rocket.chat/prettier-config": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 8.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-avatar": 8.0.0-rc.3
"@rocket.chat/ui-contexts": 12.0.0-rc.3
"@rocket.chat/ui-kit": 0.37.0-rc.0
"@rocket.chat/ui-video-conf": 12.0.0-rc.2
"@rocket.chat/ui-video-conf": 12.0.0-rc.3
"@tanstack/react-query": "*"
react: ~17.0.2
react-dom: "*"
Expand Down Expand Up @@ -8636,8 +8636,8 @@ __metadata:
"@rocket.chat/fuselage-tokens": "*"
"@rocket.chat/message-parser": 0.31.31
"@rocket.chat/styled": "*"
"@rocket.chat/ui-client": 12.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-client": 12.0.0-rc.3
"@rocket.chat/ui-contexts": 12.0.0-rc.3
katex: "*"
react: "*"
languageName: unknown
Expand Down Expand Up @@ -9888,7 +9888,7 @@ __metadata:
typescript: "npm:~5.6.3"
peerDependencies:
"@rocket.chat/fuselage": "*"
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.3
react: ~17.0.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -9938,8 +9938,8 @@ __metadata:
"@rocket.chat/fuselage": "*"
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/ui-avatar": 8.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-avatar": 8.0.0-rc.3
"@rocket.chat/ui-contexts": 12.0.0-rc.3
react: "*"
react-i18next: "*"
languageName: unknown
Expand Down Expand Up @@ -10109,8 +10109,8 @@ __metadata:
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 8.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-avatar": 8.0.0-rc.3
"@rocket.chat/ui-contexts": 12.0.0-rc.3
react: ~17.0.2
react-dom: ^17.0.2
languageName: unknown
Expand Down Expand Up @@ -10166,9 +10166,9 @@ __metadata:
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 8.0.0-rc.2
"@rocket.chat/ui-client": 12.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-avatar": 8.0.0-rc.3
"@rocket.chat/ui-client": 12.0.0-rc.3
"@rocket.chat/ui-contexts": 12.0.0-rc.3
react: ~17.0.2
react-aria: ~3.23.1
react-dom: ^17.0.2
Expand Down Expand Up @@ -10255,7 +10255,7 @@ __metadata:
peerDependencies:
"@rocket.chat/layout": "*"
"@rocket.chat/tools": 0.2.2
"@rocket.chat/ui-contexts": 12.0.0-rc.2
"@rocket.chat/ui-contexts": 12.0.0-rc.3
"@tanstack/react-query": "*"
react: "*"
react-hook-form: "*"
Expand Down

0 comments on commit 0029b60

Please sign in to comment.