diff --git a/src/layouts/authentication/sign-in/index.js b/src/layouts/authentication/sign-in/index.js index fb3fb9a..69476c5 100644 --- a/src/layouts/authentication/sign-in/index.js +++ b/src/layouts/authentication/sign-in/index.js @@ -127,6 +127,7 @@ function Basic() { login({ name: userData.User_Name, full_name: userData.Full_Name, + user_ID: userData.UserID, role: userData.Role, email: userData.email, phone_Number: userData.Contact_Number, diff --git a/src/layouts/dashboard/index.js b/src/layouts/dashboard/index.js index 7707cb8..6f7c9f6 100644 --- a/src/layouts/dashboard/index.js +++ b/src/layouts/dashboard/index.js @@ -1,4 +1,3 @@ -import { useEffect } from "react"; import Grid from "@mui/material/Grid"; import AnchorLink from "react-anchor-link-smooth-scroll"; @@ -21,7 +20,7 @@ import ComplexStatisticsCard from "examples/Cards/StatisticsCards/ComplexStatist import Projects from "layouts/dashboard/components/Projects"; import SearchBar from "./components/SearchBar/searchBar"; import { AdCard } from "./components/adCard"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { getCounts } from "api/count/counts"; import { Link } from "react-router-dom"; // import OrdersOverview from "layouts/dashboard/components/OrdersOverview"; diff --git a/src/layouts/graph/index.js b/src/layouts/graph/index.js index 58cc92b..5a5a5cc 100644 --- a/src/layouts/graph/index.js +++ b/src/layouts/graph/index.js @@ -16,14 +16,18 @@ import CategoryDistribution from "./components/barCharts/categoryDist"; import MarriageDistribution from "./components/pieCharts/marriageDist"; import HouseSaleDistribution from "./components/pieCharts/houseSaleDDist"; -import createPDF from "layouts/reports/reports"; +import generatePDF from "layouts/reports/reports"; import PriceFluctuation from "./components/lineCharts/pricefluctuation"; import MDInput from "components/MDInput"; import Demographic from "./components/lineCharts/demographic"; import HousesaleAveragePrice from "./components/barCharts/houseSaleChart"; +import { useUser } from "utils/userContext"; + function GraphViewer() { const contentRef = useRef(null); + const { user } = useUser(); + console.log(user.user_ID); const [includeLandSale, setIncludeLandSale] = useState(false); const [includeCategoryDist, setIncludeCategoryDist] = useState(false); @@ -71,7 +75,7 @@ function GraphViewer() { setIncludeMarriageDist(true); setIncludePriceFluct(true); }; - const generatePDF = () => { + const createPDF = () => { const selectedComponents = []; // Check which components are selected and add them to the selectedComponents array @@ -92,7 +96,7 @@ function GraphViewer() { } // Pass the selected components to your PDF generator function (ChartToPDF) - createPDF(selectedComponents, contentRef, title); + generatePDF(selectedComponents, contentRef, title, user.user_ID); }; return ( @@ -269,7 +273,7 @@ function GraphViewer() { /> - + Generate PDF diff --git a/src/layouts/reports/reports.js b/src/layouts/reports/reports.js index 9631f9a..5d94cb2 100644 --- a/src/layouts/reports/reports.js +++ b/src/layouts/reports/reports.js @@ -2,6 +2,7 @@ import jsPDF from "jspdf"; import "jspdf-autotable"; import html2canvas from "html2canvas"; import * as XLSX from "xlsx"; + import { savePdf } from "api/report/saveReport"; import { storage } from "../../firebase"; import { ref, uploadBytes, getDownloadURL } from "firebase/storage"; @@ -24,7 +25,7 @@ export const generateExcel = (data, filename) => { }; // Function to generate PDF -const generatePDF = async (componentsToPrint, contentRef, title) => { +const generatePDF = async (componentsToPrint, contentRef, title, user_ID) => { try { // Create a new jsPDF instance const doc = new jsPDF(); @@ -55,7 +56,7 @@ const generatePDF = async (componentsToPrint, contentRef, title) => { doc.save(`${title}.pdf`); const pdfBlob = doc.output("blob"); - const userID = "pu123"; + const userID = user_ID; const pdfRef = ref(storage, `Reports/${title}`); // Upload the PDF to Firebase Storage