import { useState, useEffect } from "react"; import { useSelector } from "react-redux"; import { RootState } from "../../store"; const PaysSlips = () => { const { projectSummary } = useSelector((state: any) => state.projects); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [rows, setRows] = useState([]); useEffect(() => { if (!projectSummary?.vaId) return; fetchPayslips(projectSummary?.vaId); }, [projectSummary?.vaId]); const fetchPayslips = async (vaId: string) => { setLoading(true); setError(null); try { console.log("getPayslips" , vaId) const result = await window.electron.getPayslips(vaId); if (!result.success) { setError(result.message || "Failed to load payslips"); return; } const response = result.data; if (!response || response.length === 0) { setRows([]); return; } // Extract payrolls array from first index const payrolls = response[0]?.payrolls || []; setRows(payrolls); } catch (err: any) { setError("An unexpected error occurred"); } finally { setLoading(false); } }; return ( <>

Payslips

{loading && (
)} {error && (
{error}
)} {!loading && !error && rows.length === 0 && (
No payslip data available.
)} {!loading && !error && rows.length > 0 && (
{rows.map((row, index) => ( ))}
# Status Date Total Hours Total Pay Action
{index + 1} {row.status} {row.payrollSchedule} {row.totalHoursFormatted} ${row.totalPayAmount.toFixed(2)}
)}
); }; export default PaysSlips;