diff --git a/src/components/forum/forumSubjectUpdate.js b/src/components/forum/forumSubjectUpdate.js
index 1d20122..4ca6cec 100644
--- a/src/components/forum/forumSubjectUpdate.js
+++ b/src/components/forum/forumSubjectUpdate.js
@@ -17,14 +17,27 @@ const ForumSubjectUpdate = ({
const updateSubjectTitle = React.createRef()
const updateSubjectAuthor = React.createRef()
+ const [selectAuthorID, setSelectAuthorID] = useState(-1)
+ const [selectThreadID, setSelectThreadID] = useState(-1)
+
const updateOldSubject = (event) => {
event.preventDefault()
- if ( updateSubjectTitle.current.value !== '') {
+ if ( updateSubjectTitle.current.value !== '' && selectAuthorID === -1 && selectThreadID === -1 ) {
let putSubject = {
id: subject.id,
name: updateSubjectTitle.current.value,
- user_id: user.id,
- thread_id: threads.actualThreadID,
+ user_id: subject.user_id,
+ thread_id: subject.thread_id,
+ token: user.token
+ }
+ updateSubject(putSubject)
+ updateSubjectTitle.current.value = ''
+ } else if ( updateSubjectTitle.current.value !== '' && user.privilige >= 2 ) {
+ let putSubject = {
+ id: subject.id,
+ name: updateSubjectTitle.current.value,
+ user_id: selectAuthorID === -1 ? subject.user_id : selectAuthorID,
+ thread_id: selectThreadID === -1 ? subject.thread_id : selectThreadID,
token: user.token
}
updateSubject(putSubject)
@@ -51,8 +64,8 @@ const ForumSubjectUpdate = ({
{ threads.subjectsList.map( subject =>
+
-
)
}
+
+
) }
@@ -140,6 +155,7 @@ const mapDispatchToProps = dispatch => ({
refreshThreadSubjects: threads => dispatch( refreshThreadSubjects(threads) ),
getSubjectComments: subjects => dispatch( getSubjectComments(subjects) ),
addSubject: subjects => dispatch( addSubject(subjects) ),
+ deleteSubject: subjects => dispatch( deleteSubject(subjects) ),
addComment: comments => dispatch( addComment(comments) ),
deactivate: () => dispatch( actions.deactivate() )
diff --git a/src/stores/subjects/duck/operations.js b/src/stores/subjects/duck/operations.js
index fa1da0a..4fdc54c 100644
--- a/src/stores/subjects/duck/operations.js
+++ b/src/stores/subjects/duck/operations.js
@@ -47,14 +47,14 @@ const fetchPutSubject = async (data) => {
return response.json()
}
- export const putSubject = (data) =>
+ export const updateSubject = (data) =>
async (dispatch) => {
const comments = await fetchPutSubject(data)
}
const fetchDeleteSubject = async (data) => {
const response = await
- fetch('http://localhost:8001/index/subject/' + data.id, {
+ fetch('http://localhost:8001/index/subject/' + data.subject_id, {
method: 'DELETE',
credentials: 'same-origin',
body: JSON.stringify(data)
diff --git a/src/stores/user/duck/operations.js b/src/stores/user/duck/operations.js
index 5d78bf2..e4624ce 100644
--- a/src/stores/user/duck/operations.js
+++ b/src/stores/user/duck/operations.js
@@ -43,18 +43,33 @@ const fetchRegister = async (user) => {
)
}
+const fetchGetAllUsers = async () => {
+ const response = await
+ fetch (
+ 'http://localhost:8001/index/user', {
+ method: 'GET',
+ credential: 'same-origin'
+ }
+ )
+ const json = response.json()
+ return json
+}
+
export const createSession = (data) =>
async (dispatch) => {
const token = await fetchLogin(data)
let user = jwtDecode(token.token)
+ let allUsers = await fetchGetAllUsers()
+
let userFull = {
- 'token': token.token,
- 'id': user.payload.id,
- 'login': user.payload.login,
- 'privilige': user.payload.privilige,
- 'avatar': user.payload.avatar,
- 'email': user.payload.email
+ token: token.token,
+ id: user.payload.id,
+ login: user.payload.login,
+ privilige: user.payload.privilige,
+ avatar: user.payload.avatar,
+ email: user.payload.email,
+ allUsersList: allUsers
}
dispatch(actions.login(userFull))
diff --git a/src/stores/user/duck/reducers.js b/src/stores/user/duck/reducers.js
index f5775f0..7fb8772 100644
--- a/src/stores/user/duck/reducers.js
+++ b/src/stores/user/duck/reducers.js
@@ -7,7 +7,8 @@ const INITIAL_STATE = {
privilige: '',
avatar: '',
token: '',
- isActive: false
+ isActive: false,
+ allUsersList: []
}
const userReducer = (state = INITIAL_STATE, action) => {
@@ -20,6 +21,7 @@ const userReducer = (state = INITIAL_STATE, action) => {
email: action.item.email,
avatar: action.item.avatar,
token: action.item.token,
+ allUsersList: action.item.allUsersList,
isActive: true
}
case types.LOGOUT_USER:
diff --git a/src/styles/general.scss b/src/styles/general.scss
index 6360a06..b5fe1a1 100644
--- a/src/styles/general.scss
+++ b/src/styles/general.scss
@@ -7,6 +7,10 @@ body {
@include inputStyle
}
+ select {
+ @include inputStyle
+ }
+
textarea {
@include inputStyle
text-align: left;
diff --git a/src/styles/indexForum.scss b/src/styles/indexForum.scss
index 9cbb93c..0f71bb9 100644
--- a/src/styles/indexForum.scss
+++ b/src/styles/indexForum.scss
@@ -98,6 +98,8 @@
p:last-child {
float: right;
padding-top: 10px;
+ min-width: 120px;
+ text-align: right;
}
@@ -186,11 +188,19 @@
transition-duration: 0.5s;
@include gapTopBetweenElements
+ form {
+ width: 100%;
+ }
input {
width: 100%;
float: left;
text-align: left;
}
+ select {
+ width: 100%;
+ float: left;
+
+ }
textarea {
width: 100%;
height: 200px;