- {/* View/Hide Change Log Btn*/}
+
+
+ {/* View/Hide Activity Log Btn*/}
- {/* Change Log Table */}
+ {/* Activity Log Table */}
{
- isViewChangeLog &&
-
-
-
-
- Date
- User
- Updates
-
-
-
-
- {
- changeLogData &&
- changeLogData.map(({updated_on, updated_by, updates}, i) => (
-
-
- {new Date(updated_on).toLocaleString()}
-
-
- {updated_by}
-
-
+ isViewActivityLog &&
+
+
+ {
+ activityLog &&
+ activityLog.map(({updated_on, updated_by, updates}, i) => (
+ -
+
+ {updated_by[0].toUpperCase()}
+
+
+
+ )}
+
+
+
{updated_by}made the following changes:
+ {
+ updates && updates.length > 0 &&
+ updates?.map(({old, new:_new, name}) => (
+
+ {"Changed "}
+
+ { (name !== "id" ||
+ name !== "created" ||
+ name !== "updated" ||
+ name !== "created_by" ||
+ name !== "updated_by") && name}
+
+ {/* { old } */}
+ to
+ { _new ?? '-'}
+
+ ))
+ }
+
+
+
+
+
+ ))
+
+ }
+
+
+
+
+
+
}
@@ -783,7 +845,7 @@ const Facility = (props) => {
};
Facility.getInitialProps = async (ctx) => {
- const allOptions = [];
+ const allOptions = {};
if (ctx.query.q) {
const query = ctx.query.q;
@@ -819,9 +881,7 @@ Facility.getInitialProps = async (ctx) => {
})
.then((r) => r.json())
.then(async (json) => {
- allOptions.push({
- data: json,
- })
+ allOptions["data"] = json
// fetch ward boundaries
@@ -842,10 +902,9 @@ Facility.getInitialProps = async (ctx) => {
const [lng, lat] =
_data?.ward_boundary.properties.center.coordinates;
- allOptions.push({
- geoLocation: JSON.parse(JSON.stringify(_data?.ward_boundary)),
- center: [lat, lng],
- });
+ allOptions["geoLocation"] = JSON.parse(JSON.stringify(_data?.ward_boundary));
+ allOptions["center"] = [lat, lng];
+
} catch (e) {
console.error("Error in fetching ward boundaries", e.message);
}
@@ -863,9 +922,8 @@ Facility.getInitialProps = async (ctx) => {
}
)).json()
- allOptions.push({
- updates: facilityUpdateData,
- })
+ allOptions["updates"]= facilityUpdateData
+
}
catch(e){
@@ -873,13 +931,27 @@ Facility.getInitialProps = async (ctx) => {
}
}
- allOptions.push({
- token
- });
+ if(json) {
+ try{
+ const resp = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/${json?.id}/?fields=__rev__&include_audit=true`, {
+ headers: {
+ 'Accept': 'application/json',
+ 'Authorization': `Bearer ${token}`
+ }
+ })
+
+ allOptions["activityLog"] = (await resp.json()).revisions
+
+ }
+ catch(e){
+ console.error('Error when fetching Activity Log', e.message)
+ }
+
+ }
+
+ allOptions["token"] = token
- allOptions.push({
- qf: ctx.query.qf
- });
+ allOptions["qf"] = ctx.query.qf
return allOptions;
})
diff --git a/pages/facilities/edit/[id].js b/pages/facilities/edit/[id].js
index 0286c193..b848fe8c 100644
--- a/pages/facilities/edit/[id].js
+++ b/pages/facilities/edit/[id].js
@@ -702,6 +702,7 @@ EditFacility.getInitialProps = async (ctx) => {
}
break;
case "facility_data":
+
try {
const _facility_data = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/${ctx.query.id}/`,
@@ -756,6 +757,8 @@ EditFacility.getInitialProps = async (ctx) => {
try {
+ console.log(facilityData?.id)
+
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/facilities/facility_regulation_status/?facility=${facilityData?.id}/?format=json`,
{
@@ -772,12 +775,12 @@ EditFacility.getInitialProps = async (ctx) => {
}
} catch (err) {
- console.log(`Error fetching ${option}: `, err);
+ console.log(`Error fetching facility_regulation_status ${option}: `, err);
}
} catch (err) {
- console.log(`Error fetching ${option}: `, err);
+ console.log(`Error fetching wards data ${option}: `, err);
}
}
diff --git a/pages/user/add.js b/pages/user/add.js
index f4f71a85..16317040 100644
--- a/pages/user/add.js
+++ b/pages/user/add.js
@@ -153,7 +153,7 @@ function User(props){
.then(res => {
router.push('/user/')
- alert.success('User deleted successfully')
+ alert.success('User Account Deactivated successfully')
})
} catch (error) {
diff --git a/pages/user/edit/[id].js b/pages/user/edit/[id].js
index fb651141..567f74ee 100644
--- a/pages/user/edit/[id].js
+++ b/pages/user/edit/[id].js
@@ -15,6 +15,7 @@ import { UserContext } from '../../../providers/user';
import { hasPermission } from '../../../utils/checkPermissions';
import Alert from '@mui/material/Alert';
import Link from 'next/link';
+import { WarningOutlined } from '@mui/icons-material';
const User = (props) => {
@@ -153,7 +154,7 @@ const User = (props) => {
.then(res => {
router.push('/user/')
- alert.success('User deleted successfully')
+ alert.success('User Account Deactivated successfully')
})
} catch (error) {
@@ -253,12 +254,16 @@ const User = (props) => {
p: 4,
}
}>
-
- Are you sure you want to delete{userData?.first_name + ' ' + userData?.last_name + ' ' + userData?.other_names} ?
-
+
+
+
+ Are you sure you want to deactivate{userData?.first_name + ' ' + userData?.last_name + ' ' + userData?.other_names} ?
+
+
+
-
-
+