Skip to content

Commit

Permalink
FFT-204 Edit payroll UX tweaks (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDudley authored and DenisDDBT committed Feb 25, 2025
1 parent 756775c commit c9cf14b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion forecast/templates/forecast/edit/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% can_access_edit_payroll user as user_can_access_edit_payroll %}
{% switch 'payroll' %}
{% if user_can_access_edit_payroll %}
<a class="govuk-link" href="{% url 'payroll:edit' view.cost_centre_details.cost_centre_code view.financial_year %}">Go to Payroll</a>
<a class="govuk-link govuk-link--no-visited-state" href="{% url 'payroll:edit' view.cost_centre_details.cost_centre_code view.financial_year %}">Go to Payroll</a>
{% endif %}
{% endswitch %}
</div>
Expand Down
17 changes: 15 additions & 2 deletions front_end/src/Apps/Payroll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ErrorSummary from "../Components/Common/ErrorSummary";
import SuccessBanner from "../Components/Common/SuccessBanner";
import ForecastTable from "../Components/EditPayroll/ForecastTable";
import { makeFinancialCodeKey } from "../Util";
import Loading from "../Components/Common/Loading";

const initialPayrollState = {
employees: [],
Expand All @@ -37,6 +38,10 @@ export default function Payroll() {
const initialShowPreviousMonths = localStorage.getItem(
"editPayroll.showPreviousMonths",
);

// State

const [isLoading, setIsLoading] = useState(true);
const [showPreviousMonths, setShowPreviousMonths] = useState(
initialShowPreviousMonths === "true",
);
Expand All @@ -47,6 +52,8 @@ export default function Payroll() {
return savedTab ? parseInt(savedTab) : 0;
});

// Fetches

async function getAllPayroll() {
try {
const data = await api.getPayrollData();
Expand All @@ -59,6 +66,8 @@ export default function Payroll() {
},
]);
}
// finally
setIsLoading(false);
}

// Use Effects
Expand Down Expand Up @@ -150,9 +159,13 @@ export default function Payroll() {
);
}

if (isLoading) {
return <Loading />;
}

return (
<>
{saveSuccess && <SuccessBanner />}
{saveSuccess && <SuccessBanner>Success - forecast updated</SuccessBanner>}
{errors && <ErrorSummary errors={errors} />}
<ToggleCheckbox
toggle={showPreviousMonths}
Expand Down Expand Up @@ -212,7 +225,7 @@ export default function Payroll() {
</Tab>
</Tabs>
<button className="govuk-button" onClick={handleSavePayroll}>
Save payroll
Save payroll and update forecast
</button>
<ForecastTable
forecast={forecastAndActuals}
Expand Down
7 changes: 7 additions & 0 deletions front_end/src/Components/Common/Loading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Loading({ children = "Loading..." }) {
return (
<p className="govuk-body" style={{ textAlign: "center", fontSize: "2rem" }}>
{children}
</p>
);
}
4 changes: 2 additions & 2 deletions front_end/src/Components/Common/SuccessBanner/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default function SuccessBanner() {
export default function SuccessBanner({ children }) {
return (
<div className="govuk-notification-banner govuk-notification-banner--success">
<div className="govuk-notification-banner__header">
<h2
className="govuk-notification-banner__title"
id="govuk-notification-banner-title"
>
Success
{children}
</h2>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions front_end/src/Components/EditPayroll/ForecastTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default function ForecastTable({ forecast, months }) {
<>
<h2 className="govuk-heading-m">Payroll forecast</h2>

<p className="govuk-body">Save payroll changes to update this table.</p>

<div className="scrollable">
<table className="govuk-table">
<thead className="govuk-table__head">
Expand Down
12 changes: 8 additions & 4 deletions payroll/templates/payroll/page/edit_payroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ <h1 class="govuk-heading-l">Edit payroll</h1>

{# Here we assume that a user with access to payroll also has access to forecast #}
{% switch 'payroll' %}
<a class="govuk-link" href="{% url 'edit_forecast' cost_centre_code financial_year %}">Go to Forecast</a>
<a class="govuk-link govuk-link--no-visited-state" href="{% url 'edit_forecast' cost_centre.cost_centre_code financial_year.financial_year %}">Go to Forecast</a>
{% endswitch %}
</div>

<h2 class="govuk-heading-m">
<a class="govuk-link govuk-link--no-visited-state" href="{% url 'forecast_cost_centre' cost_centre.cost_centre_code financial_year.financial_year %}" target="_blank">{{ cost_centre }}</a>
</h2>

<div id="payroll-app"></div>
{% endblock content %}

{% block scripts %}
<script>
window.costCentreCode = "{{ cost_centre_code|escapejs }}";
window.financialYear = new Number("{{ financial_year }}");
window.addVacancyUrl = "{% url 'payroll:add_vacancy' cost_centre_code financial_year %}"
window.costCentreCode = "{{ cost_centre.cost_centre_code|escapejs }}";
window.financialYear = new Number("{{ financial_year.financial_year }}");
window.addVacancyUrl = "{% url 'payroll:add_vacancy' cost_centre.cost_centre_code financial_year.financial_year %}"
</script>
{% vite_dev_client %}
{% vite_js 'src/index.jsx' %}
Expand Down
16 changes: 9 additions & 7 deletions payroll/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.urls import reverse
from django.views import View
from django.views.generic import CreateView, DeleteView, UpdateView
from django.views.generic.base import ContextMixin, TemplateView

from core.models import FinancialYear
from costcentre.models import CostCentre
Expand All @@ -16,7 +17,7 @@
from .services.ingest import import_payroll


class EditPayrollBaseView(UserPassesTestMixin, View):
class EditPayrollBaseView(UserPassesTestMixin, ContextMixin, View):
def test_func(self) -> bool | None:
return payroll_service.can_edit_payroll(
self.request.user,
Expand All @@ -36,15 +37,16 @@ def setup(self, request, *args, **kwargs) -> None:
pk=self.kwargs["financial_year"],
)


class EditPayrollPage(EditPayrollBaseView):
def get(self, *args, **kwargs) -> HttpResponse:
def get_context_data(self, **kwargs):
context = {
"cost_centre_code": self.cost_centre.cost_centre_code,
"financial_year": self.financial_year.financial_year,
"cost_centre": self.cost_centre,
"financial_year": self.financial_year,
}
return super().get_context_data(**kwargs) | context


return TemplateResponse(self.request, "payroll/page/edit_payroll.html", context)
class EditPayrollPage(TemplateView, EditPayrollBaseView):
template_name = "payroll/page/edit_payroll.html"


class VacancyViewMixin(PermissionRequiredMixin):
Expand Down

0 comments on commit c9cf14b

Please sign in to comment.