-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Caitlin Barnard <[email protected]>
- Loading branch information
1 parent
7fa497d
commit 68b63f7
Showing
32 changed files
with
1,445 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[ | ||
{ | ||
"model": "costcentre.departmentalgroup", | ||
"pk": "8888AA", | ||
"fields": { | ||
"created": "2024-10-03T16:05:41.208Z", | ||
"updated": "2024-10-03T16:05:41.208Z", | ||
"active": true, | ||
"group_name": "Departmental Group 0", | ||
"director_general": null, | ||
"treasury_segment_fk": null | ||
} | ||
}, | ||
{ | ||
"model": "costcentre.directorate", | ||
"pk": "88880A", | ||
"fields": { | ||
"created": "2024-10-03T16:05:41.226Z", | ||
"updated": "2024-10-03T16:05:41.226Z", | ||
"active": true, | ||
"directorate_name": "Directorate 1", | ||
"director": null, | ||
"group": "8888AA" | ||
} | ||
}, | ||
{ | ||
"model": "costcentre.costcentre", | ||
"pk": "888812", | ||
"fields": { | ||
"created": "2024-10-03T16:05:41.230Z", | ||
"updated": "2024-10-03T16:05:41.230Z", | ||
"active": true, | ||
"cost_centre_name": "Cost Centre 2", | ||
"directorate": "88880A", | ||
"deputy_director": null, | ||
"business_partner": null, | ||
"bsce_email": null, | ||
"disabled_with_actual": false, | ||
"used_for_travel": true | ||
} | ||
}, | ||
{ | ||
"model": "costcentre.costcentre", | ||
"pk": "888813", | ||
"fields": { | ||
"created": "2024-10-03T16:05:41.233Z", | ||
"updated": "2024-10-03T16:05:41.233Z", | ||
"active": true, | ||
"cost_centre_name": "Cost Centre 3", | ||
"directorate": "88880A", | ||
"deputy_director": null, | ||
"business_partner": null, | ||
"bsce_email": null, | ||
"disabled_with_actual": false, | ||
"used_for_travel": true | ||
} | ||
}, | ||
{ | ||
"model": "costcentre.costcentre", | ||
"pk": "888814", | ||
"fields": { | ||
"created": "2024-10-03T16:05:41.236Z", | ||
"updated": "2024-10-03T16:05:41.236Z", | ||
"active": true, | ||
"cost_centre_name": "Cost Centre 4", | ||
"directorate": "88880A", | ||
"deputy_director": null, | ||
"business_partner": null, | ||
"bsce_email": null, | ||
"disabled_with_actual": false, | ||
"used_for_travel": true | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: "3" | ||
|
||
services: | ||
web: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useEffect, useReducer } from "react"; | ||
|
||
import EditPayroll from "../Components/EditPayroll"; | ||
import * as api from "../Components/EditPayroll/api"; | ||
|
||
const initialPayrollState = []; | ||
|
||
export default function Payroll() { | ||
const [payroll, dispatch] = useReducer(payrollReducer, initialPayrollState); | ||
|
||
useEffect(() => { | ||
api.getPayrollData().then((data) => dispatch({ type: "fetched", data })); | ||
}, []); | ||
|
||
// Handlers | ||
async function handleSavePayroll() { | ||
try { | ||
api.postPayrollData(payroll); | ||
} catch (error) { | ||
console.error("Error saving payroll: ", error); | ||
} | ||
} | ||
|
||
function handleTogglePayPeriods(employeeNo, index, enabled) { | ||
dispatch({ type: "updatePayPeriods", employeeNo, index, enabled }); | ||
} | ||
|
||
return ( | ||
<EditPayroll | ||
payroll={payroll} | ||
onSavePayroll={handleSavePayroll} | ||
onTogglePayPeriods={handleTogglePayPeriods} | ||
/> | ||
); | ||
} | ||
|
||
function payrollReducer(payroll, action) { | ||
switch (action.type) { | ||
case "fetched": { | ||
return action.data; | ||
} | ||
case "updatePayPeriods": { | ||
return payroll.map((employeeRow) => { | ||
if (employeeRow.employee_no == action.employeeNo) { | ||
const updatedPayPeriods = employeeRow.pay_periods.map( | ||
(period, index) => { | ||
if (index + 1 >= action.index + 1) { | ||
return !action.enabled; | ||
} | ||
return period; | ||
} | ||
); | ||
return { | ||
...employeeRow, | ||
pay_periods: updatedPayPeriods, | ||
}; | ||
} | ||
return employeeRow; | ||
}); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
front_end/src/Components/EditPayroll/EmployeeRow/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState } from "react"; | ||
|
||
const EmployeeRow = ({ row, onTogglePayPeriods }) => { | ||
return ( | ||
<tr className="govuk-table__row"> | ||
<td className="govuk-table__cell">{row.name}</td> | ||
<td className="govuk-table__cell">{row.employee_no}</td> | ||
{row.pay_periods.map((enabled, index) => { | ||
return ( | ||
<td className="govuk-table__cell" key={index}> | ||
<input | ||
type="checkbox" | ||
checked={enabled} | ||
onChange={() => | ||
onTogglePayPeriods(row.employee_no, index, enabled) | ||
} | ||
/> | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
); | ||
}; | ||
|
||
export default EmployeeRow; |
38 changes: 38 additions & 0 deletions
38
front_end/src/Components/EditPayroll/PayrollTable/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import EmployeeRow from "../EmployeeRow"; | ||
|
||
/** | ||
* | ||
* @param {object} props | ||
* @param {types.PayrollData[]} props.payroll | ||
* @returns | ||
*/ | ||
export default function PayrollTable({ headers, payroll, onTogglePayPeriods }) { | ||
return ( | ||
<> | ||
<table className="govuk-table"> | ||
<thead className="govuk-table__head"> | ||
<tr className="govuk-table__row"> | ||
{headers.map((header) => { | ||
return ( | ||
<th scope="col" className="govuk-table__header" key={header}> | ||
{header} | ||
</th> | ||
); | ||
})} | ||
</tr> | ||
</thead> | ||
<tbody className="govuk-table__body"> | ||
{payroll.map((row) => { | ||
return ( | ||
<EmployeeRow | ||
row={row} | ||
key={row.employee_no} | ||
onTogglePayPeriods={onTogglePayPeriods} | ||
/> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getData, postData } from "../../Util"; | ||
|
||
import * as types from "./types"; | ||
|
||
/** | ||
* Fetch payroll data and return it as a promise. | ||
* @returns {Promise<types.PayrollData[]>} A promise resolving to an array of objects containing employee information. | ||
*/ | ||
export function getPayrollData() { | ||
return getData(getPayrollApiUrl()).then((data) => data.data); | ||
} | ||
|
||
/** | ||
* Post modified payroll data. | ||
* | ||
* @param {types.PayrollData[]} payrollData - Payroll data to be sent. | ||
* @returns {import("../../Util").PostDataResponse} Updated payroll data received. | ||
*/ | ||
export function postPayrollData(payrollData) { | ||
return postData(getPayrollApiUrl(), JSON.stringify(payrollData)); | ||
} | ||
|
||
/** | ||
* Return the payroll API URL. | ||
* | ||
* This function relies on the `costCentreCode` and `financialYear` being available on | ||
* the `window` object. | ||
* | ||
* @returns {string} The payroll API URL. | ||
*/ | ||
function getPayrollApiUrl() { | ||
const costCentreCode = window.costCentreCode; | ||
const financialYear = window.financialYear; | ||
return `/payroll/api/${costCentreCode}/${financialYear}/`; | ||
} |
Oops, something went wrong.