lab8 it works
This commit is contained in:
parent
b33f7d8d20
commit
894fc76962
@ -17,6 +17,12 @@
|
|||||||
"password": "123",
|
"password": "123",
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"id": 3
|
"id": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "testUser3",
|
||||||
|
"password": "123",
|
||||||
|
"role": "user",
|
||||||
|
"id": 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.my-footer {
|
.my-footer {
|
||||||
background-color: #000000;
|
background-color: #000000;
|
||||||
height: 100px;
|
height: 80px;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
@ -3,14 +3,10 @@ import './Footer.css';
|
|||||||
|
|
||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
const year = new Date().getFullYear();
|
const year = new Date().getFullYear();
|
||||||
// let { id } = useAuthorization();
|
|
||||||
let id = localStorage.getItem('userId');
|
|
||||||
id = parseInt(id, 10);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<footer className="my-footer mt-auto d-block flex-shrink-0 align-items-center">
|
<footer className="my-footer mt-auto d-flex justify-content-center align-items-center flex-shrink-0">
|
||||||
<p>Id: {id || 'гость'}</p>
|
Захаров Р. А., {year}
|
||||||
<p className='d-flex justify-content-center'>Захаров Р. А., {year}</p>
|
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -19,9 +19,7 @@ const RegistrationForm = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
if (await handleSubmit(event)) {
|
await handleSubmit(event);
|
||||||
// onBack();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
import UsersApiService from '../service/UsersApiService';
|
||||||
|
|
||||||
const useUserObject = () => {
|
const useUserObject = (id) => {
|
||||||
const emptyObject = {
|
const emptyObject = {
|
||||||
name: '',
|
name: '',
|
||||||
password: '',
|
password: '',
|
||||||
role: 'user',
|
role: 'user',
|
||||||
id: '',
|
id: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const [userObject, setUserObject] = useState({ ...emptyObject });
|
const [userObject, setUserObject] = useState({ ...emptyObject });
|
||||||
|
|
||||||
|
const getUserObject = async (userId) => {
|
||||||
|
if (userId && userId > 0) {
|
||||||
|
const data = await UsersApiService.get(userId);
|
||||||
|
setUserObject(data);
|
||||||
|
} else {
|
||||||
|
setUserObject({ ...emptyObject });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUserObject(id);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user: userObject,
|
user: userObject,
|
||||||
setUser: setUserObject,
|
setUser: setUserObject,
|
||||||
|
@ -15,7 +15,7 @@ const RegistrationForm = () => {
|
|||||||
} = useRegistrationForm();
|
} = useRegistrationForm();
|
||||||
|
|
||||||
const onBack = () => {
|
const onBack = () => {
|
||||||
navigate(-1);
|
navigate('/user-page');
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
const useUserObject = () => {
|
|
||||||
const emptyObject = {
|
|
||||||
name: '',
|
|
||||||
password: '',
|
|
||||||
role: 'user',
|
|
||||||
id: '',
|
|
||||||
};
|
|
||||||
const [userObject, setUserObject] = useState({ ...emptyObject });
|
|
||||||
|
|
||||||
return {
|
|
||||||
user: userObject,
|
|
||||||
setUser: setUserObject,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useUserObject;
|
|
@ -1,15 +1,16 @@
|
|||||||
import { Button } from 'react-bootstrap';
|
import { Button } from 'react-bootstrap';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import useAuthorization from '../context_hooks/AuthorizationHook';
|
import useAuthorization from '../context_hooks/AuthorizationHook';
|
||||||
import useUserObject from './UserObjectHook';
|
import useUserObject from '../hooks/UserObjectHook';
|
||||||
|
|
||||||
const UserPageInfo = () => {
|
const UserPageInfo = () => {
|
||||||
// const id = parseInt(localStorage.getItem('userId'), 10);
|
const id = parseInt(localStorage.getItem('userId'), 10);
|
||||||
|
const { user } = useUserObject(id);
|
||||||
const { userLogout } = useAuthorization();
|
const { userLogout } = useAuthorization();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className='mt-2 text-md-start text-center'>
|
<h1 className='mt-2 text-md-start text-center'>
|
||||||
Здравствуйте, {null || 'гость'}
|
Здравствуйте, {user.name || 'гость'}!
|
||||||
</h1>
|
</h1>
|
||||||
<p className="mt-2 text-md-start text-center">
|
<p className="mt-2 text-md-start text-center">
|
||||||
Это ваш личный кабинет.
|
Это ваш личный кабинет.
|
||||||
|
Loading…
Reference in New Issue
Block a user