From 25c3e16c743fd29f3aedfeddaea870717aa04373 Mon Sep 17 00:00:00 2001 From: Nikolai Petukhov Date: Fri, 4 Oct 2024 15:53:50 +0300 Subject: [PATCH] changing fields in account is done and upd chats retrieval --- src/backend/api.js | 2 +- src/components/account/AccountButtons.jsx | 37 +++++++++++++++++++++-- src/components/home/css/homeTitle.css | 7 +++++ src/components/reg/InputField.jsx | 8 +++++ src/pages/Account.jsx | 19 +++++++++--- src/pages/Home.jsx | 17 +++++++---- stubs/api/auth/index.js | 4 +++ stubs/api/change/index.js | 2 ++ 8 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/backend/api.js b/src/backend/api.js index 48a7ae3..6e34813 100644 --- a/src/backend/api.js +++ b/src/backend/api.js @@ -5,7 +5,7 @@ const LOCAL = "http://localhost:8099"; const DEV = "https://dev.bro-js.ru"; const SERVER = ""; -export const BASE_API_URL = DEV + getConfigValue("enterfront.api") + "/enterfront"; +export const BASE_API_URL = LOCAL + getConfigValue("enterfront.api") + "/enterfront"; // fetch(`${BASE_API_URL}/books/list`) diff --git a/src/components/account/AccountButtons.jsx b/src/components/account/AccountButtons.jsx index 6c9539e..c6366bd 100644 --- a/src/components/account/AccountButtons.jsx +++ b/src/components/account/AccountButtons.jsx @@ -1,15 +1,46 @@ -import React from 'react'; +import React, {useState} from 'react'; import { URLs } from "../../__data__/urls"; import ActionButton from "./ActionButton.jsx"; +import InputField from "../reg/InputField.jsx"; const AccountButtons = (props) => { + const [chName, setChName] = useState(false); + const [chPassword, setChPassword] = useState(false); + + const [nickname, setNickname] = useState(""); + const [password, setPassword] = useState(""); + return (
{props.registered ? ( <> - - + setChName(true)}/> + {chName ? ( + + ) : null} + setChPassword(true)}/> + {chPassword ? ( +
+ +
+ ) : null} ) : null} Back diff --git a/src/components/home/css/homeTitle.css b/src/components/home/css/homeTitle.css index 46f254b..eebe649 100644 --- a/src/components/home/css/homeTitle.css +++ b/src/components/home/css/homeTitle.css @@ -20,6 +20,13 @@ align-items: center; } +.search-input div input { + background-color: white; + color: black; + + border: 3px solid black; +} + @media only screen and (max-width: 800px) { .homeTitle { diff --git a/src/components/reg/InputField.jsx b/src/components/reg/InputField.jsx index 1b7ccca..730a4d4 100644 --- a/src/components/reg/InputField.jsx +++ b/src/components/reg/InputField.jsx @@ -1,6 +1,7 @@ import React from 'react'; const InputField = (props) => { + console.log('class:', props.className) return (

{props.title}

@@ -9,6 +10,13 @@ const InputField = (props) => { value={props.value} className="Input" placeholder={(props.placeholder) ? props.placeholder : ''} + onKeyDown={(e) => { + if (e.key === 'Enter') { + if (props.submit) { + props.enter(props.submit); + } + } + }} />
); diff --git a/src/pages/Account.jsx b/src/pages/Account.jsx index 338c109..9133a9e 100644 --- a/src/pages/Account.jsx +++ b/src/pages/Account.jsx @@ -19,10 +19,10 @@ const Account = () => { const [nickname, setNickname] = useState(""); const [id, setId] = useState(""); - async function changeNameHandler () { - // ... + async function changeNameHandler (newNickname) { + if (!newNickname) return; - const {ok, data} = await post('/change/nickname', {id: id, newNickname: "New Name"}); + const {ok, data} = await post('/change/nickname', {id: id, newNickname: newNickname}); if (!ok) { displayMessage(data.message, MessageType.ERROR); @@ -32,8 +32,17 @@ const Account = () => { } } - async function changePassHandler (){ - // ... + async function changePassHandler (newPass){ + if (!newPass) return; + + const {ok, data} = await post('/change/password', {id: id, newPassword: newPass}); + + if (!ok) { + displayMessage(data.message, MessageType.ERROR); + } else { + localStorage.setItem("message", "Password was changed"); + window.location.href = URLs.account.url; + } } async function getUser() { diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 794d43f..2158801 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -35,6 +35,8 @@ const Home = () => { return; } + displayMessage("Sent", MessageType.INFO); + const {ok, data} = await post('/chat/item/' + username + '/' + alias); if (!ok) { displayMessage(data.message, MessageType.ERROR); @@ -55,12 +57,15 @@ const Home = () => { - +
+ +
+

Your chats

diff --git a/stubs/api/auth/index.js b/stubs/api/auth/index.js index e9d6177..ea32017 100644 --- a/stubs/api/auth/index.js +++ b/stubs/api/auth/index.js @@ -34,11 +34,13 @@ authRouter.post('/login', (req, res) => { // Invalid identification if (!user) { res.status(401).send({message: 'Invalid credentials (id)'}); + return; } // Invalid authentication if (!password || password !== user.password) { res.status(401).send({message: 'Invalid credentials (password)'}); + return; } // Now, authorization @@ -59,10 +61,12 @@ authRouter.post('/reg', (req, res) => { // Invalid identification if (user) { res.status(409).send({message: 'Such id already exists'}); + return; } if (!name || !password || !nickname) { res.status(401).send({message: 'Empty or invalid fields'}); + return; } // Add to 'DB' diff --git a/stubs/api/change/index.js b/stubs/api/change/index.js index 37c3d98..c5e0837 100644 --- a/stubs/api/change/index.js +++ b/stubs/api/change/index.js @@ -16,6 +16,7 @@ changeRouter.post('/nickname', (req, res) => { // Invalid identification if (!user) { res.status(401).send({message: 'Invalid credentials (id)'}); + return; } const updatedUser = { @@ -42,6 +43,7 @@ changeRouter.post('/password', (req, res) => { // Invalid identification if (!user) { res.status(401).send({message: 'Invalid credentials (id)'}); + return; } // Delete the old one