Skip to content

Commit

Permalink
feat: Add User and Admin toggle on login pages (#1371)
Browse files Browse the repository at this point in the history
* feat: Add User and Admin toggle on login pages

* Refactoring and Design adjustments

* fix conflicting files
  • Loading branch information
meetulr authored Jan 6, 2024
1 parent 7482d75 commit fba3322
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 306 deletions.
3 changes: 2 additions & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"notAuthorised": "Sorry! you are not Authorised!",
"notFound": "User not found!",
"successfullyRegistered": "Successfully Registered. Please wait until you will be approved.",
"login_to_admin_portal": "Admin Portal Login",
"OR": "OR",
"admin": "ADMIN",
"user": "USER",
"lowercase_check": "Atleast one lowercase letter",
"uppercase_check": "Atleast one uppercase letter",
"numeric_value_check": "Atleaset one numeric value",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"notAuthorised": "Désolé ! vous n'êtes pas autorisé !",
"notFound": "Utilisateur introuvable !",
"successfullyRegistered": "Enregistré avec succès. Veuillez patienter jusqu'à ce que vous soyez approuvé.",
"login_to_admin_portal": "Connexion à l'administration du portail",
"OR": "OU",
"admin": "ADMIN",
"user": "UTILISATEUR",
"lowercase_check": "Au moins une lettre minuscule",
"uppercase_check": "Au moins une lettre majuscule",
"special_char_check": "Au moins un caractère spécial",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"notAuthorised": "क्षमा करें! आप अधिकृत नहीं हैं!",
"notFound": "उपयोगकर्ता नहीं मिला!",
"successfullyRegistered": "सफलतापूर्वक पंजीकृत। कृपया स्वीकृत होने तक प्रतीक्षा करें।",
"login_to_admin_portal": "एडमिन पोर्टल लॉगिन",
"OR": "या",
"admin": "व्यवस्थापक",
"user": "उपयोगकर्ता",
"lowercase_check": "कम से कम एक छोटा अक्षर",
"uppercase_check": "कम से कम एक बड़ा अक्षर",
"numeric_value_check": "कम से कम एक संख्यात्मक मान",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"notAuthorised": "¡Lo siento! ¡No estás autorizado!",
"notFound": "¡Usuario no encontrado!",
"successfullyRegistered": "Registrado con éxito. Espere hasta que sea aprobado",
"login_to_admin_portal": "Inicio de sesión en el portal de administración",
"OR": "O",
"admin": "ADMINISTRACIÓN",
"user": "USUARIO",
"lowercase_check": "Al menos una letra mayuscula",
"uppercase_check": "Al menos una letra minúscula",
"numeric_value_check": "Al menos un valor numérico",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"notAuthorised": "抱歉!你沒有被授權!",
"notFound": "找不到用戶!",
"successfullyRegistered": "註冊成功,請等待審核通過。",
"login_to_admin_portal": " 管理员门户登录 ",
"OR": "或者",
"admin": "行政",
"user": "用戶",
"lowercase_check": "至少一個小寫字母",
"uppercase_check": "至少有一個大寫字母",
"numeric_value_check": "至少一個數值",
Expand Down
34 changes: 34 additions & 0 deletions src/components/LoginPortalToggle/LoginPortalToggle.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.navLinkClass {
display: inline-block;
padding: 0.375rem 0.75rem;
font-size: 1rem;
line-height: 1.4;
text-align: center;
vertical-align: middle;
cursor: pointer;
color: var(--bs-gray-900);
border-radius: 0.3rem;
width: 100%;
box-sizing: border-box;
border: 1px solid var(--bs-gray-700);
font-weight: 500;
transition: all 0.25s ease;
}

.navLinkClass:hover {
color: var(--bs-white);
background-color: var(--bs-gray);
border-color: var(--bs-gray);
}

.activeLink {
color: var(--bs-white);
border: 1px solid var(--bs-primary);
background-color: var(--bs-primary);
}

.activeLink:hover {
color: var(--bs-white);
background-color: var(--bs-primary);
border: 1px solid var(--bs-primary);
}
32 changes: 32 additions & 0 deletions src/components/LoginPortalToggle/LoginPortalToggle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { act, render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import LoginPortalToggle from './LoginPortalToggle';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';

async function wait(ms = 100): Promise<void> {
await act(() => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
});
}

describe('Testing LoginPortalToggle component', () => {
test('Component Should be rendered properly', async () => {
render(
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPortalToggle />
</I18nextProvider>
</Provider>
</BrowserRouter>
);

await wait();
});
});
37 changes: 37 additions & 0 deletions src/components/LoginPortalToggle/LoginPortalToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import styles from './LoginPortalToggle.module.css';
import Col from 'react-bootstrap/Col';
import Row from 'react-bootstrap/Row';
import { NavLink } from 'react-router-dom';

function loginPortalToggle(): JSX.Element {
const { t } = useTranslation('translation', { keyPrefix: 'loginPage' });

return (
<Row className="mb-4">
<Col>
<NavLink
className={styles.navLinkClass}
activeClassName={styles.activeLink}
exact
to="/"
>
{t('admin')}
</NavLink>
</Col>
<Col>
<NavLink
className={styles.navLinkClass}
activeClassName={styles.activeLink}
exact
to="/user"
>
{t('user')}
</NavLink>
</Col>
</Row>
);
}

export default loginPortalToggle;
3 changes: 1 addition & 2 deletions src/components/UserPortal/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export default function login(props: InterfaceLoginProps): JSX.Element {
/* istanbul ignore next */
window.location.assign('/user/organizations');
} else {
/* istanbul ignore next */
toast.warn(t('notAuthorised'));
}
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
}
}
Expand Down Expand Up @@ -84,7 +84,6 @@ export default function login(props: InterfaceLoginProps): JSX.Element {
return (
<>
<h3 className="mt-3 font-weight-bold">{t('login')}</h3>
<div className="mt-1">{t('loginIntoYourAccount')}</div>

<div className="my-3">
<h6>{t('emailAddress')}</h6>
Expand Down
40 changes: 14 additions & 26 deletions src/screens/LoginPage/LoginPage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,32 @@
margin: 0;
position: absolute;
top: 1rem;
left: 2rem;
left: 1rem;
}

.langChangeBtnStyle {
width: 7.5rem;
height: 2.2rem;
padding: 0;
}

.row .right_portion .talawa_logo {
height: 150px;
width: 150px;
height: 5rem;
width: 5rem;
display: block;
margin: 1rem auto;
margin-top: 30px;
-webkit-animation: zoomIn 0.3s ease-in-out;
animation: zoomIn 0.3s ease-in-out;
}

.row .orText {
display: block;
position: absolute;
top: calc(-0.7rem - 0.5rem);
top: 0;
left: calc(50% - 2.6rem);
margin: 0 auto;
padding: 0.5rem 2rem;
padding: 0.35rem 2rem;
z-index: 100;
background: var(--bs-white);
color: var(--bs-secondary);
Expand Down Expand Up @@ -125,8 +132,8 @@
}

.row .right_portion .talawa_logo {
height: 120px;
margin: 0 auto 2rem auto;
height: 80px;
margin: 1rem auto 0.5rem auto;
}

.socialIcons {
Expand Down Expand Up @@ -200,22 +207,3 @@
gap: 16px;
justify-content: center;
}

.password_checks {
display: flex;
justify-content: space-between;
align-items: flex-start;
flex-direction: column;
}

.password_check_element {
margin-top: -10px;
}

.password_check_element_top {
margin-top: 18px;
}

.password_check_element_bottom {
margin-bottom: -20px;
}
50 changes: 3 additions & 47 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('Testing Login Page Screen', () => {

await wait();

expect(screen.getByText(/Admin Portal/i)).toBeInTheDocument();
expect(screen.getByText(/Admin/i)).toBeInTheDocument();
expect(window.location).toBeAt('/orglist');
});

Expand All @@ -175,8 +175,8 @@ describe('Testing Login Page Screen', () => {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
password: 'John@123',
confirmPassword: 'John@123',
password: 'johndoe',
confirmPassword: 'johndoe',
};

render(
Expand Down Expand Up @@ -215,50 +215,6 @@ describe('Testing Login Page Screen', () => {
userEvent.click(screen.getByTestId('registrationBtn'));
});

test('Testing registration functionality when all inputs are invalid', async () => {
const formData = {
firstName: '1234',
lastName: '8890',
email: '[email protected]',
password: 'john@123',
confirmPassword: 'john@123',
};

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPage />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

await wait();

userEvent.click(screen.getByTestId(/goToRegisterPortion/i));

await wait();

userEvent.type(
screen.getByPlaceholderText(/First Name/i),
formData.firstName
);
userEvent.type(
screen.getByPlaceholderText(/Last name/i),
formData.lastName
);
userEvent.type(screen.getByTestId(/signInEmail/i), formData.email);
userEvent.type(screen.getByPlaceholderText('Password'), formData.password);
userEvent.type(
screen.getByPlaceholderText('Confirm Password'),
formData.confirmPassword
);
userEvent.click(screen.getByTestId('registrationBtn'));
});

test('Testing registration functionality, when password and confirm password is not same', async () => {
const formData = {
firstName: 'John',
Expand Down
Loading

0 comments on commit fba3322

Please sign in to comment.