From 8b175365b81ee08fe0e51e30073faca78ee23ad9 Mon Sep 17 00:00:00 2001
From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com>
Date: Sat, 18 May 2024 19:58:17 +0530
Subject: [PATCH] Adding/Deactivating ORGS working
---
frontend/src/App.js | 14 ++
.../OrganizationManagament/AddOrganization.js | 133 +++++++++++-----
.../ModifyOrganization.js | 149 ++++++++++++++----
.../OrganizationManagament.js | 57 +++++--
frontend/src/languages/en.json | 1 +
frontend/src/languages/fr.json | 1 +
.../rest/OrganizationRestController.java | 45 +++---
7 files changed, 288 insertions(+), 112 deletions(-)
diff --git a/frontend/src/App.js b/frontend/src/App.js
index e91fbfd937..58b24eb2e7 100644
--- a/frontend/src/App.js
+++ b/frontend/src/App.js
@@ -40,6 +40,8 @@ import PrintBarcode from "./components/printBarcode/Index";
import NonConformIndex from "./components/nonconform/index";
import SampleBatchEntrySetup from "./components/batchOrderEntry/SampleBatchEntrySetup.js";
import AuditTrailReportIndex from "./components/reports/auditTrailReport/Index.js";
+import AddOrganization from "./components/admin/OrganizationManagament/AddOrganization.js";
+import ModifyOrganization from "./components/admin/OrganizationManagament/ModifyOrganization.js";
export default function App() {
let i18nConfig = {
@@ -226,6 +228,18 @@ export default function App() {
component={() => }
role="Global Administrator"
/>
+ }
+ role="Global Administrator"
+ />
+ }
+ role="Global Administrator"
+ />
{
- setPage(page);
- setPageSize(pageSize);
- setSelectedRowIds([]);
- };
+ // const handlePageChange = ({ page, pageSize }) => {
+ // setPage(page);
+ // setPageSize(pageSize);
+ // setSelectedRowIds([]);
+ // };
+
+ function handleOrgNameChange(e) {
+ setSaveButton(false);
+ setNewOrganizationsData((alreadyOrgInfoToPost) => ({
+ ...alreadyOrgInfoToPost,
+ organizationName: e.target.value,
+ }));
+ }
+
+ function handleOrgPrefixChange(e) {
+ setSaveButton(false);
+ setNewOrganizationsData((alreadyOrgInfoToPost) => ({
+ ...alreadyOrgInfoToPost,
+ shortName: e.target.value,
+ }));
+ }
+
+ function handleIsActiveChange(e) {
+ setSaveButton(false);
+ setNewOrganizationsData((alreadyOrgInfoToPost) => ({
+ ...alreadyOrgInfoToPost,
+ isActive: e.target.value,
+ }));
+ }
+
+ function handleInternetAddressChange(e) {
+ setSaveButton(false);
+ setNewOrganizationsData((alreadyOrgInfoToPost) => ({
+ ...alreadyOrgInfoToPost,
+ internetAddress: e.target.value,
+ }));
+ }
+
+ useEffect(() => {
+ setNewOrganizationsData((alreadyOrgInfoToPost) => ({
+ ...alreadyOrgInfoToPost,
+ selectedTypes: selectedRowIds,
+ }));
+ }, [selectedRowIds, typeOfActivity, typeOfActivityShow]);
useEffect(() => {
if (typeOfActivity) {
@@ -75,6 +115,15 @@ function AddOrganization() {
newOrganizationsManagementList,
);
setTypeOfActivityShow(newOrganizationsManagementListArray);
+
+ const newOrganizationsManagementDataPost = {
+ id: typeOfActivity.id,
+ organizationName: typeOfActivity.organizationName || "",
+ shortName: typeOfActivity.shortName || "",
+ isActive: typeOfActivity.isActive || "",
+ internetAddress: typeOfActivity.internetAddress || "",
+ };
+ setNewOrganizationsData(newOrganizationsManagementDataPost);
}
}, [typeOfActivity]);
@@ -102,26 +151,30 @@ function AddOrganization() {
function newOrganizationsSavePost(event) {
event.preventDefault();
setLoading(true);
- postToOpenElisServerFullResponse(
+ postToOpenElisServerJsonResponse(
`/rest/Organization?ID=0&startingRecNo=1`,
- newOrganizationsData, // need to check against the form of restController [mentor]
- setLoading(false),
- addNotification({
- title: intl.formatMessage({
- id: "notification.title",
- }),
- message: intl.formatMessage({
- id: "notification.organization.post.save.success",
- }),
- kind: NotificationKinds.success,
- }),
- setNotificationVisible(true),
- setTimeout(() => {
- window.location.reload();
- }, 2000),
+ JSON.stringify(newOrganizationsData),
+ newOrganizationsSavePostCallback(),
);
}
+ function newOrganizationsSavePostCallback() {
+ setLoading(false);
+ setNotificationVisible(true);
+ addNotification({
+ title: intl.formatMessage({
+ id: "notification.title",
+ }),
+ message: intl.formatMessage({
+ id: "notification.organization.post.save.success",
+ }),
+ kind: NotificationKinds.success,
+ });
+ // setTimeout(() => {
+ // window.location.reload();
+ // }, 2000);
+ }
+
const renderCell = (cell, row) => {
if (cell.info.header === "select") {
return (
@@ -196,10 +249,7 @@ function AddOrganization() {
id: "organization.add.placeholder",
})}
required
- // invalid={errors.order && touched.order}
- // invalidText={errors.order}
- // value={values.numDefaultOrderLabels}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleOrgNameChange(e)}
/>
@@ -218,10 +268,7 @@ function AddOrganization() {
placeholder={intl.formatMessage({
id: "organization.add.placeholder",
})}
- // invalid={errors.order && touched.order}
- // invalidText={errors.order}
- // value={values.numDefaultOrderLabels}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleOrgPrefixChange(e)}
/>
@@ -242,10 +289,7 @@ function AddOrganization() {
id: "organization.add.placeholder.active",
})}
required
- // invalid={errors.order && touched.order}
- // invalidText={errors.order}
- // value={values.numDefaultOrderLabels}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleIsActiveChange(e)}
/>
@@ -265,10 +309,7 @@ function AddOrganization() {
placeholder={intl.formatMessage({
id: "organization.add.placeholder",
})}
- // invalid={errors.order && touched.order}
- // invalidText={errors.order}
- // value={values.numDefaultOrderLabels}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleInternetAddressChange(e)}
/>
@@ -295,6 +336,7 @@ function AddOrganization() {
+
)}
-
+ /> */}
+
@@ -493,12 +536,16 @@ function AddOrganization() {
>
sdf
+
>
);
}
export default injectIntl(AddOrganization);
-
-// post request need to fix
-// save button fix needed
diff --git a/frontend/src/components/admin/OrganizationManagament/ModifyOrganization.js b/frontend/src/components/admin/OrganizationManagament/ModifyOrganization.js
index af1601cd68..e132fdeb33 100644
--- a/frontend/src/components/admin/OrganizationManagament/ModifyOrganization.js
+++ b/frontend/src/components/admin/OrganizationManagament/ModifyOrganization.js
@@ -24,7 +24,7 @@ import {
} from "@carbon/react";
import {
getFromOpenElisServer,
- postToOpenElisServerFullResponse,
+ postToOpenElisServerJsonResponse,
} from "../../utils/Utils.js";
import { NotificationContext } from "../../layout/Layout.js";
import {
@@ -48,13 +48,13 @@ function ModifyOrganization() {
const intl = useIntl();
const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);
- const [pageSize, setPageSize] = useState(5);
+ const [pageSize, setPageSize] = useState(20);
const [selectedRowIds, setSelectedRowIds] = useState([]);
const [orgSelectedTypeOfActivity, setOrgSelectedTypeOfActivity] = useState(
[],
);
const [orgInfo, setOrgInfo] = useState(null);
- const [orgInfoPost, setOrgInfoPost] = useState(null); // post data need to get checked
+ const [orgInfoPost, setOrgInfoPost] = useState(null);
const [saveButton, setSaveButton] = useState(true);
const [typeOfActivity, setTypeOfActivity] = useState(null);
const [typeOfActivityShow, setTypeOfActivityShow] = useState([]);
@@ -73,34 +73,93 @@ function ModifyOrganization() {
);
}
- const handlePageChange = ({ page, pageSize }) => {
- setPage(page);
- setPageSize(pageSize);
- setSelectedRowIds([]);
- };
+ // const handlePageChange = ({ page, pageSize }) => {
+ // setPage(page);
+ // setPageSize(pageSize);
+ // setSelectedRowIds([]);
+ // };
+
+ function handleOrgNameChange(e) {
+ setSaveButton(false);
+ setOrgInfoPost((prevOrgInfoPost) => ({
+ ...prevOrgInfoPost,
+ organizationName: e.target.value,
+ }));
+ setOrgInfo((prevOrgInfo) => ({
+ ...prevOrgInfo,
+ organizationName: e.target.value,
+ }));
+ }
+
+ function handleOrgPrefixChange(e) {
+ setSaveButton(false);
+ setOrgInfoPost((prevOrgInfoPost) => ({
+ ...prevOrgInfoPost,
+ shortName: e.target.value,
+ }));
+ setOrgInfo((prevOrgInfo) => ({
+ ...prevOrgInfo,
+ shortName: e.target.value,
+ }));
+ }
+
+ function handleIsActiveChange(e) {
+ setSaveButton(false);
+ setOrgInfoPost((prevOrgInfoPost) => ({
+ ...prevOrgInfoPost,
+ isActive: e.target.value,
+ }));
+ setOrgInfo((prevOrgInfo) => ({
+ ...prevOrgInfo,
+ isActive: e.target.value,
+ }));
+ }
+
+ function handleInternetAddressChange(e) {
+ setSaveButton(false);
+ setOrgInfoPost((prevOrgInfoPost) => ({
+ ...prevOrgInfoPost,
+ internetAddress: e.target.value,
+ }));
+ setOrgInfo((prevOrgInfo) => ({
+ ...prevOrgInfo,
+ internetAddress: e.target.value,
+ }));
+ }
function submitUpdatedOrgInfo() {
setLoading(true);
- postToOpenElisServerFullResponse(
+ postToOpenElisServerJsonResponse(
`/rest/Organization?ID=${id}&startingRecNo=1`,
- orgInfoPost,
- setLoading(false),
- addNotification({
- title: intl.formatMessage({
- id: "notification.title",
- }),
- message: intl.formatMessage({
- id: "notification.organization.post.success",
- }),
- kind: NotificationKinds.success,
- }),
- setNotificationVisible(true),
- setTimeout(() => {
- window.location.reload();
- }, 1000),
+ JSON.stringify(orgInfoPost),
+ submitUpdatedOrgInfoCallback(),
);
}
+ function submitUpdatedOrgInfoCallback() {
+ setLoading(false);
+ setNotificationVisible(true);
+ addNotification({
+ title: intl.formatMessage({
+ id: "notification.title",
+ }),
+ message: intl.formatMessage({
+ id: "notification.organization.post.success",
+ }),
+ kind: NotificationKinds.success,
+ });
+ // setTimeout(() => {
+ // window.location.reload();
+ // }, 2000);
+ }
+
+ useEffect(() => {
+ setOrgInfoPost((prevOrgInfoPost) => ({
+ ...prevOrgInfoPost,
+ selectedTypes: selectedRowIds,
+ }));
+ }, [selectedRowIds, orgSelectedTypeOfActivity, orgInfo]);
+
useEffect(() => {
if (typeOfActivity) {
const newOrganizationsManagementList = typeOfActivity.orgTypes.map(
@@ -123,8 +182,19 @@ function ModifyOrganization() {
shortName: typeOfActivity.shortName || "",
isActive: typeOfActivity.isActive || "",
internetAddress: typeOfActivity.internetAddress || "",
+ selectedTypes: typeOfActivity.selectedTypes || [],
+ };
+
+ const organizationsManagementIdInfoPost = {
+ id: typeOfActivity.id,
+ organizationName: typeOfActivity.organizationName || "",
+ shortName: typeOfActivity.shortName || "",
+ isActive: typeOfActivity.isActive || "",
+ internetAddress: typeOfActivity.internetAddress || "",
};
setOrgInfo(organizationsManagementIdInfo);
+ setOrgInfoPost(organizationsManagementIdInfoPost);
+ setSelectedRowIds(typeOfActivity.selectedTypes);
const organizationSelectedTypeOfActivity =
typeOfActivity.selectedTypes.map((item) => {
@@ -238,7 +308,7 @@ function ModifyOrganization() {
// invalid={errors.order && touched.order}
// invalidText={errors.order}
value={orgInfo.organizationName}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleOrgNameChange(e)}
/>
)}
@@ -262,7 +332,7 @@ function ModifyOrganization() {
// invalid={errors.order && touched.order}
// invalidText={errors.order}
value={orgInfo.shortName}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleOrgPrefixChange(e)}
/>
)}
@@ -288,7 +358,7 @@ function ModifyOrganization() {
// invalid={errors.order && touched.order}
// invalidText={errors.order}
value={orgInfo.isActive}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleIsActiveChange(e)}
/>
)}
@@ -312,7 +382,7 @@ function ModifyOrganization() {
// invalid={errors.order && touched.order}
// invalidText={errors.order}
value={orgInfo.internetAddress}
- // onChange={(e) => handleDefaultOrderLablesValue(e)}
+ onChange={(e) => handleInternetAddressChange(e)}
/>
)}
@@ -340,6 +410,7 @@ function ModifyOrganization() {
+
)}
-
+ /> */}
+
-
+ {
+ console.error(selectedRowIdsPost);
+ }}
+ >
+ selectedRowIdsPost
+
>
);
diff --git a/frontend/src/languages/en.json b/frontend/src/languages/en.json
index bf9df5cfff..de2b8242f1 100644
--- a/frontend/src/languages/en.json
+++ b/frontend/src/languages/en.json
@@ -1030,6 +1030,7 @@
"organization.edit.title": "Edit Organization",
"notification.organization.post.success": "Organization Information Updated Succesfully.",
"notification.organization.post.save.success": "Organization Information Added Succesfully.",
+ "notification.organization.post.delete.success": "Organization Deactivated Succesfully.",
"organization.select": "Select",
"organization.type.CI": "Type of Activity",
"organization.type.CI.select": "Type of Activity : Select",
diff --git a/frontend/src/languages/fr.json b/frontend/src/languages/fr.json
index 2d24d018e4..163f9f5629 100644
--- a/frontend/src/languages/fr.json
+++ b/frontend/src/languages/fr.json
@@ -940,6 +940,7 @@
"organization.edit.title": "Modifier l'organisation",
"notification.organization.post.success": "Informations sur l'organisation mises à jour avec succès.",
"notification.organization.post.save.success": "Informations sur l'organisation ajoutées avec succès.",
+ "notification.organization.post.delete.success": "Organisation désactivée avec succès.",
"organization.select": "Sélectionner",
"organization.type.CI": "Type d'activité",
"organization.type.CI.select": "Type d'activité : Sélectionner",
diff --git a/src/main/java/org/openelisglobal/organization/controller/rest/OrganizationRestController.java b/src/main/java/org/openelisglobal/organization/controller/rest/OrganizationRestController.java
index 6b8b0b50b7..e9d89eb76f 100644
--- a/src/main/java/org/openelisglobal/organization/controller/rest/OrganizationRestController.java
+++ b/src/main/java/org/openelisglobal/organization/controller/rest/OrganizationRestController.java
@@ -49,7 +49,6 @@
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.support.SessionStatus;
@@ -58,7 +57,6 @@
@RestController
@RequestMapping("/rest")
-@SessionAttributes("form")
public class OrganizationRestController extends BaseController {
private static final String[] ALLOWED_FIELDS = new String[] { "id", "parentOrgName",
@@ -77,10 +75,10 @@ public class OrganizationRestController extends BaseController {
@Autowired
private DictionaryService dictionaryService;
- @ModelAttribute("form")
- public OrganizationForm form() {
- return new OrganizationForm();
- }
+ // @ModelAttribute("form")
+ // public OrganizationForm form() {
+ // return new OrganizationForm();
+ // }
// private static boolean useZip =
// FormFields.getInstance().useField(FormFields.Field.ZipCode);
@@ -137,9 +135,11 @@ public void initBinder(WebDataBinder binder) {
}
@GetMapping(value = { "/Organization", "/NextPreviousOrganization" })
- public ResponseEntity