From e63c5565a6f758d4894811c553777beea1b08430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Tue, 26 Apr 2022 17:20:00 +0200 Subject: [PATCH] Merge pull request #7761 from overleaf/ta-settings-loading-screen Delay Settings Page Content Until Translations Are Ready GitOrigin-RevId: 0537367f672bd2e88c95248d15c5638887ff3aee --- .../js/features/settings/components/root.tsx | 73 +++++++++++-------- .../js/shared/hooks/use-wait-for-i18n.ts | 20 +++++ .../settings/components/root.test.tsx | 6 +- 3 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 services/web/frontend/js/shared/hooks/use-wait-for-i18n.ts diff --git a/services/web/frontend/js/features/settings/components/root.tsx b/services/web/frontend/js/features/settings/components/root.tsx index 27b6f2f464..c188415a44 100644 --- a/services/web/frontend/js/features/settings/components/root.tsx +++ b/services/web/frontend/js/features/settings/components/root.tsx @@ -11,49 +11,58 @@ import LeaveSection from './leave-section' import * as eventTracking from '../../../infrastructure/event-tracking' import { UserProvider } from '../../../shared/context/user-context' import { SSOProvider } from '../context/sso-context' +import useWaitForI18n from '../../../shared/hooks/use-wait-for-i18n' function SettingsPageRoot() { - const { t } = useTranslation() - const ssoError = getMeta('ol-ssoError') as string + const { isReady } = useWaitForI18n() useEffect(() => { eventTracking.sendMB('settings-view') }, []) + return ( +
+
+
+ {isReady ? : null} +
+
+
+ ) +} + +function SettingsPageContent() { + const { t } = useTranslation() + const ssoError = getMeta('ol-ssoError') as string + return ( -
-
-
- {ssoError ? ( - - {t('sso_link_error')}: {t(ssoError)} - - ) : null} -
-
-

{t('account_settings')}

-
-
- -
-
- -
-
- -
-
-
- - - - -
- -
+ {ssoError ? ( + + {t('sso_link_error')}: {t(ssoError)} + + ) : null} +
+
+

{t('account_settings')}

+
+
+ +
+
+ +
+
+
+
+ + + + +
+
diff --git a/services/web/frontend/js/shared/hooks/use-wait-for-i18n.ts b/services/web/frontend/js/shared/hooks/use-wait-for-i18n.ts new file mode 100644 index 0000000000..60f1144509 --- /dev/null +++ b/services/web/frontend/js/shared/hooks/use-wait-for-i18n.ts @@ -0,0 +1,20 @@ +import { useEffect, useState } from 'react' +import i18n from '../../../js/i18n' +import { useTranslation } from 'react-i18next' + +function useWaitForI18n() { + const { ready: isHookReady } = useTranslation() + const [isLocaleDataLoaded, setIsLocaleDataLoaded] = useState(false) + + useEffect(() => { + i18n.then(() => { + setIsLocaleDataLoaded(true) + }) + }, []) + + return { + isReady: isHookReady && isLocaleDataLoaded, + } +} + +export default useWaitForI18n diff --git a/services/web/test/frontend/features/settings/components/root.test.tsx b/services/web/test/frontend/features/settings/components/root.test.tsx index 6cc5a2b8c0..826fea8107 100644 --- a/services/web/test/frontend/features/settings/components/root.test.tsx +++ b/services/web/test/frontend/features/settings/components/root.test.tsx @@ -1,5 +1,5 @@ import sinon from 'sinon' -import { screen, render } from '@testing-library/react' +import { screen, render, waitFor } from '@testing-library/react' import * as eventTracking from '../../../../../frontend/js/infrastructure/event-tracking' import SettingsPageRoot from '../../../../../frontend/js/features/settings/components/root' @@ -34,6 +34,10 @@ describe('', function () { it('displays page', async function () { render() + await waitFor(() => { + screen.getByText('Account Settings') + }) + screen.getByRole('button', { name: 'Delete your account', })