Skip to content

Commit

Permalink
New form layout with section complete questions
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Jan 14, 2025
1 parent b8f0543 commit 9ac6ad0
Show file tree
Hide file tree
Showing 93 changed files with 1,142 additions and 926 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: Run Rubocop
run: bundle exec rubocop

- name: Run Slim-Lint with PR annotations
run: bundle exec slim-lint -r github app/views app/components
- name: Run Slim-Lint
run: bundle exec slim-lint app/views app/components

- name: Run Brakeman
run: bundle exec brakeman
Expand Down
95 changes: 25 additions & 70 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions app/components/job_application_review_component.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class JobApplicationReviewComponent < ReviewComponent
class JobApplicationReviewComponent < ApplicationComponent
renders_one :header

renders_one :above
renders_one :below

renders_one :sidebar, ReviewComponent::Sidebar

renders_many(:sections, lambda do |section_name, **kwargs|
JobApplicationReviewComponent::Section.new(
@job_application,
Expand All @@ -10,25 +17,22 @@ class JobApplicationReviewComponent < ReviewComponent

attr_reader :job_application

def initialize(job_application, step_process:, allow_edit: nil, classes: [], html_attributes: {}, **)
def initialize(job_application, show_sidebar: true, allow_edit: nil, classes: [], html_attributes: {})
super(
classes: classes,
html_attributes: html_attributes,
namespace: "jobseekers/job_applications",
**,
)

@allow_edit = allow_edit
@job_application = job_application
@step_process = step_process
@show_sidebar = show_sidebar
end

private
def column_class
show_sidebar? ? %w[govuk-grid-column-two-thirds] : %w[govuk-grid-column-full]
end

def track_assigns
super.merge(
job_application: @job_application,
step_process: @step_process,
)
def show_sidebar?
!!@show_sidebar
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- sections.each do |section|
= section

= content

= below

- if show_sidebar?
Expand Down
16 changes: 9 additions & 7 deletions app/components/job_application_review_component/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ class JobApplicationReviewComponent::Section < ReviewComponent::Section
include JobApplicationsHelper
include VacanciesHelper

def initialize(job_application, allow_edit: nil, forms: [], classes: [], html_attributes: {}, **)
def initialize(job_application, name:, id: nil, allow_edit: nil, forms: [], classes: [], html_attributes: {})
super(
job_application,
forms: forms,
name: name,
id: id,
classes: classes,
html_attributes: html_attributes,
**,
html_attributes: html_attributes
)

@allow_edit = allow_edit
Expand All @@ -21,10 +22,11 @@ def heading_text
t("jobseekers.job_applications.build.#{@name}.heading")
end

def build_list
list = nil
govuk_summary_list { |l| list = l }
list
def edit_link
title = heading_text
text = "Change"
href = error_path
govuk_link_to text, href, aria: { label: "#{text} #{title}" }, classes: "govuk-!-display-none-print" if text && href
end

def constantize_form(form_class_name)
Expand Down
52 changes: 0 additions & 52 deletions app/components/review_component.rb

This file was deleted.

44 changes: 22 additions & 22 deletions app/components/review_component/section.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# This is an abstract class. See VacancyReviewComponent::Section or
# JobApplicationReviewComponent::Section for specific implementations.
# This is an abstract class.
# See JobApplicationReviewComponent::Section for specific implementation.
class ReviewComponent::Section < ApplicationComponent
include FormsHelper
include StatusTagHelper

renders_one :heading, ReviewComponent::Section::Heading
renders_many :field_div_sets, ->(f = nil, form: nil) { render_divs_for_fields(f || form) }

delegate :with_row, to: :@list
class RowData
attr_reader :key, :value

def with_key(text:)
@key = text
end

def with_value(text:)
@value = text
end
end

attr_reader :rows

def initialize(record, name:, id: nil, forms: [], **)
super(**)
Expand All @@ -18,30 +29,19 @@ def initialize(record, name:, id: nil, forms: [], **)
@id = id || name
@name = name
@record = record
@rows = []
end

def with_row
row_data = RowData.new
yield(row_data) if block_given?
@rows << row_data
end

private

def before_render
with_field_div_sets(@forms.map { |f| { form: f } })

with_heading(title: heading_text, link_to: [error_link_text, error_path], allow_edit: allow_edit?) do
review_section_tag(@record, @forms.map(&:target_name), @forms)
end

@list = build_list
end

def content
# Calling `super` here has side-effects which
# affect the contents of `@list.rows`.
super_content = super

if @list.rows.any?
render(@list)
else
super_content
end
end

attr_reader :id
Expand Down
25 changes: 0 additions & 25 deletions app/components/review_component/section/heading.rb

This file was deleted.

This file was deleted.

12 changes: 10 additions & 2 deletions app/components/review_component/section/section.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ li
= field_div_set

= tag.div(id: id, **html_attributes) do
= heading
.review-component__section__body
= content
= govuk_summary_card(title: heading_text) do |card|
- card.with_action { edit_link }
- if rows.any?
- card.with_summary_list do |summary_list|
- rows.each do |row_data|
- summary_list.with_row do |row|
- row.with_key text: row_data.key if row_data.key.present?
- row.with_value text: row_data.value if row_data.value.present?
- else
= content
41 changes: 15 additions & 26 deletions app/controllers/jobseekers/job_applications/build_controller.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
class Jobseekers::JobApplications::BuildController < Jobseekers::JobApplications::BaseController
include Wicked::Wizard
include Jobseekers::QualificationFormConcerns

steps :personal_details, :professional_status, :qualifications, :training_and_cpds, :employment_history, :personal_statement, :references,
:equal_opportunities, :ask_for_support, :declarations

helper_method :back_path, :employments, :form, :job_application, :qualification_form_param_key, :redirect_to_review?, :vacancy

def show
skip_step_if_missing

render_wizard
render step
end

def update
if form.valid?
job_application.update(update_params.except(:teacher_reference_number, :has_teacher_reference_number))
update_or_create_jobseeker_profile! if step == :professional_status

return redirect_to finish_wizard_path, success: t("messages.jobseekers.job_applications.saved") if redirect_to_review?

render_wizard job_application
if redirect_to_review?
redirect_to jobseekers_job_application_review_path(job_application), success: t("messages.jobseekers.job_applications.saved")
else
redirect_to jobseekers_job_application_apply_path job_application
end
else
render_wizard
render step
end
end

private

def back_path
@back_path ||= if redirect_to_review?
finish_wizard_path
elsif step == :personal_details
new_jobseekers_job_job_application_path(vacancy.id)
jobseekers_job_application_review_path(job_application)
else
jobseekers_job_application_build_path(job_application.id, step_process.previous_step)
jobseekers_job_application_apply_path job_application
end
end

def form
@form ||= form_class.new(form_attributes)
end

def step
params[:id].to_sym
end

def form_class
"jobseekers/job_application/#{step}_form".camelize.constantize
end

def form_attributes
attributes = case action_name
when "show"
form_class.load(job_application.attributes)
form_class.load_form(job_application)
when "update"
form_params
end
Expand Down Expand Up @@ -83,7 +81,7 @@ def job_application
end

def redirect_to_review?
current_jobseeker.job_applications.not_draft.any? || session[:back_to_review]&.include?(job_application.id)
session[:back_to_review]&.include?(job_application.id)
end

def update_params
Expand All @@ -105,22 +103,13 @@ def update_fields
end

def step_incomplete?
return false unless step.in? %i[qualifications employment_history training_and_cpds]

form_params["#{step}_section_completed"] == "false"
end

def vacancy
@vacancy ||= job_application.vacancy
end

def skip_step_if_missing
# Calling step_process will initialize a StepProcess, which will raise if the current step is missing.
step_process
rescue StepProcess::MissingStepError
skip_step unless step == "wicked_finish"
end

def jobseeker_profile_attributes
{
jobseeker_profile: current_jobseeker.jobseeker_profile,
Expand Down
Loading

0 comments on commit 9ac6ad0

Please sign in to comment.