diff --git a/package-lock.json b/package-lock.json index ffe8398..8ed6485 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2607,6 +2607,7 @@ "version": "1.7.7", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/src/components/transactionsComponets/Table.jsx b/src/components/transactionsComponets/Table.jsx index c8a0ddd..62475a2 100644 --- a/src/components/transactionsComponets/Table.jsx +++ b/src/components/transactionsComponets/Table.jsx @@ -228,4 +228,4 @@ function Table() { ); } -export default Table; +export default Table; \ No newline at end of file diff --git a/src/components/transactionsComponets/WithdrawalHistory.jsx b/src/components/transactionsComponets/WithdrawalHistory.jsx index 2fd1a9a..8daf145 100644 --- a/src/components/transactionsComponets/WithdrawalHistory.jsx +++ b/src/components/transactionsComponets/WithdrawalHistory.jsx @@ -1,18 +1,21 @@ import React, { useState } from "react"; -import { Badge } from "../../components/ui/badge" + +import { Badge } from "@/components/ui/badge"; import { IoIosArrowForward, IoIosArrowBack } from "react-icons/io"; -import { Button } from "../../components/ui/button" +import { Button } from "@/components/ui/button"; import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, - } from "../../components/ui/card" + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import { MdCheck } from "react-icons/md"; -import { Separator } from "../../components/ui/separator" -import logo from '../../assets/icons/Group 1000002785.png' +import { Separator } from "@/components/ui/separator"; +import logo from "../../assets/Group 1000002785.png"; +import axios from "axios"; // Axios import + const tableItems = [ { @@ -21,73 +24,24 @@ const tableItems = [ receipt: "View", status: "successful", }, - { - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt:"View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", - }, - { - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt: "View", - status: "successful", -}, -{ - date: "Sept 12, 08:55pm", - amount: "30,000,000", - receipt:"View", - status: "successful", -}, + //... other items ]; // Number of items per page const itemsPerPage = 6; function Withdraw() { - const [pages, setPages] = useState(["1", "2", "3", , "...", "8", "9", "10",]) + const [pages, setPages] = useState(["1", "2", "3", "...", "8", "9", "10"]); const [currentPage, setCurrentPage] = useState(1); const totalPages = Math.ceil(tableItems.length / itemsPerPage); const currentItems = tableItems.slice( (currentPage - 1) * itemsPerPage, currentPage * itemsPerPage ); + const [popupVisible, setPopupVisible] = useState(false); + const [selectedItem, setSelectedItem] = useState(null); + const [errorMessage, setErrorMessage] = useState(""); + const handleNextPage = () => { setCurrentPage((prevPage) => Math.min(prevPage + 1, totalPages)); }; @@ -95,17 +49,33 @@ function Withdraw() { setCurrentPage((prevPage) => Math.max(prevPage - 1, 1)); }; - const [popupVisible, setPopupVisible] = useState(false); - const [selectedItem, setSelectedItem] = useState(null); - - const handleReceiptClick = (item) => { - setSelectedItem(item); - setPopupVisible(true); + const handleReceiptClick = async (item) => { + try { + const response = await axios.get( + "https://api.propertyhive.com.ng/api/v1/invoice/1", + { + headers: { + Authorization: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzI4MzEzMzYwLCJpYXQiOjE3MjgzMDYxNjAsImp0aSI6ImI5NjY3ZDhjYjI3ZjQyMTFhZDM4ZjYxODk1OTAzOTRiIiwidXNlcl9pZCI6NX0.0WunVWGIdQt_d_xpwuvuOOLN3s4vIfrjQxqBcAvvSmI`, + }, + } + ); + if (response.data) { + setSelectedItem({ ...item, ...response.data }); + setErrorMessage(""); + setPopupVisible(true); + } else { + setErrorMessage("No data fetched"); + } + } catch (error) { + setErrorMessage("Error fetching data"); + console.error("Error fetching data:", error); + } }; const handleClosePopup = () => { setPopupVisible(false); setSelectedItem(null); + setErrorMessage(""); }; return ( @@ -136,17 +106,19 @@ function Withdraw() { {item.date} - {item.status} + + {item.status} + - - + ))} @@ -160,24 +132,28 @@ function Withdraw() { Page {currentPage} of {totalPages}
-
+ {/* Popup for Receipt */} {popupVisible && selectedItem && ( -
-
-
+
+
+
+ {errorMessage ? ( +
{errorMessage}
+ ) : ( @@ -241,52 +226,50 @@ function Withdraw() {
- Withdrawal Successful + Transaction successful - - ₦{selectedItem.amount} - - - -
    -
  • - Ref Number - 000085752257 -
  • -
  • - Payment Time - {selectedItem.date} -
  • -
  • - Account Name - John James -
  • -
  • - Payment Number - 1234567890 -
  • -
  • - Bank - Guaranty Bank PLC -
  • -
+ +
+ Amount + + ₦ {selectedItem.amount} + +
+
+ Fee + + ₦ {selectedItem.fee} + +
+
+ Date + + {selectedItem.date} + +
+ +
+ Receipt + + {selectedItem.receipt} + +
- + -
- logo -
-
+ )}
- )} +
+ )} ); } diff --git a/src/components/transactionsComponets/transactionDetails.jsx b/src/components/transactionsComponets/transactionDetails.jsx index 907d12c..a8d1f33 100644 --- a/src/components/transactionsComponets/transactionDetails.jsx +++ b/src/components/transactionsComponets/transactionDetails.jsx @@ -1,130 +1,190 @@ +import { useEffect, useState } from "react"; +import axios from "axios"; +import { DollarSign, Paperclip, Phone } from "lucide-react"; +import { Button } from "@/components/ui/button"; import { - DollarSign, - Paperclip, - Phone, -} from "lucide-react"; -import { Button } from "../ui/button" -import { - Avatar, - AvatarFallback, - AvatarImage, -} from "../ui/avatar"; + + Avatar, + AvatarFallback, + AvatarImage, +} from "@/components/ui/avatar"; import { - Card, - CardContent, - CardHeader, - CardTitle, -} from "../ui/card"; + Card, + CardContent, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +export function Details() { + const [transactionData, setTransactionData] = useState(null); + const [error, setError] = useState(null); -const tableItems = [ - { - date: "Sept 12, 08:55pm", - amount: "30,000,000", - document: "pending", - status: "full payment", - }, -]; + useEffect(() => { + const fetchTransaction = async () => { + try { + const response = await axios.get( + "https://api.propertyhive.com.ng/api/v1/transactions/1/", + { + headers: { + Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzI4NTAyMzQ4LCJpYXQiOjE3Mjg0OTUxNDgsImp0aSI6IjFmYmE0ZWVlNWFlNDQ2MzJiZDFjNGMxYThiYmNjZmZmIiwidXNlcl9pZCI6NX0.rHQpbeuvBsrrONhYu0hgEdj4iHRgls0MrwcPeBfVcoY`, + }, + } + ); + console.log("Transaction Data:", response.data); // Debugging line + setTransactionData(response.data); // Adjust this if needed based on response structure + } catch (error) { + if (error.response && error.response.status === 403) { + setError("You are not authorized to view this data. Please check your token or permissions."); + } else { + setError(error.response?.statusText || error.message); + } + console.error("Error fetching transaction:", error.response || error); + } + }; -export function Details() { - return ( -
-
- - -
- - - OM - -
- John James -
- - 08040951697 -
-
-
-
- - -
-
- - -
- Transactions -
-
- -
-
- - - - - - - - - - - - {tableItems.map((item, idx) => ( - - - - - - - - ))} - -
S/NAmount(₦)DateDocumentStatus
- {idx + 1} - -
- {item.amount} -
-
{item.date}• {item.document} - {item.status} -
-
+ fetchTransaction(); + }, []); + + return ( +
+
+ + +
+ + + OM + +
+ + John James + +
+ + 08040951697 +
+
+
+
+ +
+ +
+ + +
+ Transactions +
+
+ +
+
+ + + + + + + + + + + + {error ? ( + + + + ) : !transactionData ? ( + + + + ) : ( + + + + + + + + )} + +
S/NAmount(₦)DateDocumentStatus
+ Error fetching data: {error} +
+ No transactions available +
+ 1 + +
+ {transactionData.total_amount}
-

- John James has completed payment, kindly proceed to
send the necessary documents, the funds will be - locked
until verification has been done by the buyer. -

- - - - - Full Payment - - - Payment Illustration -

- Luxury Duplex, Banana Island, Lekki, Lagos state -

-

- ₦200,000,000 -

- -

- Documents sent -

-
-
- {/* Button below transactions card */} -
- -
+
+ {/* Format the created_at date and time */} + {new Date(transactionData.created_at).toLocaleString('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + hour12: true, + })} + + • {transactionData.document ? ( + {transactionData.document} + ) : ( + Pending + )} + + {transactionData.status} +
-
+
+

+ John James has completed payment, kindly proceed to
{" "} + send the necessary documents, the funds will be locked
{" "} + until verification has been done by the buyer. +

+ + + + + + + Full Payment + + + + Payment Illustration +

+ Luxury Duplex, Banana Island, Lekki, Lagos state +

+

+ ₦200,000,000 +

+ +

+ Documents sent +

+
+
+ +
+ +
- ); +
+
+ ); }