Skip to content

Commit

Permalink
Save tab state to local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Dec 17, 2024
1 parent 4f59556 commit f22bb57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion front_end/src/Apps/Payroll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default function Payroll() {
initialPayModifiersState,
);
const [saveSuccess, setSaveSuccess] = useState(false);
const [activeTab, setActiveTab] = useState(() => {
const savedTab = localStorage.getItem("activeTab");
return savedTab ? parseInt(savedTab) : 0;
});

useEffect(() => {
localStorage.setItem("activeTab", activeTab);
}, [activeTab]);

useEffect(() => {
const savedSuccessFlag = localStorage.getItem("saveSuccess");
Expand Down Expand Up @@ -98,7 +106,7 @@ export default function Payroll() {
</div>
</div>
)}
<Tabs>
<Tabs activeTab={activeTab} setActiveTab={setActiveTab}>
<Tab label="Dashboard" key="1">
<h2 className="govuk-heading-m">Payroll</h2>
<PayrollTable
Expand Down
3 changes: 1 addition & 2 deletions front_end/src/Components/EditPayroll/Tabs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from "react";

export default function Tabs({ children }) {
const [activeTab, setActiveTab] = useState(0);
export default function Tabs({ activeTab, setActiveTab, children }) {
const tabs = Array.isArray(children) ? children : [children];
return (
<>
Expand Down

0 comments on commit f22bb57

Please sign in to comment.