From 80828f9a222071045bc1cfd93071966f251e7c7f Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Sat, 17 Oct 2020 21:02:01 +0530 Subject: [PATCH 1/9] Modified view-agency component & css for updated interface --- .../view-agency/view-agency.component.js | 235 ++++++++++++------ .../agencies/view-agency/view-agency.css | 23 ++ src/helpers/i18n/en/translation.json | 1 + 3 files changed, 184 insertions(+), 75 deletions(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index 6abf4100..6bf45f21 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -1,16 +1,25 @@ import React, { Component, Fragment } from "react"; import { NavLink } from "react-router-dom"; import { withTranslation } from "react-i18next"; +import SearchIcon from "@material-ui/icons/Search"; +import Pagination from "@material-ui/lab/Pagination"; -import { EDIT_AGENCIES_PAGE } from "./../../../root/root.constants"; +import { EDIT_AGENCIES_PAGE, NEW_USER_PAGE,EDIT_USER_PAGE } from "./../../../root/root.constants"; + +import { checkUserType,goToPage } from "../../../helpers/get-data"; import AgencyService from "./../../../services/agency.service"; +import AuthService from "../../../services/auth.service"; + import AgencyFormData from "../form-data/form-data.js" import AgencyDataSharing from "../data-sharing/data-sharing.js" +import UserPhoto from "../../partials/user-photo/user-photo.component"; +import Highlighter from "react-highlight-words"; import "./view-agency.css"; const agencyService = AgencyService.getInstance(); +const authService = AuthService.getInstance(); class ViewAgency extends Component { state = { @@ -29,6 +38,11 @@ class ViewAgency extends Component { }); }; + goEditUser = (id) => { + //TODO: Use router! + goToPage(EDIT_USER_PAGE, id); + }; + componentDidMount() { const { id } = this.props.match.params; @@ -36,6 +50,7 @@ class ViewAgency extends Component { agencyService .getAgency(id) .then((data) => { + const agencyInfo = { ...data, ...this.state.agencyInfo }; this.setState({ @@ -50,8 +65,13 @@ class ViewAgency extends Component { } render() { - const { agencyInfo, activeTab, loading } = this.state; + const { agencyInfo, activeTab, loading, isFocused, total, limit, page } = this.state; + const { t } = this.props; + const isGlobalAdmin = authService.user.global.admin; + const isAgencyAdmin = authService.user.agency.admin; + const isFieldOfficer = + !authService.user.global.admin && !authService.user.agency.admin; return (
@@ -60,32 +80,32 @@ class ViewAgency extends Component { {loading ? ( t("LOADING.LOADING") ) : ( - -
{t("TABLE.AGENCY")}
-
{agencyInfo.agency}
-
{agencyInfo.description}
-
-
- no logo + +
{t("TABLE.AGENCY")}
+
{agencyInfo.agency}
+
{agencyInfo.description}
+
+
+ no logo +
+ {agencyInfo.site}
- {agencyInfo.site} -
-
-
- no logo +
+
+ no logo +
+ {agencyInfo.email}
- {agencyInfo.email} -
- - )} + + )}
@@ -94,25 +114,22 @@ class ViewAgency extends Component {
this.handleChangeTab(1)} > {t("TABLE.OFFICERS")}
this.handleChangeTab(2)} > {t("AGENCY_PAGE.FORM_DATA")}
this.handleChangeTab(3)} > {t("AGENCY_PAGE.DATA_SHARING")} @@ -121,54 +138,122 @@ class ViewAgency extends Component {
{1 === activeTab && (
- - - - - - - - {agencyInfo.officers - ? agencyInfo.officers.map((officer, ind) => ( - - + + + {isFieldOfficer && !isGlobalAdmin && ( + + )} + + {isAgencyAdmin && ( + + )} + ) + })} + +
-
-
- {`${t("TABLE.OFFICERS")} (${ - agencyInfo.officers.length - })`} -
- -
-
-
-
- no logo + +
+ {`${agencyInfo.officers.length} ${t("TABLE.OFFICERS")}`} +
+ +
+
+
+ +
+ this.setState({ isFocused: true })} + > +
+ +
+ +
+ + + + +
+
+ {agencyInfo.officers ? ( +
+
+ + + + + + + + + + + {agencyInfo.officers.map((officer, ind) => { + const status = officer.active ? "active" : "inactive"; + return ( + + - - )) - : t("WARNINGS.NO_OFFICERS")} - -
{t("TABLE.NAME")} {t("CREATE_USER_PAGE.USER_GROUP")}{t("CREATE_USER_PAGE.ROLE")}{t("TABLE.STATUS")}
+
+
- {officer.name} - -
+
+ {isGlobalAdmin + ? officer.group + ? officer.group.name + : officer.userGroup + ? officer.userGroup.name + : "N/A" + : officer.userGroup} + {checkUserType(officer)}{officer.email} +
+ {status} +
+
+
this.goEditUser(officer._id)} + > + {t("BUTTONS.EDIT")} +
+
+
+ { total > limit && ( + + )} +
+ ) : t("WARNINGS.NO_OFFICERS")}
)} - { 2 === activeTab && ( + {2 === activeTab && (
- +
)} - { 3 === activeTab && ( + {3 === activeTab && (
- +
)}
diff --git a/src/components/agencies/view-agency/view-agency.css b/src/components/agencies/view-agency/view-agency.css index 069a4770..23ce79a0 100644 --- a/src/components/agencies/view-agency/view-agency.css +++ b/src/components/agencies/view-agency/view-agency.css @@ -41,3 +41,26 @@ height: 50px; margin-right: 10px; } + +.officer-search-panel { + width: 450px; + background: inherit; + border:1px solid #ececec; + border-radius: 5px; +} + +.officer-search-panel .search-icon { + margin:auto 5px; + } + +.officer-search-panel-input { + outline: none; + border: none; + margin:8px auto; + flex-grow: 1; +} + +.officer-table-border-width { + border-width: 3px; +} + diff --git a/src/helpers/i18n/en/translation.json b/src/helpers/i18n/en/translation.json index e29ffb39..83f8cad4 100644 --- a/src/helpers/i18n/en/translation.json +++ b/src/helpers/i18n/en/translation.json @@ -164,6 +164,7 @@ "CREATE_REPORT": "Create Activity Report", "CREATE_USER": "Create User", "UPDATE_USER": "Update User", + "ADD_NEW_USER": "Add New User", "MANAGE_SHARED_DATA": "Manage Shared Data" }, "TABLE": { From 79ff6aebd91de4d259c12b20ee578dc0c4be2c0f Mon Sep 17 00:00:00 2001 From: Sheeri Date: Mon, 19 Oct 2020 22:00:56 -0400 Subject: [PATCH 2/9] Update view-agency.component.js --- src/components/agencies/view-agency/view-agency.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index b5043373..2806e020 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -79,7 +79,7 @@ class ViewAgency extends Component { {loading ? ( t("LOADING.LOADING") ) : ( -] +
{t("TABLE.AGENCY")}
{agencyInfo.agency}
{agencyInfo.description}
From 0bb22f8fb54156cd2bbbe72034a101e0562fbae5 Mon Sep 17 00:00:00 2001 From: Sheeri Cabral Date: Mon, 19 Oct 2020 22:02:00 -0400 Subject: [PATCH 3/9] Update view-agency.component.js getting rid of errant ] --- src/components/agencies/view-agency/view-agency.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index b5043373..2806e020 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -79,7 +79,7 @@ class ViewAgency extends Component { {loading ? ( t("LOADING.LOADING") ) : ( -] +
{t("TABLE.AGENCY")}
{agencyInfo.agency}
{agencyInfo.description}
From 744564884162b88f0507d49a64a69479d13e2e93 Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Thu, 22 Oct 2020 23:10:53 +0530 Subject: [PATCH 4/9] Changed agencyinfo reference to agency --- src/components/agencies/view-agency/view-agency.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index 994dd627..f1346489 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -254,7 +254,7 @@ class ViewAgency extends Component { )} {2 === activeTab && (
- +
)} {3 === activeTab && ( From 06951b9005c6b4b168a841f8be62a8c750bc0b22 Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Fri, 23 Oct 2020 21:01:20 +0530 Subject: [PATCH 5/9] fixed parsing error in translation.json --- src/helpers/i18n/fr/translation.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/i18n/fr/translation.json b/src/helpers/i18n/fr/translation.json index 739119de..c12a92d0 100644 --- a/src/helpers/i18n/fr/translation.json +++ b/src/helpers/i18n/fr/translation.json @@ -193,7 +193,7 @@ "SHARE_DATA": "Partager des Données", "STOP_SHARING": "Arrêter de Partager", "MANAGE_SHARED_DATA": "Gérer des Données Partagées", - "CHOOSE_DATA": "Choisir des Données" + "CHOOSE_DATA": "Choisir des Données", "SEE_SHARED_DATA": "SEE SHARED DATA" }, "TABLE": { From 3caea1145c23bec2f278640ebc9c66630b3ea37b Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Sun, 25 Oct 2020 11:52:14 +0530 Subject: [PATCH 6/9] Modified logic to populate officers --- .../view-agency/view-agency.component.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index f1346489..4d2e726e 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -10,6 +10,7 @@ import { checkUserType,goToPage } from "../../../helpers/get-data"; import AgencyService from "./../../../services/agency.service"; import AuthService from "../../../services/auth.service"; +import BoardingService from "../../../services/boarding.service"; import AgencyFormData from "../form-data/form-data.js" import AgencyDataSharing from "../data-sharing/data-sharing.js"; @@ -20,6 +21,7 @@ import "./view-agency.css"; const agencyService = AgencyService.getInstance(); const authService = AuthService.getInstance(); +const boardingService = BoardingService.getInstance(); class ViewAgency extends Component { state = { @@ -46,14 +48,29 @@ class ViewAgency extends Component { componentDidMount() { const { id } = this.props.match.params; - this.setState({ loading: true }, () => { agencyService .getAgency(id) .then((data) => { this.setState({ agency: data, - loading: false, + }); + + boardingService.getBoardingsWithFacet(50,0,null,{"agency":data.name}).then((userData)=>{ + const officers = userData.boardings.reduce((res,item)=>{ + if(!res.email.includes(item.reportingOfficer.email)){ + res.email.push(item.reportingOfficer.email); + res.officers.push(item.reportingOfficer); + } + return res; + },{email:[],officers:[]}).officers; + + this.setState({ + agencyAdditionalInfo:{"officers": officers}, + loading: false, + }); + }).catch((error) => { + console.error(error); }); }) .catch((error) => { @@ -64,7 +81,6 @@ class ViewAgency extends Component { render() { const { agencyAdditionalInfo, agency, activeTab, loading, isFocused, total, limit, page } = this.state; - const { t } = this.props; const isGlobalAdmin = authService.user.global.admin; const isAgencyAdmin = authService.user.agency.admin; @@ -190,7 +206,7 @@ class ViewAgency extends Component { - {agencyAdditionalInfo.officers.map((officer, ind) => { + { agencyAdditionalInfo.officers.map((officer, ind) => { const status = officer.active ? "active" : "inactive"; return ( @@ -216,7 +232,7 @@ class ViewAgency extends Component { : "N/A" : officer.userGroup} - {checkUserType(officer)} + {(officer.global || officer.agency) ? checkUserType(officer) : "N/A"} {isFieldOfficer && !isGlobalAdmin && ( {officer.email} )} @@ -225,7 +241,7 @@ class ViewAgency extends Component { {status}
- {isAgencyAdmin && ( + {isAgencyAdmin && officer._id && (
Date: Tue, 27 Oct 2020 10:05:24 +0530 Subject: [PATCH 7/9] Populating officers using getusers method --- .../view-agency/view-agency.component.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/components/agencies/view-agency/view-agency.component.js b/src/components/agencies/view-agency/view-agency.component.js index 4d2e726e..65ca55dc 100644 --- a/src/components/agencies/view-agency/view-agency.component.js +++ b/src/components/agencies/view-agency/view-agency.component.js @@ -10,7 +10,7 @@ import { checkUserType,goToPage } from "../../../helpers/get-data"; import AgencyService from "./../../../services/agency.service"; import AuthService from "../../../services/auth.service"; -import BoardingService from "../../../services/boarding.service"; +import UserService from "../../../services/user.service"; import AgencyFormData from "../form-data/form-data.js" import AgencyDataSharing from "../data-sharing/data-sharing.js"; @@ -21,7 +21,7 @@ import "./view-agency.css"; const agencyService = AgencyService.getInstance(); const authService = AuthService.getInstance(); -const boardingService = BoardingService.getInstance(); +const userService = UserService.getInstance(); class ViewAgency extends Component { state = { @@ -42,7 +42,6 @@ class ViewAgency extends Component { }; goEditUser = (id) => { - //TODO: Use router! goToPage(EDIT_USER_PAGE, id); }; @@ -56,22 +55,13 @@ class ViewAgency extends Component { agency: data, }); - boardingService.getBoardingsWithFacet(50,0,null,{"agency":data.name}).then((userData)=>{ - const officers = userData.boardings.reduce((res,item)=>{ - if(!res.email.includes(item.reportingOfficer.email)){ - res.email.push(item.reportingOfficer.email); - res.officers.push(item.reportingOfficer); - } - return res; - },{email:[],officers:[]}).officers; - + userService.getUsers(50,0,null).then((userData)=>{ this.setState({ - agencyAdditionalInfo:{"officers": officers}, + agencyAdditionalInfo:{"officers": userData.users}, loading: false, - }); - }).catch((error) => { - console.error(error); + }); }); + }) .catch((error) => { console.error(error); From 40557234b0424e48aede25676fe4f2fab25d933f Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Tue, 27 Oct 2020 10:44:45 +0530 Subject: [PATCH 8/9] Removed unused var from reset password --- src/components/restore-password/reset-password.component.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/restore-password/reset-password.component.js b/src/components/restore-password/reset-password.component.js index df42327a..24c399b0 100644 --- a/src/components/restore-password/reset-password.component.js +++ b/src/components/restore-password/reset-password.component.js @@ -56,7 +56,6 @@ class ResetPassword extends Component { render() { const { error, loading } = this.state; - const { t } = this.props; return (
From dc172e228a7d1cdf75a477415cb32ee57cf40c99 Mon Sep 17 00:00:00 2001 From: deveshchatuphale7 Date: Tue, 27 Oct 2020 10:56:17 +0530 Subject: [PATCH 9/9] Removed unused var from reset password --- src/components/restore-password/restore-password.component.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/restore-password/restore-password.component.js b/src/components/restore-password/restore-password.component.js index 3a0ee930..3ff33ed5 100644 --- a/src/components/restore-password/restore-password.component.js +++ b/src/components/restore-password/restore-password.component.js @@ -37,8 +37,7 @@ class RestorePassword extends Component { render() { const { error, loading, success } = this.state; - const { t } = this.props; - + return (