Skip to content

Commit

Permalink
Begin refactor of cost centre page for payroll
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Oct 28, 2024
1 parent 68b63f7 commit ed0ddb0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions forecast/templates/forecast/edit/choose_cost_centre.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h3 class="govuk-heading-l">My cost centres</h3>
{% endblock %}
{% block scripts %}
<script>
window.isForecastOrPayroll = {{ view.get_is_forecast_or_payroll|safe }}
window.costCentres = {{ view.get_user_cost_centres|safe }};
window.currentFinancialYear = {{ view.get_financial_year|safe }};
window.currentFinancialYearDisplay = "{{ view.get_financial_year_display|safe }}";
Expand Down
6 changes: 6 additions & 0 deletions forecast/views/edit_select_cost_centre.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def get_user_cost_centres(self):

return json.dumps(cost_centres)

def get_is_forecast_or_payroll(self):
if "forecast" in self.request.path:
return ["forecast"]

return ["payroll"]

def get_form_kwargs(self):
kwargs = super(ChooseCostCentreView, self).get_form_kwargs()
kwargs["user"] = self.request.user
Expand Down
4 changes: 3 additions & 1 deletion front_end/src/Components/CostCentreList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
const [financialYears, setFinancialYears] = useState([])
const [forecastFinYearDisplay, setForecastFinYearDisplay] = useState(null)
const [forecastFinYear, setForecastFinYear] = useState(null)
const [isForecastOrPayroll, setIsForecastOrPayroll] = useState([])

useEffect(() => {
const timer = () => {
Expand All @@ -18,6 +19,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
if (window.financialYears){
setFinancialYears(window.financialYears)
}
setIsForecastOrPayroll(window.isForecastOrPayroll)
} else {
timer()
}
Expand Down Expand Up @@ -68,7 +70,7 @@ const CostCentreList = ({rowIndex, cellKey, format}) => {
<ul className="cost-centre-list">
{displayedCentres.map((costCentre, index) => {
return <li key={index}>
<a href={ `/forecast/edit/${costCentre.code}/${forecastFinYear}` } className="govuk-link">{costCentre.code} - {costCentre.name}</a>
<a href={ `/${isForecastOrPayroll}/edit/${costCentre.code}/${forecastFinYear}` } className="govuk-link">{costCentre.code} - {costCentre.name}</a>
</li>
})}
</ul>
Expand Down
8 changes: 7 additions & 1 deletion payroll/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.urls import path

from forecast.views.edit_select_cost_centre import ChooseCostCentreView

from . import views


app_name = "payroll"

urlpatterns = [
# TODO: Add choose financial year and cost centre url.
path(
"edit/<str:cost_centre_code>/<int:financial_year>/",
views.edit_payroll_page,
Expand All @@ -17,4 +18,9 @@
views.PayrollView.as_view(),
name="api",
),
path(
"edit/choose-cost-centre/",
ChooseCostCentreView.as_view(),
name="choose_cost_centre",
),
]

0 comments on commit ed0ddb0

Please sign in to comment.