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