Skip to content

Commit db25554

Browse files
committed
Add AppConsentCardComponent
This adds a new component which renders a small card containing information about a consent response. This will be used in the new designs for the consent responses on the patient session page. Jira-Issue: MAV-1474
1 parent 51c6c5e commit db25554

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
class AppConsentCardComponent < ViewComponent::Base
4+
def initialize(consent, session:)
5+
super
6+
7+
@consent = consent
8+
@session = session
9+
end
10+
11+
def call
12+
render AppCardComponent.new(**card_options) do |card|
13+
card.with_heading { heading }
14+
govuk_summary_list(rows:)
15+
end
16+
end
17+
18+
private
19+
20+
attr_reader :consent, :session
21+
22+
delegate :patient, :programme, to: :consent
23+
24+
def link_to
25+
session_patient_programme_consent_path(session, patient, programme, consent)
26+
end
27+
28+
def card_options = { link_to:, colour: "offset", compact: true }
29+
30+
def heading
31+
if consent.via_self_consent?
32+
consent.who_responded
33+
else
34+
"#{consent.name} (#{consent.who_responded})"
35+
end
36+
end
37+
38+
def rows
39+
[
40+
if (phone = consent.parent&.phone).present?
41+
{ key: { text: "Phone number" }, value: { text: phone } }
42+
end,
43+
if (email = consent.parent&.email).present?
44+
{ key: { text: "Email address" }, value: { text: email } }
45+
end,
46+
{
47+
key: {
48+
text: "Date"
49+
},
50+
value: {
51+
text: consent.responded_at.to_fs(:long)
52+
}
53+
},
54+
{
55+
key: {
56+
text: "Decision"
57+
},
58+
value: {
59+
text: helpers.consent_status_tag(consent)
60+
}
61+
}
62+
].compact
63+
end
64+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
describe AppConsentCardComponent do
4+
subject { render_inline(component) }
5+
6+
let(:component) { described_class.new(consent, session:) }
7+
8+
let(:programme) { create(:programme) }
9+
let(:organisation) { create(:organisation, programmes: [programme]) }
10+
11+
let(:consent) do
12+
create(
13+
:consent,
14+
patient:,
15+
parent:,
16+
programme:,
17+
organisation:,
18+
submitted_at: Time.zone.local(2024, 1, 1)
19+
)
20+
end
21+
let(:school) { create(:school, name: "Waterloo Road", organisation:) }
22+
let(:session) do
23+
create(:session, programmes: [programme], organisation:, location: school)
24+
end
25+
let(:parent) { create(:parent) }
26+
let(:patient) { create(:patient) }
27+
28+
it { should have_content(parent.full_name) }
29+
30+
it { should have_content("Phone number") }
31+
it { should have_content(parent.phone) }
32+
33+
it { should have_content("Email address") }
34+
it { should have_content(parent.email) }
35+
36+
it { should have_content("Date") }
37+
it { should have_content("1 January 2024 at 12:00am") }
38+
39+
it { should have_content("Decision") }
40+
it { should have_content("Consent given") }
41+
end

0 commit comments

Comments
 (0)