From f274089c6a3a98453b47254de1f6257c2adaa87f Mon Sep 17 00:00:00 2001
From: Nadun Sanjeevana <108867149+NadunSanjeevana@users.noreply.github.com>
Date: Tue, 17 Oct 2023 12:19:16 +0530
Subject: [PATCH 01/39] manage user
---
src/api/ManageUser/users.js | 52 ++++++++
src/api/report/getReports.js | 46 +++++--
src/layouts/admin/manageuser/data/userData.js | 121 +++++++++---------
3 files changed, 147 insertions(+), 72 deletions(-)
create mode 100644 src/api/ManageUser/users.js
diff --git a/src/api/ManageUser/users.js b/src/api/ManageUser/users.js
new file mode 100644
index 0000000..7abc093
--- /dev/null
+++ b/src/api/ManageUser/users.js
@@ -0,0 +1,52 @@
+import axios from "axios";
+import baseURL from "config";
+
+// Function to delete a user
+export async function deleteUser(userId) {
+ try {
+ const response = await axios.post(`${baseURL}/delete-user`, { user_ID: userId });
+ if (response.status === 200) {
+ console.log(response.data.message); // Assuming the response has a message field
+ } else {
+ console.error("Failed to delete user:", response.statusText);
+ }
+ } catch (error) {
+ console.error("Error deleting user:", error);
+ throw error;
+ }
+}
+
+// Function to edit user details
+export async function editUser(userId, updatedData) {
+ try {
+ const response = await axios.post(`${baseURL}/updateUser`, {
+ userId: userId,
+ fullName: updatedData.fullName,
+ mobile: updatedData.contactNumber,
+ profession: updatedData.profession,
+ });
+ if (response.status === 200) {
+ console.log(response.data.message); // Assuming the response has a message field
+ } else {
+ console.error("Failed to edit user:", response.statusText);
+ }
+ } catch (error) {
+ console.error("Error editing user:", error);
+ throw error;
+ }
+}
+
+// Function to get the list of users
+export async function getUserList() {
+ try {
+ const response = await axios.get(`${baseURL}/getAllUsers`);
+ if (response.status === 200) {
+ return response.data;
+ } else {
+ console.error("Failed to fetch user list:", response.statusText);
+ }
+ } catch (error) {
+ console.error("Error fetching user list:", error);
+ throw error;
+ }
+}
diff --git a/src/api/report/getReports.js b/src/api/report/getReports.js
index 179dbc9..1bbb9b0 100644
--- a/src/api/report/getReports.js
+++ b/src/api/report/getReports.js
@@ -1,25 +1,47 @@
import axios from "axios";
import baseURL from "config";
-// Function to fetch a saved PDF report from the backend
-export async function getReportPdf(reportId) {
+// Function to delete a user
+export async function deleteUser(userId) {
try {
- const response = await axios.get(`${baseURL}/view-pdf?ReportID=${reportId}`, {
- responseType: "blob", // Specify the response type as a blob
- });
+ const response = await axios.delete(`${baseURL}/users/${userId}`);
+ if (response.status === 200) {
+ console.log(`User with ID ${userId} has been deleted`);
+ } else {
+ console.error("Failed to delete user:", response.statusText);
+ }
+ } catch (error) {
+ console.error("Error deleting user:", error);
+ throw error;
+ }
+}
+// Function to edit user details
+export async function editUser(userId, updatedData) {
+ try {
+ const response = await axios.put(`${baseURL}/users/${userId}`, updatedData);
if (response.status === 200) {
- // Create a blob URL for the PDF data
- const blob = new Blob([response.data], { type: "application/pdf" });
- const url = window.URL.createObjectURL(blob);
+ console.log(`User with ID ${userId} has been updated`);
+ } else {
+ console.error("Failed to edit user:", response.statusText);
+ }
+ } catch (error) {
+ console.error("Error editing user:", error);
+ throw error;
+ }
+}
- // Open the PDF in a new tab
- window.open(url, "_blank");
+// Function to get the list of users
+export async function getUserList() {
+ try {
+ const response = await axios.get(`${baseURL}/users`);
+ if (response.status === 200) {
+ return response.data;
} else {
- console.error("Failed to fetch PDF report:", response.statusText);
+ console.error("Failed to fetch user list:", response.statusText);
}
} catch (error) {
- console.error("Error fetching PDF report:", error);
+ console.error("Error fetching user list:", error);
throw error;
}
}
diff --git a/src/layouts/admin/manageuser/data/userData.js b/src/layouts/admin/manageuser/data/userData.js
index 9b144ad..7b4e64f 100644
--- a/src/layouts/admin/manageuser/data/userData.js
+++ b/src/layouts/admin/manageuser/data/userData.js
@@ -1,102 +1,103 @@
-/* eslint-disable react/prop-types */
-/* eslint-disable react/function-component-definition */
-/**
- * =========================================================
- * Material Dashboard 2 React - v2.2.0
- * =========================================================
- *
- * Product Page: https://www.creative-tim.com/product/material-dashboard-react
- * Copyright 2023 Creative Tim (https://www.creative-tim.com)
- *
- * Coded by www.creative-tim.com
- *
- * =========================================================
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- */
-
-// Material Dashboard 2 React components
import MDBox from "components/MDBox";
import MDTypography from "components/MDTypography";
import MDBadge from "components/MDBadge";
import { useEffect, useState } from "react";
-import { getReportList } from "api/report/reportsdata";
+import { deleteUser, editUser, getUserList } from "api/ManageUser/users";
+import PropTypes from "prop-types";
export default function Data() {
- const Job = ({ title, description }) => (
+ const UserDetails = ({ name, email }) => (