Skip to content

Commit f2c7799

Browse files
authored
refactor(experience,phrases): update resend passcode phrases (#6103)
1 parent d123d46 commit f2c7799

File tree

18 files changed

+91
-52
lines changed

18 files changed

+91
-52
lines changed

packages/experience/src/containers/VerificationCode/index.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import resource from '@logto/phrases-experience';
12
import { SignInIdentifier } from '@logto/schemas';
23
import { act, fireEvent, waitFor } from '@testing-library/react';
34

@@ -8,6 +9,7 @@ import {
89
addProfileWithVerificationCodeIdentifier,
910
} from '@/apis/interaction';
1011
import { sendVerificationCodeApi } from '@/apis/utils';
12+
import { setupI18nForTesting } from '@/jest.setup';
1113
import { UserFlow } from '@/types';
1214

1315
import VerificationCode from '.';
@@ -69,19 +71,37 @@ describe('<VerificationCode />', () => {
6971
});
7072

7173
it('fire resend event', async () => {
74+
/**
75+
* Apply the resource with resend_passcode for testing nested translation
76+
* Since the 'resend_passcode' phrase need be rendered into the following structure for testing:
77+
* ```
78+
* <div>Not received yet? <a>Resend verification code</a></div>
79+
* ```
80+
* otherwise this phrase will be rendered as 'description.resend_passcode'.
81+
* That will cause the resend button cannot be clicked.
82+
*/
83+
await setupI18nForTesting({
84+
translation: {
85+
description: { resend_passcode: resource.en.translation.description.resend_passcode },
86+
},
87+
});
88+
7289
const { getByText } = renderWithPageContext(
7390
<VerificationCode flow={UserFlow.SignIn} identifier={SignInIdentifier.Email} target={email} />
7491
);
7592
act(() => {
7693
jest.advanceTimersByTime(1e3 * 60);
7794
});
78-
const resendButton = getByText('description.resend_passcode');
95+
const resendButton = getByText('Resend verification code');
7996

8097
await waitFor(() => {
8198
fireEvent.click(resendButton);
8299
});
83100

84101
expect(sendVerificationCodeApi).toBeCalledWith(UserFlow.SignIn, { email });
102+
103+
// Reset i18n
104+
await setupI18nForTesting();
85105
});
86106

87107
describe('sign-in', () => {

packages/experience/src/containers/VerificationCode/index.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,30 @@ const VerificationCode = ({ flow, identifier, className, hasPasswordButton, targ
6161
error={errorMessage}
6262
onChange={setCode}
6363
/>
64-
{isRunning ? (
65-
<div className={styles.message}>
64+
<div className={styles.message}>
65+
{isRunning ? (
6666
<Trans components={{ span: <span key="counter" /> }}>
6767
{t('description.resend_after_seconds', { seconds })}
6868
</Trans>
69-
</div>
70-
) : (
71-
<TextLink
72-
className={styles.link}
73-
text="description.resend_passcode"
74-
onClick={async () => {
75-
clearErrorMessage();
76-
await onResendVerificationCode();
77-
setCode([]);
78-
}}
79-
/>
80-
)}
81-
69+
) : (
70+
<Trans
71+
components={{
72+
a: (
73+
<TextLink
74+
className={styles.link}
75+
onClick={async () => {
76+
clearErrorMessage();
77+
await onResendVerificationCode();
78+
setCode([]);
79+
}}
80+
/>
81+
),
82+
}}
83+
>
84+
{t('description.resend_passcode')}
85+
</Trans>
86+
)}
87+
</div>
8288
{flow === UserFlow.SignIn && hasPasswordButton && (
8389
<PasswordSignInLink method={identifier} target={target} className={styles.switch} />
8490
)}

packages/experience/src/jest.setup.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
22

3+
import { type LocalePhrase } from '@logto/phrases-experience';
4+
import { type DeepPartial } from '@silverhand/essentials';
35
import i18next from 'i18next';
46
import { initReactI18next } from 'react-i18next';
57

@@ -19,9 +21,18 @@ Object.defineProperty(window, 'matchMedia', {
1921
})),
2022
});
2123

22-
void i18next.use(initReactI18next).init({
23-
// Simple resources for testing
24-
resources: { en: { translation: { action: { agree: 'Agree' } } } },
25-
lng: 'en',
26-
react: { useSuspense: false },
27-
});
24+
// Simple resources for testing
25+
const defaultI18nResources: DeepPartial<LocalePhrase> = {
26+
translation: { action: { agree: 'Agree' } },
27+
};
28+
29+
export const setupI18nForTesting = async (
30+
enPhrase: DeepPartial<LocalePhrase> = defaultI18nResources
31+
) =>
32+
i18next.use(initReactI18next).init({
33+
resources: { en: enPhrase },
34+
lng: 'en',
35+
react: { useSuspense: false },
36+
});
37+
38+
void setupI18nForTesting();

packages/phrases-experience/src/locales/de/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'und',
1515
enter_passcode: 'Der Bestätigungscode wurde an deine {{address}} gesendet',
1616
passcode_sent: 'Der Bestätigungscode wurde erneut gesendet',
17-
resend_after_seconds: 'Nach <span>{{seconds}}</span> Sekunden erneut senden',
18-
resend_passcode: 'Bestätigungscode erneut senden',
17+
resend_after_seconds: 'Noch nicht erhalten? Erneut senden nach <span>{{seconds}}</span> Sekunden',
18+
resend_passcode: 'Noch nicht erhalten? <a>Bestätigungscode erneut senden</a>',
1919
create_account_id_exists:
2020
'Das Konto mit {{type}} {{value}} existiert bereits, möchtest du dich anmelden?',
2121
link_account_id_exists:

packages/phrases-experience/src/locales/en/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'and',
1515
enter_passcode: 'The verification code has been sent to your {{address}} {{target}}',
1616
passcode_sent: 'The verification code has been resent',
17-
resend_after_seconds: 'Resend after <span>{{seconds}}</span> seconds',
18-
resend_passcode: 'Resend verification code',
17+
resend_after_seconds: 'Not received yet? Resend after <span>{{seconds}}</span> seconds',
18+
resend_passcode: 'Not received yet? <a>Resend verification code</a>',
1919
create_account_id_exists:
2020
'The account with {{type}} {{value}} already exists, would you like to sign in?',
2121
link_account_id_exists:

packages/phrases-experience/src/locales/es/description.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const description = {
1414
and: 'y',
1515
enter_passcode: 'El código de verificación ha sido enviado a su {{address}} {{target}}',
1616
passcode_sent: 'El código de verificación ha sido reenviado',
17-
resend_after_seconds: 'Reenviar después de <span>{{seconds}}</span> segundos',
18-
resend_passcode: 'Reenviar código de verificación',
17+
resend_after_seconds:
18+
'¿No lo has recibido? Reenviar después de <span>{{seconds}}</span> segundos',
19+
resend_passcode: '¿No lo has recibido? <a>Reenviar código de verificación</a>',
1920
create_account_id_exists: 'La cuenta con {{type}} {{value}} ya existe, ¿desea iniciar sesión?',
2021
link_account_id_exists: 'La cuenta con {{type}} {{value}} ya existe. ¿Desea vincular?',
2122
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/fr/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'et',
1515
enter_passcode: 'Le code a été envoyé à {{address}} {{target}}',
1616
passcode_sent: 'Le code a été renvoyé',
17-
resend_after_seconds: 'Renvoyer après <span>{{seconds}}</span> secondes',
18-
resend_passcode: 'Renvoyer le code',
17+
resend_after_seconds: 'Pas encore reçu ? Renvoyer après <span>{{seconds}}</span> secondes',
18+
resend_passcode: 'Pas encore reçu ? <a>Renvoyer le code de vérification</a>',
1919
create_account_id_exists:
2020
'Le compte avec {{type}} {{value}} existe déjà, voulez-vous vous connecter?',
2121
link_account_id_exists: 'Le compte avec {{type}} {{value}} existe déjà, voulez-vous le lier?',

packages/phrases-experience/src/locales/it/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'e',
1515
enter_passcode: 'Il codice di verifica è stato inviato alla tua {{address}} {{target}}',
1616
passcode_sent: 'Il codice di verifica è stato inviato di nuovo',
17-
resend_after_seconds: 'Inviare di nuovo dopo <span>{{seconds}}</span> secondi',
18-
resend_passcode: 'Inviare nuovamente il codice di verifica',
17+
resend_after_seconds: 'Non ricevuto? Invia di nuovo dopo <span>{{seconds}}</span> secondi',
18+
resend_passcode: 'Non ricevuto? <a>Invia di nuovo il codice di verifica</a>',
1919
create_account_id_exists: "L'account con {{type}} {{value}} già esiste, vuoi accedere?",
2020
link_account_id_exists: "L'account con {{type}} {{value}} è già esistente. Vuoi collegarlo?",
2121
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/ja/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: '及び',
1515
enter_passcode: '確認コードが{{address}} {{target}}に送信されました',
1616
passcode_sent: '確認コードを再送します',
17-
resend_after_seconds: '<span>{{seconds}}</span>秒後に再送信',
18-
resend_passcode: '確認コードを再送信します',
17+
resend_after_seconds: 'まだ届いていませんか? <span>{{seconds}}</span> 秒後に再送',
18+
resend_passcode: 'まだ届いていませんか? <a>認証コードを再送</a>',
1919
create_account_id_exists:
2020
'{{type}} {{value}}でアカウントが既に存在しています。ログインしますか?',
2121
link_account_id_exists: '{{type}} {{value}}でアカウントが既に存在しています。リンクしますか?',

packages/phrases-experience/src/locales/ko/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: '그리고',
1515
enter_passcode: '{{address}} {{target}} 으로 비밀번호가 전송되었어요.',
1616
passcode_sent: '비밀번호가 재전송되었어요.',
17-
resend_after_seconds: '<span>{{seconds}}</span> 초 후에 재전송',
18-
resend_passcode: '비밀번호 재전송',
17+
resend_after_seconds: '아직 못 받으셨나요? <span>{{seconds}}</span> 초 후에 다시 보내기',
18+
resend_passcode: '아직 못 받으셨나요? <a>인증 코드를 다시 보내기</a>',
1919
create_account_id_exists:
2020
'{{type}} {{value}} 계정은 다른 계정과 연결되어 있습니다. 다른 {{type}}을(를) 시도해주세요.',
2121
link_account_id_exists: '{{type}} {{value}}와/과 연동된 계정이 이미 존재해요. 연동할까요?',

packages/phrases-experience/src/locales/pl-pl/description.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const description = {
1414
and: 'i',
1515
enter_passcode: 'Kod weryfikacyjny został wysłany na twoje {{address}} {{target}}',
1616
passcode_sent: 'Kod weryfikacyjny został wysłany ponownie',
17-
resend_after_seconds: 'Wyślij ponownie po <span>{{seconds}}</span> sekundach',
18-
resend_passcode: 'Wyślij kod weryfikacyjny ponownie',
17+
resend_after_seconds:
18+
'Nie otrzymałeś jeszcze? Wyślij ponownie za <span>{{seconds}}</span> sekund',
19+
resend_passcode: 'Nie otrzymałeś jeszcze? <a>Wyślij ponownie kod weryfikacyjny</a>',
1920
create_account_id_exists: 'Konto z {{type}} {{value}} już istnieje. Czy chcesz się zalogować?',
2021
link_account_id_exists: 'Konto z {{type}} {{value}} już istnieje. Czy chcesz je połączyć?',
2122
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/pt-br/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'e',
1515
enter_passcode: 'O código de verificação foi enviado para o seu {{address}} {{target}}',
1616
passcode_sent: 'O código de verificação foi reenviado',
17-
resend_after_seconds: 'Reenviar depois <span>{{seconds}}</span> segundos',
18-
resend_passcode: 'Reenviar código de verificação',
17+
resend_after_seconds: 'Ainda não recebeu? Reenviar após <span>{{seconds}}</span> segundos',
18+
resend_passcode: 'Ainda não recebeu? <a>Reenviar código de verificação</a>',
1919
create_account_id_exists: 'A conta com {{type}} {{value}} já existe, gostaria de entrar?',
2020
link_account_id_exists: 'A conta com {{type}} {{value}} já existe, gostaria de vincular?',
2121
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/pt-pt/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'e',
1515
enter_passcode: 'O código de verificação foi enviado para o seu {{address}} {{target}}',
1616
passcode_sent: 'O código de verificação foi reenviado',
17-
resend_after_seconds: 'Reenviar após <span>{{seconds}}</span> segundos',
18-
resend_passcode: 'Reenviar código de verificação',
17+
resend_after_seconds: 'Ainda não recebeu? Reenviar após <span>{{seconds}}</span> segundos',
18+
resend_passcode: 'Ainda não recebeu? <a>Reenviar código de verificação</a>',
1919
create_account_id_exists: 'A conta com {{type}} {{value}} já existe, gostaria de fazer login?',
2020
link_account_id_exists: 'A conta com {{type}} {{value}} já existe, gostaria de vinculá-la?',
2121
sign_in_id_does_not_exist: 'A conta com {{type}} {{value}} não existe, gostaria de criar uma?',

packages/phrases-experience/src/locales/ru/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 'и',
1515
enter_passcode: 'Код подтверждения был отправлен на {{address}}',
1616
passcode_sent: 'Код подтверждения был отправлен повторно',
17-
resend_after_seconds: 'Отправить повторно через <span>{{seconds}}</span> сек.',
18-
resend_passcode: 'Отправить повторно',
17+
resend_after_seconds: 'Еще не получили? Отправить повторно через <span>{{seconds}}</span> секунд',
18+
resend_passcode: 'Еще не получили? <a>Отправить повторно код подтверждения</a>',
1919
create_account_id_exists: 'Учетная запись для {{value}} уже существует, хотите войти?',
2020
link_account_id_exists: 'Учетная запись для {{value}} уже существует, хотите привязать?',
2121
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/tr-tr/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: 've',
1515
enter_passcode: 'Doğrulama kodu {{address}} {{target}} adresinize gönderildi',
1616
passcode_sent: 'Doğrulama kodu yeniden gönderildi',
17-
resend_after_seconds: '<span>{{seconds}}</span> saniye sonra tekrar gönder',
18-
resend_passcode: 'Doğrulama kodunu tekrar gönder',
17+
resend_after_seconds: 'Henüz almadınız mı? <span>{{seconds}}</span> saniye sonra tekrar gönderin',
18+
resend_passcode: 'Henüz almadınız mı? <a>Doğrulama kodunu tekrar gönderin</a>',
1919
create_account_id_exists: '{{type}} {{value}} ile hesap mevcut, giriş yapmak ister misiniz?',
2020
link_account_id_exists: '{{type}} {{value}} olan hesap zaten var, bağlamak ister misiniz?',
2121
sign_in_id_does_not_exist:

packages/phrases-experience/src/locales/zh-cn/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: '和',
1515
enter_passcode: '验证码已经发送至你的{{ address }} {{target}}',
1616
passcode_sent: '验证码已经发送',
17-
resend_after_seconds: ' <span>{{ seconds }}</span> 秒后重发',
18-
resend_passcode: '重发验证码',
17+
resend_after_seconds: '还没收到? <span>{{seconds}}</span> 秒后重发',
18+
resend_passcode: '还没收到? <a>重发验证码</a>',
1919
create_account_id_exists: '{{type}}为 {{value}} 的帐号已存在,你要登录吗?',
2020
link_account_id_exists: ' {{type}}为 {{value}} 的账号已注册,你要绑定至这个账号吗?',
2121
sign_in_id_does_not_exist: '{{type}}为 {{value}} 的帐号不存在,你要创建一个新帐号吗?',

packages/phrases-experience/src/locales/zh-hk/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: '和',
1515
enter_passcode: '驗證碼已經發送至你的{{ address }} {{target}}',
1616
passcode_sent: '驗證碼已經發送',
17-
resend_after_seconds: ' <span>{{ seconds }}</span> 秒後重發',
18-
resend_passcode: '重發驗證碼',
17+
resend_after_seconds: '還沒收到? <span>{{seconds}}</span> 秒後重發',
18+
resend_passcode: '還沒收到? <a>重發驗證碼</a>',
1919
create_account_id_exists: '{{type}}為 {{value}} 的帳號已存在,你要登錄嗎?',
2020
link_account_id_exists: ' {{type}}為 {{value}} 的帳號已註冊,你要綁定至這個帳號嗎?',
2121
sign_in_id_does_not_exist: '{{type}}為 {{value}} 的帳號不存在,你要創建一個新帳號嗎?',

packages/phrases-experience/src/locales/zh-tw/description.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const description = {
1414
and: '和',
1515
enter_passcode: '驗證碼已經發送至你的{{address}} {{target}}',
1616
passcode_sent: '驗證碼已經發送',
17-
resend_after_seconds: ' <span>{{seconds}}</span> 秒後重新發送',
18-
resend_passcode: '重新發送驗證碼',
17+
resend_after_seconds: '還沒收到? <span>{{seconds}}</span> 秒後重發',
18+
resend_passcode: '還沒收到? <a>重發驗證碼</a>',
1919
create_account_id_exists: '{{type}} 為 {{value}} 的帳號已存在,你要登錄嗎?',
2020
link_account_id_exists: ' {{type}} 為 {{value}} 的帳號已註冊,你要綁定至這個帳號嗎?',
2121
sign_in_id_does_not_exist: '{{type}} 為 {{value}} 的帳號不存在,你要創建一個新帳號嗎?',

0 commit comments

Comments
 (0)