Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin][Frontend] Admin Registration Page #820

Merged
merged 18 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FrontEnd/src/pages/AdminPage/AdminGlobal.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
--border-input__admin-panel: #d9d9d9;
--background-butons__admin-panel: #1F9A7C;
--button-color__admin-panel: #1F9A7C;
--button-text-color__admin-panel: #FFF;
--error-notification-text-color__admin-panel: #f4282b;
--box-shadow-color__admin-panel: rgba(0, 0, 0, 0.04);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import axios from 'axios';
import { toast } from 'react-toastify';
import { Tooltip } from 'antd';
import { useState } from 'react';
import { EMAIL_PATTERN } from '../../../constants/constants';
import css from './AdminRegistration.module.css';

const AdminRegistration = () => {
const [email, setEmail] = useState('');
const [error, setError] = useState(null);

const handleInputChange = (e) => {
setEmail(e.target.value);
};

const url = `${process.env.REACT_APP_BASE_API_URL}/api/admin/admin_create/`;

const handleSubmit = () => {
EMAIL_PATTERN.test(email) ?
axios.post(url, { email: email })
.then(() => {
toast.success('Пароль надіслано на електронну адресу');
})
.catch(() => {
toast.error('Виникла помилка');
})
.finally(() => {
setError(null);
})
:
setError('Будь ласка, введіть дійсну електронну адресу');
};

return (
<div className={css['admin_registration-section']}>
<h3>Реєстрація Адміністратора</h3>
<div className={css['admin_registration-outer-wrapper']}>
<label className={css['admin_registration-label']} htmlFor="newAdminEmail">
<span className={css['admin_registration-asterisk']} >*</span>
Електронна адреса
</label>
<div className={css['admin_registration-input-wrapper']}>
<Tooltip
title={'Введіть тут електронну пошту особи, яку потрібно зареєструвати в якості адміністратора'}
placement="top">
<input className={css['admin_registration-input']}
id="newAdminEmail"
onChange={handleInputChange}
type="text"
placeholder="Введіть текст"
autoComplete="email" />
</Tooltip>
<button className={css['admin_registration-button']} onClick={handleSubmit}>
Згенерувати та надіслати пароль
</button>
</div>
{error && <p className={css['admin_registration-error']} >{error}</p>}
</div>
</div>
);
};

export default AdminRegistration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.admin_registration-section {
display: flex;
flex-direction: column;
padding-left: 25px;
padding-top: 30px;
}

.admin_registration-outer-wrapper {
display: flex;
flex-direction: column;
gap: 2px;
margin-top: 40px;
}
.admin_registration-asterisk {
font-family: var(--font-main);
font-size: 14px;
padding-right: 3px;
color: var(--notification-text-color__admin-panel);
}

.admin_registration-label {
color: var(--main-black-90, #292E32);
font-family: var(--font-main);
font-size: 14px;
line-height: 20px;
letter-spacing: -0.01em;
}

.admin_registration-input-wrapper {
display: flex;
flex-direction: row;
gap: 10px;
}

.admin_registration-input {
width: 320px;
height: 25px;
padding: 0 2px;
margin: auto;
}

.admin_registration-button {
padding: 5px 15px;
width: auto;
border-radius: 4px;
border: 1px solid var(--button-color__admin-panel);
background: var(--button-color__admin-panel);
box-shadow: 0px 2px 0px 0px var(--box-shadow-color__admin-panel);
color: var(--button-text-color__admin-panel);
font-family: var(--font-main);
font-size: 16px;
font-weight: 600;
line-height: 20px;
letter-spacing: -0.16px;
cursor: pointer;
}

.admin_registration-error {
color: var(--error-notification-text-color__admin-panel);
font-family: var(--font-main);
font-size: 14px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const AutoApproveDelay = () => {
});
const url = `${process.env.REACT_APP_BASE_API_URL}/api/admin/automoderation/`;
const { data, mutate } = useSWR(url, fetcher);
const [delay, setDelay] = useState(null);
const [delay, setDelay] = useState('');
const [error, setError] = useState(null);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions FrontEnd/src/pages/AdminPage/DetailView/ModerationEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ModerationEmail = () => {
const { data, mutate } = useSWR(url, fetcher);

// Define email and setEmail using useState
const [email, setEmail] = useState(null);
const [email, setEmail] = useState('');

// Update email state when data is fetched
useEffect(() => {
Expand Down Expand Up @@ -39,7 +39,7 @@ const ModerationEmail = () => {
title={'Введіть Email'}
placement="top"
pointAtCenter={true}>
<input className={css['moderation_email-input']} type="email" onChange={handleInputChange} value={email || ''} />
<input className={css['moderation_email-input']} type="email" onChange={handleInputChange} value={email} />
</Tooltip>
<button className={css['save-button']} onClick={handleSubmit}>Змінити</button>
</div>
Expand Down
6 changes: 6 additions & 0 deletions FrontEnd/src/pages/AdminPage/Menu/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const MENU = [
title: 'Пошта адміністратора',
link: '/customadmin/email/'
},
{
id: 'am6',
title: 'Реєстрація адміністратора',
link: '/customadmin/admin-create/'
}

];

function Menu() {
Expand Down
2 changes: 2 additions & 0 deletions FrontEnd/src/routes/AdminRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AutoApproveDelay from '../pages/AdminPage/AutoApproveDelay/AutoApproveDel
import ModerationEmail from '../pages/AdminPage/DetailView/ModerationEmail';
import Contacts from '../pages/AdminPage/DetailView/Contacts';
import AdminProfilePage from '../pages/AdminPage/AdminProfile/AdminProfilePage';
import AdminRegistration from '../pages/AdminPage/AdminRegistration/AdminRegistration';

import '../pages/AdminPage/AdminGlobal.css';
import css from '../pages/AdminPage/AdminPage.module.css';
Expand All @@ -35,6 +36,7 @@ function AdminRouter() {
<Route path="/email" element={<ModerationEmail />} />
<Route path="/contacts" element={<Contacts />} />
<Route path="/admin-profile/*" element={<AdminProfilePage />} />
<Route path="/admin-create" element={<AdminRegistration />} />
</>
) : (
<Route path="/customadmin/" />
Expand Down
Loading