From 4f6c3c29bde0378ccd6545a756a3b1cd258437c4 Mon Sep 17 00:00:00 2001 From: "Gloire Mutaliko (Salva)" <86450367+GloireMutaliko21@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:44:19 +0200 Subject: [PATCH] Fix/login with one team workspace (#2685) * feat: skip select team/workspace for member with only one (magic link) * feat: skip team and workspace selection for user with only one * feat: auto redirect user with one team signin with password * fix: broken style for workspace screen --- .../app/[locale]/auth/passcode/component.tsx | 55 ++++++++++++++----- .../app/[locale]/auth/password/component.tsx | 45 ++++++++++----- apps/web/locales/ar.json | 1 + apps/web/locales/bg.json | 1 + apps/web/locales/de.json | 1 + apps/web/locales/en.json | 1 + apps/web/locales/es.json | 1 + apps/web/locales/fr.json | 1 + apps/web/locales/he.json | 1 + apps/web/locales/it.json | 1 + apps/web/locales/nl.json | 1 + apps/web/locales/pl.json | 1 + apps/web/locales/pt.json | 1 + apps/web/locales/ru.json | 1 + apps/web/locales/zh.json | 1 + 15 files changed, 83 insertions(+), 30 deletions(-) diff --git a/apps/web/app/[locale]/auth/passcode/component.tsx b/apps/web/app/[locale]/auth/passcode/component.tsx index 5cc5cb0ad..b133743f2 100644 --- a/apps/web/app/[locale]/auth/passcode/component.tsx +++ b/apps/web/app/[locale]/auth/passcode/component.tsx @@ -4,7 +4,17 @@ import { getAccessTokenCookie, getActiveUserIdCookie } from '@app/helpers'; import { TAuthenticationPasscode, useAuthenticationPasscode } from '@app/hooks'; import { IClassName, ISigninEmailConfirmWorkspaces } from '@app/interfaces'; import { clsxm } from '@app/utils'; -import { AuthCodeInputField, Avatar, BackButton, Button, Card, InputField, SpinnerLoader, Text } from 'lib/components'; +import { + AuthCodeInputField, + Avatar, + BackButton, + BackdropLoader, + Button, + Card, + InputField, + SpinnerLoader, + Text +} from 'lib/components'; import { CircleIcon, CheckCircleOutlineIcon } from 'assets/svg'; import { AuthLayout } from 'lib/layout'; import { useTranslations } from 'next-intl'; @@ -298,6 +308,7 @@ function PasscodeScreen({ form, className }: { form: TAuthenticationPasscode } & } function WorkSpaceScreen({ form, className }: { form: TAuthenticationPasscode } & IClassName) { + const t = useTranslations(); const [selectedWorkspace, setSelectedWorkspace] = useState(0); const [selectedTeam, setSelectedTeam] = useState(''); const router = useRouter(); @@ -339,21 +350,35 @@ function WorkSpaceScreen({ form, className }: { form: TAuthenticationPasscode } } }, [form.authScreen, router]); + const hasMultipleTeams = form.workspaces.some((workspace) => workspace.current_teams.length > 1); + return ( - { - form.authScreen.setScreen('email'); - form.setErrors({}); - }} - selectedWorkspace={selectedWorkspace} - setSelectedWorkspace={setSelectedWorkspace} - setSelectedTeam={setSelectedTeam} - selectedTeam={selectedTeam} - signInWorkspaceLoading={form.signInWorkspaceLoading} - /> + <> + {/* The workspace component will be visible only if there are two or many workspaces and/or teams */} +
+ { + form.authScreen.setScreen('email'); + form.setErrors({}); + }} + selectedWorkspace={selectedWorkspace} + setSelectedWorkspace={setSelectedWorkspace} + setSelectedTeam={setSelectedTeam} + selectedTeam={selectedTeam} + signInWorkspaceLoading={form.signInWorkspaceLoading} + /> +
+ + {/* If the user is a member of only one workspace and only one team, render a redirecting component */} + {form.workspaces.length === 1 && !hasMultipleTeams && ( +
+ +
+ )} + ); } diff --git a/apps/web/app/[locale]/auth/password/component.tsx b/apps/web/app/[locale]/auth/password/component.tsx index 2876dd839..08dcba15c 100644 --- a/apps/web/app/[locale]/auth/password/component.tsx +++ b/apps/web/app/[locale]/auth/password/component.tsx @@ -4,7 +4,7 @@ import { getAccessTokenCookie } from '@app/helpers'; import { TAuthenticationPassword, useAuthenticationPassword } from '@app/hooks'; import { IClassName } from '@app/interfaces'; import { clsxm } from '@app/utils'; -import { Button, Card, InputField, Text } from 'lib/components'; +import { BackdropLoader, Button, Card, InputField, Text } from 'lib/components'; import { AuthLayout } from 'lib/layout'; import { useTranslations } from 'next-intl'; import Link from 'next/link'; @@ -99,6 +99,7 @@ function LoginForm({ form }: { form: TAuthenticationPassword }) { } function WorkSpaceScreen({ form, className }: { form: TAuthenticationPassword } & IClassName) { + const t = useTranslations(); const [selectedWorkspace, setSelectedWorkspace] = useState(0); const [selectedTeam, setSelectedTeam] = useState(''); const router = useRouter(); @@ -140,20 +141,34 @@ function WorkSpaceScreen({ form, className }: { form: TAuthenticationPassword } } }, [form.authScreen, router]); + const hasMultipleTeams = form.workspaces.some((workspace) => workspace.current_teams.length > 1); + return ( - { - form.authScreen.setScreen('login'); - form.setErrors({}); - }} - selectedWorkspace={selectedWorkspace} - setSelectedWorkspace={setSelectedWorkspace} - setSelectedTeam={setSelectedTeam} - selectedTeam={selectedTeam} - signInWorkspaceLoading={form.signInWorkspaceLoading} - /> + <> + {/* The workspace component will be visible only if there are two or many workspaces and/or teams */} +
+ { + form.authScreen.setScreen('login'); + form.setErrors({}); + }} + selectedWorkspace={selectedWorkspace} + setSelectedWorkspace={setSelectedWorkspace} + setSelectedTeam={setSelectedTeam} + selectedTeam={selectedTeam} + signInWorkspaceLoading={form.signInWorkspaceLoading} + /> +
+ + {/* If the user is a member of only one workspace and only one team, render a redirecting component */} + {form.workspaces.length === 1 && !hasMultipleTeams && ( +
+ +
+ )} + ); } diff --git a/apps/web/locales/ar.json b/apps/web/locales/ar.json index 71495801e..031e4d8ba 100644 --- a/apps/web/locales/ar.json +++ b/apps/web/locales/ar.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "إنشاء فريق جديد", "HEADING_DESCRIPTION": "يرجى إدخال تفاصيل فريقك لإنشاء فريق جديد.", "LOADING_TEXT": "نحن الآن ننشئ مساحة عملك الجديدة، انتظر...", + "REDIRECT_TO_WORSPACE_LOADING": "إعادة التوجيه إلى مساحة العمل الخاصة بك", "VERIFY_EMAIL_LOADING_TEXT": "نحن نحقق من بريدك الإلكتروني، انتظر...", "INPUT_TEAM_NAME": "أدخل اسم فريقك", "JOIN_EXISTING_TEAM": "الانضمام إلى فريق موجود؟", diff --git a/apps/web/locales/bg.json b/apps/web/locales/bg.json index 05e3a4394..a9eb65082 100644 --- a/apps/web/locales/bg.json +++ b/apps/web/locales/bg.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Създаване на нов отбор", "HEADING_DESCRIPTION": "Моля, въведете данните на вашия отбор, за да създадете нов отбор.", "LOADING_TEXT": "В момента създаваме новото ви работно място, изчакайте...", + "REDIRECT_TO_WORSPACE_LOADING": "Пренасочване към вашето работно пространство...", "VERIFY_EMAIL_LOADING_TEXT": "Проверяваме имейла ви, изчакайте...", "INPUT_TEAM_NAME": "Въведете име на отбора", "JOIN_EXISTING_TEAM": "Присъединявате се към съществуващ отбор?", diff --git a/apps/web/locales/de.json b/apps/web/locales/de.json index 6c412848d..3920c8d1b 100644 --- a/apps/web/locales/de.json +++ b/apps/web/locales/de.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Neues Team erstellen", "HEADING_DESCRIPTION": "Bitte geben Sie die Details für Ihr neues Team ein, um ein neues Team zu erstellen.", "LOADING_TEXT": "Wir erstellen gerade Ihren neuen Arbeitsbereich, bitte warten...", + "REDIRECT_TO_WORSPACE_LOADING": "Weiterleitung zu Ihrem Arbeitsbereich...", "VERIFY_EMAIL_LOADING_TEXT": "Wir verifizieren gerade Ihre E-Mail, bitte warten...", "INPUT_TEAM_NAME": "Teamnamen eingeben", "JOIN_EXISTING_TEAM": "Einem bestehenden Team beitreten?", diff --git a/apps/web/locales/en.json b/apps/web/locales/en.json index 23c2cb9c4..955d35e9d 100644 --- a/apps/web/locales/en.json +++ b/apps/web/locales/en.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Create New Team", "HEADING_DESCRIPTION": "Please enter your team details to create a new team.", "LOADING_TEXT": "We are now creating your new workplace, hold on...", + "REDIRECT_TO_WORSPACE_LOADING": "Redirecting to your workspace...", "VERIFY_EMAIL_LOADING_TEXT": "We are verifying your email, hold on...", "INPUT_TEAM_NAME": "Input your team name", "JOIN_EXISTING_TEAM": "Joining existing team?", diff --git a/apps/web/locales/es.json b/apps/web/locales/es.json index 48245f713..a11845ac9 100644 --- a/apps/web/locales/es.json +++ b/apps/web/locales/es.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Crear nuevo equipo", "HEADING_DESCRIPTION": "Por favor ingrese los detalles de su equipo para crear un nuevo equipo.", "LOADING_TEXT": "Ahora estamos creando su nuevo lugar de trabajo, espere...", + "REDIRECT_TO_WORSPACE_LOADING": "Redirigiendo a tu espacio de trabajo...", "VERIFY_EMAIL_LOADING_TEXT": "Estamos verificando su correo electrónico, espere...", "INPUT_TEAM_NAME": "Ingrese el nombre de su equipo", "JOIN_EXISTING_TEAM": "¿Unirse a un equipo existente?", diff --git a/apps/web/locales/fr.json b/apps/web/locales/fr.json index 58ac24882..575f3ab38 100644 --- a/apps/web/locales/fr.json +++ b/apps/web/locales/fr.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Créer une nouvelle équipe", "HEADING_DESCRIPTION": "Veuillez entrer les détails de votre équipe pour créer une nouvelle équipe.", "LOADING_TEXT": "Nous créons maintenant votre nouvel espace de travail, patientez...", + "REDIRECT_TO_WORSPACE_LOADING": "Redirection vers votre espace de travail...", "VERIFY_EMAIL_LOADING_TEXT": "Nous vérifions votre e-mail, patientez...", "INPUT_TEAM_NAME": "Saisissez le nom de votre équipe", "JOIN_EXISTING_TEAM": "Rejoindre une équipe existante ?", diff --git a/apps/web/locales/he.json b/apps/web/locales/he.json index de09d3472..482415d4e 100644 --- a/apps/web/locales/he.json +++ b/apps/web/locales/he.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "צור צוות חדש", "HEADING_DESCRIPTION": "אנא הכנס את פרטי הצוות שלך כדי ליצור צוות חדש.", "LOADING_TEXT": "אנחנו עכשיו יוצרים את סביבת העבודה החדשה שלך, רגע קטן...", + "REDIRECT_TO_WORSPACE_LOADING": "מכוון מחדש לחלל העבודה שלך", "VERIFY_EMAIL_LOADING_TEXT": "אנחנו מאמתים את האימייל שלך, רגע קטן...", "INPUT_TEAM_NAME": "הכנס את שם הצוות שלך", "JOIN_EXISTING_TEAM": "מצטרף לצוות קיים?", diff --git a/apps/web/locales/it.json b/apps/web/locales/it.json index 59a30ce9f..6a74c2a4e 100644 --- a/apps/web/locales/it.json +++ b/apps/web/locales/it.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Crea un Nuovo Team", "HEADING_DESCRIPTION": "Inserisci i dettagli del tuo team per crearne uno nuovo.", "LOADING_TEXT": "Stiamo creando il tuo nuovo spazio di lavoro, attendi...", + "REDIRECT_TO_WORSPACE_LOADING": "Reindirizzamento al tuo spazio di lavoro...", "VERIFY_EMAIL_LOADING_TEXT": "Stiamo verificando la tua email, attendi...", "INPUT_TEAM_NAME": "Inserisci il nome del tuo team", "JOIN_EXISTING_TEAM": "Unisciti a un team esistente?", diff --git a/apps/web/locales/nl.json b/apps/web/locales/nl.json index 3748ca039..379580428 100644 --- a/apps/web/locales/nl.json +++ b/apps/web/locales/nl.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Nieuw team maken", "HEADING_DESCRIPTION": "Voer uw teamgegevens in om een nieuw team te maken.", "LOADING_TEXT": "We maken nu uw nieuwe werkplek aan, even geduld...", + "REDIRECT_TO_WORSPACE_LOADING": "Doorverwijzen naar uw werkruimte...", "VERIFY_EMAIL_LOADING_TEXT": "We controleren uw e-mailadres, even geduld...", "INPUT_TEAM_NAME": "Voer uw teamnaam in", "JOIN_EXISTING_TEAM": "Bestaand team joinen?", diff --git a/apps/web/locales/pl.json b/apps/web/locales/pl.json index e6baa5879..2c338afe1 100644 --- a/apps/web/locales/pl.json +++ b/apps/web/locales/pl.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Stwórz Nowy Zespół", "HEADING_DESCRIPTION": "Proszę podać szczegóły swojego zespołu, aby stworzyć nowy zespół.", "LOADING_TEXT": "Teraz tworzymy twoje nowe miejsce pracy, proszę czekać...", + "REDIRECT_TO_WORSPACE_LOADING": "Przekierowywanie do Twojej przestrzeni roboczej...", "VERIFY_EMAIL_LOADING_TEXT": "Weryfikujemy twój e-mail, proszę czekać...", "INPUT_TEAM_NAME": "Wprowadź nazwę swojego zespołu", "JOIN_EXISTING_TEAM": "Dołączasz do istniejącego zespołu?", diff --git a/apps/web/locales/pt.json b/apps/web/locales/pt.json index da21ac9f7..fbf63bcfd 100644 --- a/apps/web/locales/pt.json +++ b/apps/web/locales/pt.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Criar Nova Equipe", "HEADING_DESCRIPTION": "Por favor, insira os detalhes da sua equipe para criar uma nova equipe.", "LOADING_TEXT": "Estamos criando o seu novo ambiente de trabalho, aguarde...", + "REDIRECT_TO_WORSPACE_LOADING": "Redirecionando para o seu espaço de trabalho...", "VERIFY_EMAIL_LOADING_TEXT": "Estamos verificando o seu e-mail, aguarde...", "INPUT_TEAM_NAME": "Insira o nome da sua equipe", "JOIN_EXISTING_TEAM": "Já faz parte de uma equipe?", diff --git a/apps/web/locales/ru.json b/apps/web/locales/ru.json index 73ab9203b..060ea4d32 100644 --- a/apps/web/locales/ru.json +++ b/apps/web/locales/ru.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "Создать новую команду", "HEADING_DESCRIPTION": "Введите данные вашей команды, чтобы создать новую команду.", "LOADING_TEXT": "Мы сейчас создаем ваше новое рабочее место, подождите...", + "REDIRECT_TO_WORSPACE_LOADING": "Перенаправление на ваше рабочее пространство...", "VERIFY_EMAIL_LOADING_TEXT": "Мы проверяем вашу электронную почту, подождите...", "INPUT_TEAM_NAME": "Введите название вашей команды", "JOIN_EXISTING_TEAM": "Присоединиться к существующей команде?", diff --git a/apps/web/locales/zh.json b/apps/web/locales/zh.json index 5102546f0..d9d68c603 100644 --- a/apps/web/locales/zh.json +++ b/apps/web/locales/zh.json @@ -312,6 +312,7 @@ "HEADING_TITLE": "创建新团队", "HEADING_DESCRIPTION": "请输入团队信息以创建新团队。", "LOADING_TEXT": "正在为您创建新的工作区,请稍候......", + "REDIRECT_TO_WORSPACE_LOADING": "正在重定向到您的工作空间......", "VERIFY_EMAIL_LOADING_TEXT": "正在验证您的电子邮箱,请稍候......", "INPUT_TEAM_NAME": "输入您的团队名称", "JOIN_EXISTING_TEAM": "加入已有团队?",