feat(invitation): add translations (#909)

This commit is contained in:
Gustavo J. Maciel 2023-08-10 03:55:40 -04:00 committed by GitHub
parent 672eec08bc
commit 1360ce801d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import axios, { AxiosResponse } from "axios";
import { UUID } from "crypto";
import { useParams, useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useSubscriptionApi } from "@/lib/api/subscription/useSubscriptionApi";
import { BrainRoleType } from "@/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types";
@ -13,8 +14,9 @@ import { useEventTracking } from "@/services/analytics/useEventTracking";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useInvitation = () => {
const { t } = useTranslation(["brain","invitation"]);
const params = useParams();
const brainId = params?.brainId as UUID | undefined;
const brainId = params.brainId as UUID | undefined;
const [isLoading, setIsLoading] = useState(false);
const [brainName, setBrainName] = useState<string>("");
const [role, setRole] = useState<BrainRoleType | undefined>();
@ -26,7 +28,7 @@ export const useInvitation = () => {
useSubscriptionApi();
if (brainId === undefined) {
throw new Error("Brain ID is undefined");
throw new Error(t("brainUndefined",{ns:"brain"}));
}
const { fetchAllBrains, setActiveBrain } = useBrainContext();
@ -44,12 +46,12 @@ export const useInvitation = () => {
if (axios.isAxiosError(error) && error.response?.status === 404) {
publish({
variant: "warning",
text: "This invitation is not valid.",
text: t("invitationNotFound",{ns:"invitation"}),
});
} else {
publish({
variant: "danger",
text: "An unknown error occurred while checking the invitaiton",
text: t("errorCheckingInvitation",{ns:"invitation"})
});
}
router.push("/");
@ -63,13 +65,13 @@ export const useInvitation = () => {
const handleAccept = async () => {
setIsProcessingRequest(true);
try {
const response = await acceptInvitation(brainId);
await acceptInvitation(brainId);
void track("INVITATION_ACCEPTED");
await fetchAllBrains();
publish({
variant: "success",
text: JSON.stringify(response.message),
text: t("accept",{ns:"invitation"}),
});
setActiveBrain({ id: brainId, name: brainName });
} catch (error) {
@ -86,7 +88,7 @@ export const useInvitation = () => {
console.error("Error calling the API:", error);
publish({
variant: "danger",
text: "An unknown error occurred while accepting the invitaiton",
text: t("errorAccepting",{ns:"invitation"})
});
}
} finally {
@ -98,10 +100,10 @@ export const useInvitation = () => {
const handleDecline = async () => {
setIsProcessingRequest(true);
try {
const response = await declineInvitation(brainId);
await declineInvitation(brainId);
publish({
variant: "success",
text: JSON.stringify(response.message),
text: t("declined",{ns:"invitation"})
});
void track("INVITATION_DECLINED");
} catch (error) {
@ -117,7 +119,7 @@ export const useInvitation = () => {
} else {
publish({
variant: "danger",
text: "An unknown error occurred while declining the invitation",
text: t("errorDeclining",{ns:"invitation"})
});
}
} finally {

View File

@ -1,5 +1,7 @@
"use client";
import { useTranslation } from "react-i18next";
import Button from "@/lib/components/ui/Button";
import PageHeading from "@/lib/components/ui/PageHeading";
import Spinner from "@/lib/components/ui/Spinner";
@ -9,6 +11,7 @@ import { redirectToLogin } from "@/lib/router/redirectToLogin";
import { useInvitation } from "./hooks/useInvitation";
const InvitationPage = (): JSX.Element => {
const { t } = useTranslation('invitation');
const {
handleAccept,
isProcessingRequest,
@ -37,13 +40,13 @@ const InvitationPage = (): JSX.Element => {
return (
<main className="pt-10">
<PageHeading
title={`Welcome to ${brainName}!`}
subtitle={`You have been invited to join this brain as a ${role} and start exploring. Do you accept this exciting journey?`}
title={t("wellcome",{brain: brainName, ns: "invitation"})}
subtitle={t("invitationMessage",{role: role, ns: "invitation"})}
/>
{isProcessingRequest ? (
<div className="flex flex-col items-center justify-center mt-5">
<Spinner />
<p className="text-center">Processing your request...</p>
<p className="text-center">{t("processingRequest",{ns: "invitation"})}</p>
</div>
) : (
<div className="flex flex-col items-center justify-center gap-5 mt-5">
@ -52,14 +55,14 @@ const InvitationPage = (): JSX.Element => {
variant={"secondary"}
className="py-3"
>
Yes, count me in!
{t("accept",{ns: "invitation"})}
</Button>
<Button
onClick={() => void handleDecline()}
variant={"danger"}
className="py-3"
>
No, thank you.
{t("reject",{ns: "invitation"})}
</Button>
</div>
)}

View File

@ -5,6 +5,7 @@ import chat_en from "../../../public/locales/en/chat.json";
import config_en from "../../../public/locales/en/config.json";
import delete_brain_en from "../../../public/locales/en/deleteBrain.json";
import explore_en from "../../../public/locales/en/explore.json";
import invitation_en from "../../../public/locales/en/invitation.json";
import login_en from "../../../public/locales/en/login.json";
import logout_en from "../../../public/locales/en/logout.json";
import signUp_en from "../../../public/locales/en/signUp.json";
@ -18,6 +19,7 @@ import chat_es from "../../../public/locales/es/chat.json";
import config_es from "../../../public/locales/es/config.json";
import delete_brain_es from "../../../public/locales/es/deleteBrain.json";
import explore_es from "../../../public/locales/es/explore.json";
import invitation_es from "../../../public/locales/es/invitation.json";
import login_es from "../../../public/locales/es/login.json";
import logout_es from "../../../public/locales/es/logout.json";
import signUp_es from "../../../public/locales/es/signUp.json";
@ -31,6 +33,7 @@ import chat_fr from "../../../public/locales/fr/chat.json";
import config_fr from "../../../public/locales/fr/config.json";
import delete_brain_fr from "../../../public/locales/fr/deleteBrain.json";
import explore_fr from "../../../public/locales/fr/explore.json";
import invitation_fr from "../../../public/locales/fr/invitation.json";
import login_fr from "../../../public/locales/fr/login.json";
import logout_fr from "../../../public/locales/fr/logout.json";
import signUp_fr from "../../../public/locales/fr/signUp.json";
@ -44,6 +47,7 @@ import chat_ru from "../../../public/locales/ru/chat.json";
import config_ru from "../../../public/locales/ru/config.json";
import delete_brain_ru from "../../../public/locales/ru/deleteBrain.json";
import explore_ru from "../../../public/locales/ru/explore.json";
import invitation_ru from "../../../public/locales/ru/invitation.json";
import login_ru from "../../../public/locales/ru/login.json";
import logout_ru from "../../../public/locales/ru/logout.json";
import signUp_ru from "../../../public/locales/ru/signUp.json";
@ -59,6 +63,7 @@ export const resources = {
chat: chat_en,
config: config_en,
explore: explore_en,
invitation: invitation_en,
login: login_en,
logout: logout_en,
signUp: signUp_en,
@ -73,6 +78,7 @@ export const resources = {
chat: chat_es,
config: config_es,
explore: explore_es,
invitation: invitation_es,
login: login_es,
logout: logout_es,
signUp: signUp_es,
@ -87,6 +93,7 @@ export const resources = {
chat: chat_fr,
config: config_fr,
explore: explore_fr,
invitation: invitation_fr,
login: login_fr,
logout: logout_fr,
signUp: signUp_fr,
@ -101,6 +108,7 @@ export const resources = {
chat: chat_ru,
config: config_ru,
explore: explore_ru,
invitation: invitation_ru,
login: login_ru,
logout: logout_ru,
signUp: signUp_ru,

View File

@ -0,0 +1,13 @@
{
"wellcome": "Welcome to {{brain}}!",
"invitationMessage": "You have been invited to join this brain as a {{role}} and start exploring. Do you accept this exciting journey?",
"processingRequest": "Processing your request...",
"accept": "Yes, count me in!",
"reject": "No, thank you.",
"invitationNotFound": "This invitation is not valid.",
"errorCheckingInvitation": "An unknown error occurred while checking the invitation",
"accepted": "Invitation accepted",
"errorAccepting": "An unknown error occurred while accepting the invitation",
"declined": "Invitation declined",
"errorDeclining": "An unknown error occurred while declining the invitation"
}

View File

@ -0,0 +1,13 @@
{
"wellcome": "Bienvenido/a a {{brain}}!",
"invitationMessage": "Te han invitado a unirte a este cerebro como un {{role}} y empezar a explorar. ¿Aceptas este entusiasmante viaje?",
"processingRequest": "Procesando tu pedido...",
"accept": "¡Sí, cuenta conmigo!",
"reject": "No, gracias",
"invitationNotFound": "Esta invitación no es válida",
"errorCheckingInvitation": "Ocurrió un error durante la comprobación de la invitación",
"accepted": "Invitación aceptada",
"errorAccepting": "Ocurrió un error aceptando la invitación",
"declined": "Invitación rechazada",
"errorDeclining": "Ocurrió un error rechazando la invitación"
}

View File

@ -0,0 +1,13 @@
{
"wellcome": "Bienvenue sur {{brain}} !",
"invitationMessage": "Vous avez été invité(e) à rejoindre ce cerveau en tant que {{role}} et à commencer à explorer. Acceptez-vous ce voyage passionnant ?",
"processingRequest": "Traitement de votre demande en cours...",
"accept": "Oui, je suis partant(e) !",
"reject": "Non, merci",
"invitationNotFound": "Cette invitation n'est pas valide",
"errorCheckingInvitation": "Une erreur s'est produite lors de la vérification de l'invitation",
"accepted": "Invitation acceptée",
"errorAccepting": "Une erreur s'est produite lors de l'acceptation de l'invitation",
"declined": "Invitation refusée",
"errorDeclining": "Une erreur s'est produite lors du refus de l'invitation"
}

View File

@ -0,0 +1,13 @@
{
"wellcome": "Добро пожаловать в {{brain}}!",
"invitationMessage": "Bac пригласили присоединиться к этому мозгу как {{role}} и начать исследование. Принимаете ли вы это захватывающее путешествие?",
"processingRequest": "Обработка вашего запроса...",
"accept": "Да, я согласен/согласна!",
"reject": "Нет, спасибо",
"invitationNotFound": "Это приглашение недействительно",
"errorCheckingInvitation": "Произошла ошибка при проверке приглашения",
"accepted": "Приглашение принято",
"errorAccepting": "Произошла ошибка при принятии приглашения",
"declined": "Приглашение отклонено",
"errorDeclining": "Произошла ошибка при отклонении приглашения"
}