Skip to content

Commit

Permalink
feat: update translations
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko committed Oct 26, 2023
1 parent 13c7d1e commit 106cc2f
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";

import { useMagicLinkLogin } from "../useMagicLinkLogin";

Expand All @@ -12,32 +12,40 @@ const mockUseSupabase = () => ({
},
},
});
const email = "user@quivr.app";
const watchMock = vi.fn(() => email);
vi.mock("react-hook-form", async () => {
const actual = await vi.importActual<typeof import("react-hook-form")>(
"react-hook-form"
);

return {
...actual,
useForm: () => ({
...actual.useForm(),
watch: watchMock,
}),
};
});

vi.mock("@/lib/context/SupabaseProvider", () => ({
useSupabase: () => mockUseSupabase(),
}));
const setEmail = vi.fn();

describe("useMagicLinkLogin", () => {
afterEach(() => {
vi.restoreAllMocks();
});

it("should not call signInWithOtp if email is empty", async () => {
const { result } = renderHook(() =>
useMagicLinkLogin({
email: "",
setEmail,
})
);
watchMock.mockReturnValueOnce("");
const { result } = renderHook(() => useMagicLinkLogin());
await act(() => result.current.handleMagicLinkLogin());
expect(mockSignInWithOtp).toHaveBeenCalledTimes(0);
});

it("should call signInWithOtp with proper arguments", async () => {
const email = "user@quivr.app";
const { result } = renderHook(() =>
useMagicLinkLogin({
email,
setEmail,
})
);
const { result } = renderHook(() => useMagicLinkLogin());
await result.current.handleMagicLinkLogin();
expect(mockSignInWithOtp).toHaveBeenCalledTimes(1);
expect(mockSignInWithOtp).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const useMagicLinkLogin = () => {
variant: "danger",
text: t("errorMailMissed"),
});

return;
}

const { error } = await supabase.auth.signInWithOtp({
Expand All @@ -50,11 +52,6 @@ export const useMagicLinkLogin = () => {
throw error; // this error is caught by react-hook-form
}

publish({
variant: "success",
text: "Magic link sent successfully if email recognized",
});

setValue("email", "");
});

Expand Down
21 changes: 16 additions & 5 deletions frontend/app/(auth)/login/components/MagicLinkLogin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ export const MagicLinkLogin = (): JSX.Element => {

if (isSubmitSuccessful) {
return (
<>
<p>{t("check_your_email", { ns: "login" })} </p>
<div className="text-center flex flex-col gap-4">
<p>
{t("cant_find", { ns: "login" })}{" "}
<Button onClick={() => void reset()}>{t("try_again")}</Button>
{t("check_your_email.part1", { ns: "login" })}{" "}
<span className="font-semibold">
{t("check_your_email.magic_link", { ns: "login" })}
</span>{" "}
{t("check_your_email.part2", { ns: "login" })}
</p>
</>
<div>
<span>{t("cant_find", { ns: "login" })}</span>{" "}
<span
className="cursor-pointer underline"
onClick={() => void reset()}
>
{t("try_again")}
</span>
</div>
</div>
);
}

Expand Down
6 changes: 5 additions & 1 deletion frontend/public/locales/en/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"email":"Email address",
"cant_find":"Can't find it ?",
"try_again":"Try again",
"check_your_email":"We just sent you a Magic link, check your emails and follow the steps."
"check_your_email":{
"part1":"We just sent you a ",
"magic_link":"Magic link",
"part2":", check your emails and follow the steps."
}
}
19 changes: 13 additions & 6 deletions frontend/public/locales/es/login.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"googleLogin": "Continuar con Google",
"magicLink": "Continuar con correo electrónico",
"errorMailMissed": "Por favor, ingrese su dirección de correo electrónico",
"talk_to": "Hablar con",
"restriction_message": "Los usuarios no pagos tienen acceso a una demostración gratuita y limitada de Quivr",
"email":"Dirección de correo electrónico"
"googleLogin": "Continuar con Google",
"magicLink": "Continuar con correo electrónico",
"errorMailMissed": "Por favor, ingrese su dirección de correo electrónico",
"talk_to": "Hablar con",
"restriction_message": "Los usuarios no pagos tienen acceso a una demostración gratuita y limitada de Quivr",
"email":"Dirección de correo electrónico",
"cant_find":"¿No lo encuentras?",
"try_again":"Inténtalo de nuevo",
"check_your_email": {
"part1":"Acabamos de enviarte un ",
"magic_link":"enlace mágico",
"part2":". Revisa tus correos electrónicos y sigue los pasos."
}
}
19 changes: 13 additions & 6 deletions frontend/public/locales/fr/login.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"googleLogin": "Continuer avec Google",
"magicLink": "Continuer avec e-mail",
"errorMailMissed": "Veuillez saisir votre adresse e-mail",
"talk_to": "Parler à",
"restriction_message": "Les utilisateurs non payants ont accès à une démonstration gratuite et limitée de Quivr",
"email":"Adresse e-mail"
"googleLogin": "Continuer avec Google",
"magicLink": "Continuer avec e-mail",
"errorMailMissed": "Veuillez saisir votre adresse e-mail",
"talk_to": "Parler à",
"restriction_message": "Les utilisateurs non payants ont accès à une démonstration gratuite et limitée de Quivr",
"email":"Adresse e-mail",
"cant_find":"Vous ne le trouvez pas ?",
"try_again":"Réessayez",
"check_your_email": {
"part1":"Nous venons de vous envoyer un ",
"magic_link":"lien magique",
"part2":". Vérifiez vos e-mails et suivez les étapes."
}
}
19 changes: 13 additions & 6 deletions frontend/public/locales/pt-br/login.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"googleLogin": "Continuar com o Google",
"magicLink": "Continuar com o e-mail",
"errorMailMissed": "Por favor, insira seu endereço de e-mail",
"talk_to": "Converse com",
"restriction_message": "Usuários não pagos têm acesso a uma demonstração gratuita e limitada do Quivr",
"email":"Email address"
"googleLogin": "Continuar com o Google",
"magicLink": "Continuar com o e-mail",
"errorMailMissed": "Por favor, insira seu endereço de e-mail",
"talk_to": "Converse com",
"restriction_message": "Usuários não pagos têm acesso a uma demonstração gratuita e limitada do Quivr",
"email":"Email address",
"cant_find":"Não consegue encontrar?",
"try_again":"Tente novamente",
"check_your_email":{
"part1":"Acabamos de enviar um ",
"magic_link":"link mágico",
"part2":" para você, verifique seus emails e siga as instruções."
}
}
19 changes: 13 additions & 6 deletions frontend/public/locales/ru/login.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"googleLogin": "Продолжить с Google",
"magicLink": "Продолжить с электронной почтой",
"errorMailMissed": "Пожалуйста, введите ваш адрес электронной почты",
"talk_to": "Общение с",
"restriction_message": "Неоплаченным пользователям доступен бесплатный и ограниченный демонстрационный доступ к Quivr",
"email":"Адрес электронной почты"
"googleLogin": "Продолжить с Google",
"magicLink": "Продолжить с электронной почтой",
"errorMailMissed": "Пожалуйста, введите ваш адрес электронной почты",
"talk_to": "Общение с",
"restriction_message": "Неоплаченным пользователям доступен бесплатный и ограниченный демонстрационный доступ к Quivr",
"email":"Адрес электронной почты",
"cant_find":"Не можете найти?",
"try_again":"Попробуйте еще раз",
"check_your_email": {
"part1":"Мы только что отправили вам ",
"magic_link":"волшебную ссылку",
"part2":". Проверьте свою электронную почту и следуйте инструкциям."
}
}
19 changes: 13 additions & 6 deletions frontend/public/locales/zh-cn/login.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"googleLogin": "使用Google继续",
"magicLink": "使用电子邮件继续",
"errorMailMissed": "请输入您的电子邮件地址",
"talk_to": "与之交谈",
"restriction_message": "未付费用户可以访问 Quivr 的免费和有限演示",
"email":"电子邮件地址"
"googleLogin": "使用Google继续",
"magicLink": "使用电子邮件继续",
"errorMailMissed": "请输入您的电子邮件地址",
"talk_to": "与之交谈",
"restriction_message": "未付费用户可以访问 Quivr 的免费和有限演示",
"email":"电子邮件地址",
"cant_find":"找不到吗?",
"try_again":"再试一次",
"check_your_email": {
"part1":"我们刚刚发送了一个",
"magic_link":"魔法链接",
"part2":",请查看您的电子邮件并按照步骤进行操作。"
}
}

0 comments on commit 106cc2f

Please sign in to comment.