Skip to content

Commit

Permalink
Fix/login with one team workspace (#2685)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GloireMutaliko21 authored Jul 5, 2024
1 parent 1ee0d25 commit 4f6c3c2
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 30 deletions.
55 changes: 40 additions & 15 deletions apps/web/app/[locale]/auth/passcode/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -298,6 +308,7 @@ function PasscodeScreen({ form, className }: { form: TAuthenticationPasscode } &
}

function WorkSpaceScreen({ form, className }: { form: TAuthenticationPasscode } & IClassName) {
const t = useTranslations();
const [selectedWorkspace, setSelectedWorkspace] = useState<number>(0);
const [selectedTeam, setSelectedTeam] = useState('');
const router = useRouter();
Expand Down Expand Up @@ -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 (
<WorkSpaceComponent
className={className}
workspaces={form.workspaces}
onSubmit={signInToWorkspace}
onBackButtonClick={() => {
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 */}
<div className={clsxm(`${form.workspaces.length === 1 && !hasMultipleTeams ? 'hidden' : ''}`, 'w-full')}>
<WorkSpaceComponent
className={className}
workspaces={form.workspaces}
onSubmit={signInToWorkspace}
onBackButtonClick={() => {
form.authScreen.setScreen('email');
form.setErrors({});
}}
selectedWorkspace={selectedWorkspace}
setSelectedWorkspace={setSelectedWorkspace}
setSelectedTeam={setSelectedTeam}
selectedTeam={selectedTeam}
signInWorkspaceLoading={form.signInWorkspaceLoading}
/>
</div>

{/* If the user is a member of only one workspace and only one team, render a redirecting component */}
{form.workspaces.length === 1 && !hasMultipleTeams && (
<div>
<BackdropLoader show={true} title={t('pages.authTeam.REDIRECT_TO_WORSPACE_LOADING')} />
</div>
)}
</>
);
}

Expand Down
45 changes: 30 additions & 15 deletions apps/web/app/[locale]/auth/password/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -99,6 +99,7 @@ function LoginForm({ form }: { form: TAuthenticationPassword }) {
}

function WorkSpaceScreen({ form, className }: { form: TAuthenticationPassword } & IClassName) {
const t = useTranslations();
const [selectedWorkspace, setSelectedWorkspace] = useState<number>(0);
const [selectedTeam, setSelectedTeam] = useState('');
const router = useRouter();
Expand Down Expand Up @@ -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 (
<WorkSpaceComponent
className={className}
workspaces={form.workspaces}
onSubmit={signInToWorkspace}
onBackButtonClick={() => {
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 */}
<div className={clsxm(`${form.workspaces.length === 1 && !hasMultipleTeams ? 'hidden' : ''}`, 'w-full')}>
<WorkSpaceComponent
className={className}
workspaces={form.workspaces}
onSubmit={signInToWorkspace}
onBackButtonClick={() => {
form.authScreen.setScreen('login');
form.setErrors({});
}}
selectedWorkspace={selectedWorkspace}
setSelectedWorkspace={setSelectedWorkspace}
setSelectedTeam={setSelectedTeam}
selectedTeam={selectedTeam}
signInWorkspaceLoading={form.signInWorkspaceLoading}
/>
</div>

{/* If the user is a member of only one workspace and only one team, render a redirecting component */}
{form.workspaces.length === 1 && !hasMultipleTeams && (
<div>
<BackdropLoader show={true} title={t('pages.authTeam.REDIRECT_TO_WORSPACE_LOADING')} />
</div>
)}
</>
);
}
1 change: 1 addition & 0 deletions apps/web/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"HEADING_TITLE": "إنشاء فريق جديد",
"HEADING_DESCRIPTION": "يرجى إدخال تفاصيل فريقك لإنشاء فريق جديد.",
"LOADING_TEXT": "نحن الآن ننشئ مساحة عملك الجديدة، انتظر...",
"REDIRECT_TO_WORSPACE_LOADING": "إعادة التوجيه إلى مساحة العمل الخاصة بك",
"VERIFY_EMAIL_LOADING_TEXT": "نحن نحقق من بريدك الإلكتروني، انتظر...",
"INPUT_TEAM_NAME": "أدخل اسم فريقك",
"JOIN_EXISTING_TEAM": "الانضمام إلى فريق موجود؟",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"HEADING_TITLE": "Създаване на нов отбор",
"HEADING_DESCRIPTION": "Моля, въведете данните на вашия отбор, за да създадете нов отбор.",
"LOADING_TEXT": "В момента създаваме новото ви работно място, изчакайте...",
"REDIRECT_TO_WORSPACE_LOADING": "Пренасочване към вашето работно пространство...",
"VERIFY_EMAIL_LOADING_TEXT": "Проверяваме имейла ви, изчакайте...",
"INPUT_TEAM_NAME": "Въведете име на отбора",
"JOIN_EXISTING_TEAM": "Присъединявате се към съществуващ отбор?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"HEADING_TITLE": "צור צוות חדש",
"HEADING_DESCRIPTION": "אנא הכנס את פרטי הצוות שלך כדי ליצור צוות חדש.",
"LOADING_TEXT": "אנחנו עכשיו יוצרים את סביבת העבודה החדשה שלך, רגע קטן...",
"REDIRECT_TO_WORSPACE_LOADING": "מכוון מחדש לחלל העבודה שלך",
"VERIFY_EMAIL_LOADING_TEXT": "אנחנו מאמתים את האימייל שלך, רגע קטן...",
"INPUT_TEAM_NAME": "הכנס את שם הצוות שלך",
"JOIN_EXISTING_TEAM": "מצטרף לצוות קיים?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"HEADING_TITLE": "Создать новую команду",
"HEADING_DESCRIPTION": "Введите данные вашей команды, чтобы создать новую команду.",
"LOADING_TEXT": "Мы сейчас создаем ваше новое рабочее место, подождите...",
"REDIRECT_TO_WORSPACE_LOADING": "Перенаправление на ваше рабочее пространство...",
"VERIFY_EMAIL_LOADING_TEXT": "Мы проверяем вашу электронную почту, подождите...",
"INPUT_TEAM_NAME": "Введите название вашей команды",
"JOIN_EXISTING_TEAM": "Присоединиться к существующей команде?",
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"HEADING_TITLE": "创建新团队",
"HEADING_DESCRIPTION": "请输入团队信息以创建新团队。",
"LOADING_TEXT": "正在为您创建新的工作区,请稍候......",
"REDIRECT_TO_WORSPACE_LOADING": "正在重定向到您的工作空间......",
"VERIFY_EMAIL_LOADING_TEXT": "正在验证您的电子邮箱,请稍候......",
"INPUT_TEAM_NAME": "输入您的团队名称",
"JOIN_EXISTING_TEAM": "加入已有团队?",
Expand Down

0 comments on commit 4f6c3c2

Please sign in to comment.