From ed718f5ecc2e5a0c37ad99ac8f830d13671c2905 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 26 Sep 2022 16:32:41 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=95=D1=81=D0=BB=D0=B8=20=D1=83=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=B8=D0=BC?= =?UTF-8?q?=D1=8F=20=D0=B8=20=D0=BF=D0=BE=D1=87=D1=82=D0=B0,=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BB=D0=B5=D0=B7=D0=B5=D1=82=20=D0=BC=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=BA=D0=BD=D0=BE,=20?= =?UTF-8?q?=D1=81=20=D0=BF=D1=80=D0=BE=D1=81=D1=8C=D0=B1=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D1=8C=20=D0=B8?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/profile/ProfileUser.jsx | 6 ++- src/features/profile/profileSlice.js | 22 +++++++++++ .../questions-list/QuestionsList.jsx | 37 ++++++++++++++++++- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/features/profile/ProfileUser.jsx b/src/features/profile/ProfileUser.jsx index 7dfe8af..236b73b 100644 --- a/src/features/profile/ProfileUser.jsx +++ b/src/features/profile/ProfileUser.jsx @@ -60,8 +60,10 @@ const ProfileUser = () => {
Зарегистрирован {dayjs(profile.createdAt).fromNow()}
-
Атамазов Насырбек
-
atamazov00@mail.ru
+
+ {profile.fullName ? profile.fullName : `User ${profile._id}`} +
+
{profile.email}
diff --git a/src/features/profile/profileSlice.js b/src/features/profile/profileSlice.js index 7467ec8..729d225 100644 --- a/src/features/profile/profileSlice.js +++ b/src/features/profile/profileSlice.js @@ -15,6 +15,21 @@ export const fetchProfile = createAsyncThunk('profile/fetch', async (_, thunkAPI } }); +export const patchFullName = createAsyncThunk( + 'profile/patch', + async ({ id, value, emailValue }, thunkAPI) => { + try { + const response = await axios.patch(`http://localhost:3030/user/profile/${id}`, { + fullName: value, + email: emailValue, + }); + return response.data; + } catch (e) { + return thunkAPI.rejectWithValue(e.message); + } + } +); + const profileSlice = createSlice({ name: 'profile', initialState: { @@ -26,6 +41,7 @@ const profileSlice = createSlice({ questionIdsThatUserFavorite: [], isAdmin: false, createdAt: null, + email: null, // добавить остальные поля по мере необходимости }, @@ -43,6 +59,7 @@ const profileSlice = createSlice({ state.questionIdsThatUserFavorite = payload.questionIdsThatUserFavorite; state.isAdmin = payload.isAdmin; state.createdAt = payload.createdAt; + state.email = payload.email; }, [addQuestionToFavorites.pending]: (state, action) => { @@ -54,6 +71,11 @@ const profileSlice = createSlice({ (id) => id !== action.meta.arg.questionId ); }, + + [patchFullName.fulfilled]: (state, action) => { + state.fullName = action.payload.fullName; + state.email = action.payload.email; + }, }, reducers: { resetProfile: (state) => { diff --git a/src/features/questions/questions-list/QuestionsList.jsx b/src/features/questions/questions-list/QuestionsList.jsx index bc8d8d3..f6e05c1 100644 --- a/src/features/questions/questions-list/QuestionsList.jsx +++ b/src/features/questions/questions-list/QuestionsList.jsx @@ -1,6 +1,6 @@ -import React, { useEffect, useCallback } from 'react'; +import React, { useEffect, useCallback, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { Spin, Switch } from 'antd'; +import { Button, Input, Modal, Spin, Switch } from 'antd'; import { LoadingOutlined } from '@ant-design/icons'; import styled from 'styled-components'; import { Title } from 'app/Title/Title'; @@ -21,6 +21,7 @@ import { generateTitle } from 'common/utils/title'; import { useQueryString } from 'common/hooks/useQueryString'; import QuestionsListMapper from './QuestionsListMapper'; import QuestionEmptyFolder from './QuestionEmptyFolder'; +import { patchFullName, selectProfile } from '../../profile/profileSlice'; const StyledSwitchBlock = styled.span` color: #409eff; @@ -86,8 +87,40 @@ const QuestionsList = () => { dispatch(toggleIsCompactMode()); }; + const profile = useSelector(selectProfile); + + const [value, setValue] = useState(''); + const [emailValue, setEmailValue] = useState(''); + + const id = profile._id; + + const handleSubmit = () => { + dispatch(patchFullName({ id, value, emailValue })); + setValue(''); + setEmailValue(''); + }; + return ( <> + +
+ setValue(e.target.value)} + type="text" + placeholder="Введите имя и фамилию" + /> + setEmailValue(e.target.value)} + type="text" + placeholder="Введите Email" + /> + +
+
{`iqa: ${generatedTitle}`}
From f6dda6d4e8cefdd6c357a364c6ab966eed91312a Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 30 Sep 2022 17:08:27 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BC=D0=BE=D0=B4=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D0=B8=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=BB=20=D1=81=D1=82=D0=B8=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/App.jsx | 2 + src/components/PatchUserModal.jsx | 73 +++++++++++++++++++ src/features/profile/profileSlice.js | 10 +-- .../questions-list/QuestionsList.jsx | 37 +--------- 4 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 src/components/PatchUserModal.jsx diff --git a/src/app/App.jsx b/src/app/App.jsx index c02f5ac..338e206 100644 --- a/src/app/App.jsx +++ b/src/app/App.jsx @@ -5,6 +5,7 @@ import { useAuth } from 'common/context/Auth/useAuth'; import { Header } from 'components/layout/header/Header'; import { fetchProfile } from 'features/profile/profileSlice'; import { Footer } from 'components/layout/Footer'; +import PatchUserModal from 'components/PatchUserModal'; import { LazyPlaceholder } from './LazyPlaceholder'; const QuestionPage = lazy(() => import('features/questions/question-page/QuestionPage')); @@ -56,6 +57,7 @@ export const App = () => { return ( <> +
}> diff --git a/src/components/PatchUserModal.jsx b/src/components/PatchUserModal.jsx new file mode 100644 index 0000000..ab4136a --- /dev/null +++ b/src/components/PatchUserModal.jsx @@ -0,0 +1,73 @@ +import { Button, Input, Modal } from 'antd'; +import React, { useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { selectProfile, updateProfile } from 'features/profile/profileSlice'; +import styled from 'styled-components'; + +const StyledModalHeading = styled.h2` + text-align: center; +`; +const StyledButtonBlock = styled.div` + width: 110px; + margin: auto; +`; + +const PatchUserModal = () => { + const profile = useSelector(selectProfile); + + const dispatch = useDispatch(); + + const [userFullName, setUserFullName] = useState(''); + const [userEmail, setUserEmail] = useState(''); + + const id = profile._id; + + const handleSubmit = () => { + dispatch(updateProfile({ id, userFullName, userEmail })); + setUserFullName(''); + setUserEmail(''); + }; + + const isModalOpened = !profile.fullName || !profile.email; + + return ( +
+ +
+ Введите полное имя и почту, что бы продолжить +
+ {profile.fullName && ( + setUserFullName(e.target.value)} + type="text" + placeholder="Введите имя и фамилию" + /> + )} + {profile.email && ( + setUserEmail(e.target.value)} + type="text" + placeholder="Введите Email" + className="mt-2" + /> + )} + + + +
+
+
+
+ ); +}; + +export default PatchUserModal; diff --git a/src/features/profile/profileSlice.js b/src/features/profile/profileSlice.js index 729d225..938ee80 100644 --- a/src/features/profile/profileSlice.js +++ b/src/features/profile/profileSlice.js @@ -15,13 +15,13 @@ export const fetchProfile = createAsyncThunk('profile/fetch', async (_, thunkAPI } }); -export const patchFullName = createAsyncThunk( +export const updateProfile = createAsyncThunk( 'profile/patch', - async ({ id, value, emailValue }, thunkAPI) => { + async ({ id, userFullName, userEmail }, thunkAPI) => { try { const response = await axios.patch(`http://localhost:3030/user/profile/${id}`, { - fullName: value, - email: emailValue, + fullName: userFullName, + email: userEmail, }); return response.data; } catch (e) { @@ -72,7 +72,7 @@ const profileSlice = createSlice({ ); }, - [patchFullName.fulfilled]: (state, action) => { + [updateProfile.fulfilled]: (state, action) => { state.fullName = action.payload.fullName; state.email = action.payload.email; }, diff --git a/src/features/questions/questions-list/QuestionsList.jsx b/src/features/questions/questions-list/QuestionsList.jsx index f6e05c1..bc8d8d3 100644 --- a/src/features/questions/questions-list/QuestionsList.jsx +++ b/src/features/questions/questions-list/QuestionsList.jsx @@ -1,6 +1,6 @@ -import React, { useEffect, useCallback, useState } from 'react'; +import React, { useEffect, useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { Button, Input, Modal, Spin, Switch } from 'antd'; +import { Spin, Switch } from 'antd'; import { LoadingOutlined } from '@ant-design/icons'; import styled from 'styled-components'; import { Title } from 'app/Title/Title'; @@ -21,7 +21,6 @@ import { generateTitle } from 'common/utils/title'; import { useQueryString } from 'common/hooks/useQueryString'; import QuestionsListMapper from './QuestionsListMapper'; import QuestionEmptyFolder from './QuestionEmptyFolder'; -import { patchFullName, selectProfile } from '../../profile/profileSlice'; const StyledSwitchBlock = styled.span` color: #409eff; @@ -87,40 +86,8 @@ const QuestionsList = () => { dispatch(toggleIsCompactMode()); }; - const profile = useSelector(selectProfile); - - const [value, setValue] = useState(''); - const [emailValue, setEmailValue] = useState(''); - - const id = profile._id; - - const handleSubmit = () => { - dispatch(patchFullName({ id, value, emailValue })); - setValue(''); - setEmailValue(''); - }; - return ( <> - -
- setValue(e.target.value)} - type="text" - placeholder="Введите имя и фамилию" - /> - setEmailValue(e.target.value)} - type="text" - placeholder="Введите Email" - /> - -
-
{`iqa: ${generatedTitle}`}
From b5f08f97ee1ade06de69488e3075eaf69c5a76e8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 2 Oct 2022 01:38:01 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B1?= =?UTF-8?q?=D0=B5=D1=81=D1=81=D0=BC=D1=8B=D0=BB=D0=B5=D0=BD=D0=BD=D1=83?= =?UTF-8?q?=D1=8E=20=D0=BE=D1=87=D0=B8=D1=81=D1=82=D1=83=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9=20=D0=B2=D0=B2=D0=BE=D0=B4=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PatchUserModal.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/PatchUserModal.jsx b/src/components/PatchUserModal.jsx index ab4136a..74e5d8f 100644 --- a/src/components/PatchUserModal.jsx +++ b/src/components/PatchUserModal.jsx @@ -24,8 +24,6 @@ const PatchUserModal = () => { const handleSubmit = () => { dispatch(updateProfile({ id, userFullName, userEmail })); - setUserFullName(''); - setUserEmail(''); }; const isModalOpened = !profile.fullName || !profile.email;