From 8e37a148a6fae84f8f2368912634173ffe2e545f Mon Sep 17 00:00:00 2001 From: Bobby Date: Fri, 27 Aug 2021 14:25:05 +0530 Subject: [PATCH 1/3] fixed backlog issues #128, #127, #118 --- src/components/Assignments/AssignUser.js | 40 +- src/components/UploadTexts.js | 1 - src/store/actions/userActions.js | 444 ++++++++++++----------- 3 files changed, 257 insertions(+), 228 deletions(-) diff --git a/src/components/Assignments/AssignUser.js b/src/components/Assignments/AssignUser.js index ccbc1f1..bf1ae04 100755 --- a/src/components/Assignments/AssignUser.js +++ b/src/components/Assignments/AssignUser.js @@ -32,6 +32,7 @@ import { bibleBookNewTestments, bibleBookOldTestments, } from "../Common/BibleOldNewTestment"; +import swal from "sweetalert"; const styles = (theme) => ({ root: { @@ -317,18 +318,41 @@ class AssignUser extends Component { assignBooksToUser = () => { const { userId, availableBooksData } = this.state; - const { dispatch, location } = this.props; + const { dispatch, location, assignedUsers } = this.props; const projectId = location.pathname.split("/").pop(); + console.log(assignedUsers, "users"); + let assignedUsersBooks = []; + for (var i in assignedUsers) { + //Listing the books of users + if (assignedUsers[i].user.userId === this.state.userId) { + console.log(assignedUsers[i], "state", this.state.userId); + + //Checking if not current user then push the books + assignedUsersBooks = assignedUsers[i].books; + } + } + console.log(assignedUsersBooks, "assigned books"); const checkedBooks = Object.keys(availableBooksData).filter( (book) => availableBooksData[book]["assigned"] === true ); - const apiData = { - projectId: projectId, - userId: userId, - books: checkedBooks, - action: "assign", - }; - dispatch(assignUserToProject(apiData, this.closeBookListing)); + if ( + assignedUsersBooks.sort().toString() === + checkedBooks.sort().toString() + ) { + swal({ + title: "Book assignment", + text: "No change in assigned books", + icon: "warning", + }); + } else { + const apiData = { + projectId: projectId, + userId: userId, + books: checkedBooks, + action: "assign", + }; + dispatch(assignUserToProject(apiData, this.closeBookListing)); + } }; render() { diff --git a/src/components/UploadTexts.js b/src/components/UploadTexts.js index 90a36b6..713fdf5 100755 --- a/src/components/UploadTexts.js +++ b/src/components/UploadTexts.js @@ -14,7 +14,6 @@ import ComponentHeading from "./ComponentHeading"; import { uploadBibleTexts, setCompletedUpload, - setUploadError, clearUploadError, } from "../store/actions/sourceActions"; import { connect } from "react-redux"; diff --git a/src/store/actions/userActions.js b/src/store/actions/userActions.js index 91962f7..55b6133 100755 --- a/src/store/actions/userActions.js +++ b/src/store/actions/userActions.js @@ -1,8 +1,8 @@ import { - SET_USERS, - SET_IS_FETCHING, - SET_ASSIGNED_USERS, - SET_USER_BOOKS, + SET_USERS, + SET_IS_FETCHING, + SET_ASSIGNED_USERS, + SET_USER_BOOKS, } from "./actionConstants"; import apiUrl from "../../components/GlobalUrl.js"; import swal from "sweetalert"; @@ -10,249 +10,255 @@ import swal from "sweetalert"; const accessToken = localStorage.getItem("accessToken"); export const fetchUsers = () => async (dispatch) => { - try { - dispatch(setIsFetching(true)); - const data = await fetch(apiUrl + "v1/autographamt/users", { - method: "GET", - headers: { - Authorization: "bearer " + accessToken, - }, - }); - const userData = await data.json(); - dispatch(setUsers(userData)); - } catch (e) { - swal({ - title: "Users", - text: "Unable to fetch users, check your internet connection or contact admin", - icon: "error", - }); - } - dispatch(setIsFetching(false)); + try { + dispatch(setIsFetching(true)); + const data = await fetch(apiUrl + "v1/autographamt/users", { + method: "GET", + headers: { + Authorization: "bearer " + accessToken, + }, + }); + const userData = await data.json(); + dispatch(setUsers(userData)); + } catch (e) { + swal({ + title: "Users", + text: "Unable to fetch users, check your internet connection or contact admin", + icon: "error", + }); + } + dispatch(setIsFetching(false)); }; export const updateAdminStatus = (data) => async (dispatch) => { - try { - dispatch(setIsFetching(true)); - const update = await fetch(apiUrl + "v1/autographamt/approvals/users", { - method: "POST", - body: JSON.stringify(data), - headers: { - Authorization: "bearer " + accessToken, - }, - }); - const response = await update.json(); - if (response.success) { - dispatch(fetchUsers()); - swal({ - title: "User status", - text: "User status has been updated successfully", - icon: "success", - }); - } else { - swal({ - title: "User status", - text: "User status could not be updated. Please try later", - icon: "error", - }); - } - } catch (e) { - swal({ - title: "Users", - text: "Unable to update users, check your internet connection or contact admin", - icon: "error", - }); - } - dispatch(setIsFetching(false)); + try { + dispatch(setIsFetching(true)); + const update = await fetch(apiUrl + "v1/autographamt/approvals/users", { + method: "POST", + body: JSON.stringify(data), + headers: { + Authorization: "bearer " + accessToken, + }, + }); + const response = await update.json(); + if (response.success) { + dispatch(fetchUsers()); + swal({ + title: "User status", + text: "User status has been updated successfully", + icon: "success", + }); + } else { + swal({ + title: "User status", + text: "User status could not be updated. Please try later", + icon: "error", + }); + } + } catch (e) { + swal({ + title: "Users", + text: "Unable to update users, check your internet connection or contact admin", + icon: "error", + }); + } + dispatch(setIsFetching(false)); }; export const getAssignedUsers = (projectId) => async (dispatch) => { - try { - dispatch(setIsFetching(true)); - const data = await fetch( - apiUrl + "v1/autographamt/projects/assignments/" + projectId, - { - method: "GET", - headers: { - Authorization: "bearer " + accessToken, - }, - } - ); - const assignedUsers = await data.json(); - if (!assignedUsers.message) { - // this.setState({ assignedUsers }) - dispatch(setAssignedUsers(assignedUsers)); - dispatch(setIsFetching(false)); - } else { - dispatch(setIsFetching(false)); - swal({ - title: "Assigned Users", - text: assignedUsers.message, - icon: "error", - }); - } - } catch (e) { - dispatch(setIsFetching(false)); - swal({ - title: "Assigned Users", - text: - "Unable to fetch assigned users, check your internet connection or contact admin" + - e, - icon: "error", - }); - } + try { + dispatch(setIsFetching(true)); + const data = await fetch( + apiUrl + "v1/autographamt/projects/assignments/" + projectId, + { + method: "GET", + headers: { + Authorization: "bearer " + accessToken, + }, + } + ); + const assignedUsers = await data.json(); + if (!assignedUsers.message) { + // this.setState({ assignedUsers }) + dispatch(setAssignedUsers(assignedUsers)); + dispatch(setIsFetching(false)); + } else { + dispatch(setIsFetching(false)); + swal({ + title: "Assigned Users", + text: assignedUsers.message, + icon: "error", + }); + } + } catch (e) { + dispatch(setIsFetching(false)); + swal({ + title: "Assigned Users", + text: + "Unable to fetch assigned users, check your internet connection or contact admin" + + e, + icon: "error", + }); + } }; export const assignUserToProject = (apiData, close) => async (dispatch) => { - dispatch(setIsFetching(true)); - try { - const data = await fetch(apiUrl + "v1/autographamt/projects/assignments", { - method: "POST", - body: JSON.stringify(apiData), - }); - const myJson = await data.json(); - // dispatch(setIsFetching(false)) - if (myJson.success) { - dispatch(getAssignedUsers(apiData.projectId)); - close(); - } - swal({ - title: "User assignment", - text: myJson.message, - icon: myJson.success ? "success" : "error", - }); - } catch (ex) { - swal({ - title: "User assignment", - text: - "Unable to update user to project, check your internet connection or contact admin admin " + - ex, - icon: "error", - }); - } - dispatch(setIsFetching(false)); + dispatch(setIsFetching(true)); + try { + const data = await fetch( + apiUrl + "v1/autographamt/projects/assignments", + { + method: "POST", + body: JSON.stringify(apiData), + } + ); + const myJson = await data.json(); + // dispatch(setIsFetching(false)) + if (myJson.success) { + dispatch(getAssignedUsers(apiData.projectId)); + close(); + } + swal({ + title: "User assignment", + text: "Books assignment updated", + icon: myJson.success ? "success" : "error", + }); + } catch (ex) { + swal({ + title: "User assignment", + text: + "Unable to update user to project, check your internet connection or contact admin admin " + + ex, + icon: "error", + }); + } + dispatch(setIsFetching(false)); }; export const deleteUser = (apiData) => async (dispatch) => { - dispatch(setIsFetching(true)); - try { - const data = await fetch(apiUrl + "v1/autographamt/projects/assignments", { - method: "DELETE", - body: JSON.stringify(apiData), - }); - const response = await data.json(); - dispatch(setIsFetching(false)); - if (response.success) { - swal({ - title: "Remove user", - text: "User successfully removed from project", - icon: "success", - }); - dispatch(getAssignedUsers(apiData.projectId)); - } else { - swal({ - title: "Remove user", - text: response.message, - icon: "error", - }); - } - } catch (e) { - swal({ - title: "User assignment", - text: "Unable to remove user from project, check your internet connection or contact admin", - icon: "error", - }); - } + dispatch(setIsFetching(true)); + try { + const data = await fetch( + apiUrl + "v1/autographamt/projects/assignments", + { + method: "DELETE", + body: JSON.stringify(apiData), + } + ); + const response = await data.json(); + dispatch(setIsFetching(false)); + if (response.success) { + swal({ + title: "Remove user", + text: "User successfully removed from project", + icon: "success", + }); + dispatch(getAssignedUsers(apiData.projectId)); + } else { + swal({ + title: "Remove user", + text: response.message, + icon: "error", + }); + } + } catch (e) { + swal({ + title: "User assignment", + text: "Unable to remove user from project, check your internet connection or contact admin", + icon: "error", + }); + } }; export const deleteUserAccess = (apiData) => async (dispatch) => { - dispatch(setIsFetching(true)); - try { - const data = await fetch(apiUrl + "v1/autographamt/user/delete", { - method: "DELETE", - headers: { - Authorization: "bearer " + accessToken, - }, - body: JSON.stringify(apiData), - }); - const response = await data.json(); - dispatch(setIsFetching(false)); - if (response.success) { - swal({ - title: "Removed user", - text: "User successfully removed", - icon: "success", - }); - dispatch(fetchUsers()); - } else { - swal({ - title: "User cannot be removed", - text: response.message, - icon: "error", - }); - } - } catch (e) { - swal({ - title: "User assignment", - text: "Unable to remove user, check your internet connection or contact admin", - icon: "error", - }); - } + dispatch(setIsFetching(true)); + try { + const data = await fetch(apiUrl + "v1/autographamt/user/delete", { + method: "DELETE", + headers: { + Authorization: "bearer " + accessToken, + }, + body: JSON.stringify(apiData), + }); + const response = await data.json(); + dispatch(setIsFetching(false)); + if (response.success) { + swal({ + title: "Removed user", + text: "User successfully removed", + icon: "success", + }); + dispatch(fetchUsers()); + } else { + swal({ + title: "User cannot be removed", + text: response.message, + icon: "error", + }); + } + } catch (e) { + swal({ + title: "User assignment", + text: "Unable to remove user, check your internet connection or contact admin", + icon: "error", + }); + } }; export const getUserBooks = (userId, projectId) => async (dispatch) => { - try { - dispatch(setIsFetching(true)); - const data = await fetch( - apiUrl + "v1/sources/projects/books/" + projectId + "/" + userId, - { - method: "GET", - headers: { - Authorization: "bearer " + accessToken, - }, - } - ); - const response = await data.json(); - dispatch(setIsFetching(false)); - if ("success" in response) { - swal({ - title: "Fetch books", - text: response.message, - icon: "error", - }); - } else { - dispatch(setUserBooks(response)); - // swal({ - // title: 'Fetch books', - // text: 'Books fetched successfully', - // icon: 'success' - // }); - } - } catch (ex) { - dispatch(setIsFetching(false)); - swal({ - title: "Fetch books", - text: "Unable to fetch books of users, check your internet connection or contact admin", - icon: "error", - }); - } + try { + dispatch(setIsFetching(true)); + const data = await fetch( + apiUrl + "v1/sources/projects/books/" + projectId + "/" + userId, + { + method: "GET", + headers: { + Authorization: "bearer " + accessToken, + }, + } + ); + const response = await data.json(); + dispatch(setIsFetching(false)); + if ("success" in response) { + swal({ + title: "Fetch books", + text: response.message, + icon: "error", + }); + } else { + dispatch(setUserBooks(response)); + // swal({ + // title: 'Fetch books', + // text: 'Books fetched successfully', + // icon: 'success' + // }); + } + } catch (ex) { + dispatch(setIsFetching(false)); + swal({ + title: "Fetch books", + text: "Unable to fetch books of users, check your internet connection or contact admin", + icon: "error", + }); + } }; export const setUsers = (users) => ({ - type: SET_USERS, - users, + type: SET_USERS, + users, }); export const setAssignedUsers = (users) => ({ - type: SET_ASSIGNED_USERS, - users, + type: SET_ASSIGNED_USERS, + users, }); export const setUserBooks = (books) => ({ - type: SET_USER_BOOKS, - books, + type: SET_USER_BOOKS, + books, }); export const setIsFetching = (status) => ({ - type: SET_IS_FETCHING, - status, + type: SET_IS_FETCHING, + status, }); From b76da2453132e077ba4b5e6c2d9c024596b36e5b Mon Sep 17 00:00:00 2001 From: Bobby Date: Fri, 27 Aug 2021 15:03:09 +0530 Subject: [PATCH 2/3] removed console --- src/components/Assignments/AssignUser.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/Assignments/AssignUser.js b/src/components/Assignments/AssignUser.js index bf1ae04..392017a 100755 --- a/src/components/Assignments/AssignUser.js +++ b/src/components/Assignments/AssignUser.js @@ -320,18 +320,14 @@ class AssignUser extends Component { const { userId, availableBooksData } = this.state; const { dispatch, location, assignedUsers } = this.props; const projectId = location.pathname.split("/").pop(); - console.log(assignedUsers, "users"); let assignedUsersBooks = []; for (var i in assignedUsers) { //Listing the books of users if (assignedUsers[i].user.userId === this.state.userId) { - console.log(assignedUsers[i], "state", this.state.userId); - //Checking if not current user then push the books assignedUsersBooks = assignedUsers[i].books; } } - console.log(assignedUsersBooks, "assigned books"); const checkedBooks = Object.keys(availableBooksData).filter( (book) => availableBooksData[book]["assigned"] === true ); From 7653ee2e46e92a224ec9c47bb20e60e1f245ddec Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 30 Aug 2021 14:10:26 +0530 Subject: [PATCH 3/3] added upload book error count --- src/components/UploadTexts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/UploadTexts.js b/src/components/UploadTexts.js index 713fdf5..3cc8463 100755 --- a/src/components/UploadTexts.js +++ b/src/components/UploadTexts.js @@ -49,7 +49,9 @@ class UploadTexts extends Component { if (uploadErrorBooks.length > 0) { swal({ title: "Upload Bible", - text: `Some books failed to upload :-\n${uploadErrorBooks.join( + text: `${ + uploadErrorBooks.length + } book(s) failed to upload :-\n${uploadErrorBooks.join( ", " )}`, icon: "warning",