Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM7 Provider: Amend main/additional defendant content #1188

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions app/forms/nsm/steps/defendant_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def main_record?
application.defendants.count.zero?
end

def position
record.position || position_attributes[:position]
end

private

def persist!
Expand Down
8 changes: 0 additions & 8 deletions app/forms/nsm/steps/defendant_summary_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ def save
super
end

def main_defendant
@main_defendant ||= defendants.detect(&:main_record?)
end

def additional_defendants
@additional_defendants ||= defendants.reject(&:main_record?)
end

def defendants
@defendants ||= application.defendants.map do |defendant|
DefendantDetailsForm.build(defendant, application:)
Expand Down
2 changes: 1 addition & 1 deletion app/views/nsm/steps/defendant_delete/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1 class="govuk-heading-l"><%= t('.heading') %></h1>

<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m"><%= t(@form_object.caption_key) %></caption>
<caption class="govuk-table__caption govuk-table__caption--m"><%= t(@form_object.caption_key, count: @form_object.record.position) %></caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-!-width-one-half"><%= t('.headers.full_name') %></th>
Expand Down
9 changes: 7 additions & 2 deletions app/views/nsm/steps/defendant_details/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= govuk_error_summary(@form_object) %>
<h1 class="govuk-heading-l"><%= t('.heading') %></h1>
<% if @form_object.record.main %>
<h1 class="govuk-heading-l"><%= t('.heading_main') %></h1>
<% else %>
<h1 class="govuk-heading-l"><%= t('.heading_additional', count: @form_object.position ) %></h1>
<p><%= t('.add_another_hint') %>
<% end %>
<%= step_form @form_object, url: nsm_steps_defendant_details_path(@form_object.application, defendant_id: @form_object.record.id) do |f| %>
<%= f.govuk_fieldset legend: { text: t(@form_object.label_key, index: @form_object.index) }, class: 'moj-add-another__item' do %>
<%= f.govuk_fieldset legend: { text: t(@form_object.label_key, index: @form_object.position), hidden: true }, class: 'moj-add-another__item' do %>
<%= f.govuk_text_field :first_name, maxlength_enabled: true %>
<%= f.govuk_text_field :last_name, maxlength_enabled: true %>
<% if @form_object.maat_required? %>
Expand Down
69 changes: 24 additions & 45 deletions app/views/nsm/steps/defendant_summary/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,44 @@
<h1 class="govuk-heading-l"><%= t('.heading', count: @form_object.application.defendants.count) %></h1>

<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m"><%= t('.main_defendant') %></caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-table__space-30"><%= t('.headers.full_name') %></th>
<th scope="col" class="govuk-table__header govuk-table__space-30"><%= t('.headers.defendant') %></th>
<th scope="col" class="govuk-table__header govuk-table__space-30"><%= t('.headers.name') %></th>
<% if maat_required?(@form_object) %>
<th scope="col" class="govuk-table__header govuk-table__space-25"><%= t('.headers.maat') %></th>
<% end %>
<th scope="col" class="govuk-table__header govuk-table__space-30"><%= t('.headers.change') %></th>
<th scope="col" class="govuk-table__header govuk-table__space-15"><%= t('.headers.action') %></th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @form_object.defendants.each do |defendant| %>

<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= check_missing(@form_object.main_defendant.full_name_if_valid) %></td>
<% if maat_required?(@form_object) %>
<td class="govuk-table__cell"><%= check_missing(@form_object.main_defendant.maat_if_valid) %></td>
<% end %>
<td class="govuk-table__cell">
<%= link_to t('.change'), edit_nsm_steps_defendant_details_path(@form_object.application, defendant_id: @form_object.main_defendant.id) %>
</td>
</tr>
</tbody>
</table>

<% if @form_object.additional_defendants.any? %>
<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m"><%= t('.additional_defendant') %></caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-table__space-30"><%= t('.headers.full_name') %></th>
<% if maat_required?(@form_object) %>
<th scope="col" class="govuk-table__header govuk-table__space-25"><%= t('.headers.maat') %></th>
<% end %>
<th scope="col" class="govuk-table__header govuk-table__space-15"><%= t('.headers.change') %></th>
<th scope="col" class="govuk-table__header govuk-table__space-15"><%= t('.headers.delete') %></th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @form_object.additional_defendants.each do |defendant| %>

<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= check_missing(defendant.full_name_if_valid) %></td>
<% if maat_required?(@form_object) %>
<td class="govuk-table__cell"><%= check_missing(defendant.maat_if_valid) %></td>
<% end %>
<td class="govuk-table__cell">
<%= link_to t('.change'), edit_nsm_steps_defendant_details_path(@form_object.application, defendant_id: defendant.id) %>
</td>
<tr class="govuk-table__row">
<% if defendant.record.main %>
<td class="govuk-table__cell"><%= t('.cells.defendant_main') %></td>
<% else %>
<td class="govuk-table__cell"><%= t('.cells.defendant_additional', count: defendant.position ) %></td>
<% end %>
<td class="govuk-table__cell"><%= link_to check_missing(defendant.full_name_if_valid), edit_nsm_steps_defendant_details_path(@form_object.application, defendant_id: defendant.id) %></td>
<% if maat_required?(@form_object) %>
<td class="govuk-table__cell"><%= check_missing(defendant.maat_if_valid) %></td>
<% end %>
<% if defendant.record.main != true %>
<td class="govuk-table__cell">
<%= link_to t('.delete'), edit_nsm_steps_defendant_delete_path(@form_object.application, defendant_id: defendant.id) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% else %>
<td class="govuk-table__cell"></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>

<%= step_form @form_object do |f| %>
<% if @form_object.defendants.all?(&:valid?) %>
<%= f.govuk_radio_buttons_fieldset :add_another, legend: { text: t('.add_another'), size: 'm' } do %>
<%= f.govuk_radio_buttons_fieldset :add_another, legend: { text: t('.add_another'), size: 'm' }, hint: { text: t('.add_another_hint') } do %>
<%= f.govuk_radio_button :add_another, YesNoAnswer::YES.to_s %>
<%= f.govuk_radio_button :add_another, YesNoAnswer::NO.to_s %>
<% end %>
Expand Down
25 changes: 15 additions & 10 deletions config/locales/en/nsm/steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,38 @@ en:
defendant_details:
edit:
page_title: Defendant details
heading: Defendant details
main_defendant_field_set: Main defendant
defendant_field_set: Additional defendant %{index}
heading_main: Defendant 1 (lead defendant)
heading_additional: Defendant %{count}
main_defendant_field_set: Defendant 1 (lead defendant)
defendant_field_set: Defendant %{index}
main_defendant: main
defendant: additional %{index}
add_another_hint: Only add this defendant if you are representing them in the same case
defendant_summary:
edit:
page_title: Defendant summary
heading:
one: You've added 1 defendant
other: You've added %{count} defendants
main_defendant: Main defendant details
additional_defendant: Additional defendant details
main_defendant: Defendant 1 (lead)
headers:
full_name: Full name
defendant: Defendant
name: Name
maat: MAAT ID number
change: Change
delete: Delete
action: Action
cells:
defendant_main: Defendant 1 (lead)
defendant_additional: Defendant %{count}
add_another: Do you want to add another defendant?
add_another_hint: Only add this defendant if you are representing them in the same case
change: Change
delete: Delete
defendant_delete:
edit:
page_title: Are you sure you want to delete this defendant?
heading: Are you sure you want to delete this defendant?
main_defendant: Main defendant details
additional_defendant: Additional defendant details
main_defendant: Defendant 1 (lead)
additional_defendant: Defendant %{count}
headers:
full_name: Full name
maat: MAAT ID number
Expand Down
4 changes: 2 additions & 2 deletions spec/system/nsm/defendants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'can add a defendant' do
visit edit_nsm_steps_defendant_details_path(claim.id, defendant_id: Nsm::StartPage::NEW_RECORD)

within('.govuk-fieldset', text: 'Main defendant') do
within('.govuk-fieldset', text: 'Defendant 1 (lead defendant)') do
fill_in 'First name', with: 'Jim'
fill_in 'Last name', with: 'Bob'
fill_in 'MAAT ID number', with: '1234567'
Expand All @@ -37,7 +37,7 @@

click_on 'Save and continue'

within('.govuk-fieldset', text: 'Additional defendant') do
within('.govuk-fieldset', text: 'Defendant 2') do
fill_in 'First name', with: 'Bob'
fill_in 'Last name', with: 'Jim'
fill_in 'MAAT ID number', with: '9876543'
Expand Down