Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/controllers/faf_controller.rb

This file was deleted.

33 changes: 33 additions & 0 deletions app/controllers/fafs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class FafsController < ApplicationController
skip_before_action :authenticate_user!

def index; end

def show; end

def new
@faf_form = FafForm.new(step: 1)
end

def create
@faf_form = form
@faf_form.advance! if validation.success?
render :new
end

private

# @return [FafForm] form object populated with validation messages
def form
FafForm.new(step: form_params[:step], messages: validation.errors(full: true).to_h, **validation.to_h)
end

def form_params
params.require(:faf_form).permit(:step, :dsi)
end

# @return [FafFormSchema] validated form input
def validation
FafFormSchema.new.call(**form_params)
end
end
61 changes: 61 additions & 0 deletions app/forms/faf_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# @abstract Form Object for multi-step Find-a-Framework support questionnaire
#
class FafForm
extend Dry::Initializer

# @see https://design-system.service.gov.uk/components/error-summary/
#
class ErrorSummary
extend Dry::Initializer

# @!attribute [r] messages
#
# @example
# { phone_number: ["size cannot be less than 10"] }
#
# @return [Hash]
param :messages, Types::Hash, default: proc { {} }

delegate :any?, to: :messages
end

# @!attribute [r] step
# @return [Integer] internal counter defaults to 1, coerces strings
option :step, Types::Params::Integer, default: proc { 1 }

# @!attribute [r] messages
# @return [Hash] field validation error messages
option :messages, Types::Hash, default: proc { {} }

# @!attribute [r] dsi
# @return [Boolean]
option :dsi, Types::Params::Bool, optional: true # 1

# @see https://govuk-form-builder.netlify.app/introduction/error-handling/
#
# @return [ErrorSummary]
def errors
ErrorSummary.new(messages)
end

# Proceed or skip to next questions
#
# @param num [Integer] number of steps to advance
#
# @return [Integer] next step position
def advance!(num = 1)
@step += num
end

# @return [Integer] previous step position
def back
@step - 1
end

# @see SupportRequestsController#update
#
# @return [Hash] form parms as support request attributes
def to_h
self.class.dry_initializer.attributes(self).except(:step, :messages)
end
end
18 changes: 18 additions & 0 deletions app/forms/faf_form_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Validate "find-a-framework support requests"
#
class FafFormSchema < Dry::Validation::Contract
import_predicates_as_macros

config.messages.backend = :i18n
config.messages.top_namespace = :forms
config.messages.load_paths << Rails.root.join("config/locales/validation/en.yml")

params do
optional(:dsi).value(:bool)
end

rule(:dsi) do
key.failure(:missing) unless key?
end
end
2 changes: 1 addition & 1 deletion app/models/support_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# A form submission that contacts the case management team
#
class SupportRequest < ApplicationRecord
belongs_to :user
belongs_to :user, optional: true
belongs_to :category, optional: true
belongs_to :journey, optional: true
end
6 changes: 6 additions & 0 deletions app/views/fafs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render "fafs/steps/form", path: fafs_path(@faf), verb: :patch %>
</div>
</div>

41 changes: 41 additions & 0 deletions app/views/fafs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%= content_for :title, I18n.t("faf.start_page.header") %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h1 class="govuk-heading-xl"><%= I18n.t("faf.start_page.header") %></h1>

<p class="govuk-body"><%= I18n.t("faf.start_page.overview_purpose") %></p>
<p class="govuk-body"><%= I18n.t("faf.start_page.you_can_ask_for") %>:</p>

<ul class="govuk-list govuk-list--bullet">
<% I18n.t("faf.start_page.overview_category_list").each do |list_item| %>
<li><%= list_item %></li>
<% end %>
</ul>

<p class="govuk-body"><%= I18n.t("faf.start_page.overview_response") %></p>



<%= link_to new_faf_path,
class: "govuk-button govuk-!-margin-top-2 govuk-!-margin-bottom-8 govuk-button--start" do %>
<%= I18n.t("generic.button.start") %>
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z" />
</svg>
<% end %>

<h2 class="govuk-heading-m"><%= I18n.t("faf.start_page.subheading") %></h2>
<p class="govuk-body"><%= I18n.t("faf.start_page.you_can") %>:</p>

<ul class="govuk-list govuk-list--bullet">
<li>read <%= link_to "about frameworks", "https://www.gov.uk/guidance/buying-procedures-and-procurement-law-for-schools/find-the-right-way-to-buy" %></li>
<li>find out more about <%= link_to "planning for what you're buying", "https://buy-for-your-school-staging.herokuapp.com/beta/phase-6/gov/buying-for-schools" %></li>
<li>read information on <%= link_to "finding the right way to buy", "https://buy-for-your-school-staging.herokuapp.com/beta/phase-6/gov/buying-procedures-for-schools" %> for your school.</li>
<li><%= link_to "create a specification", "https://get-help-buying-for-schools.education.gov.uk/" %> if you don't have one yet</li>
</ul>



</div>
</div>
5 changes: 5 additions & 0 deletions app/views/fafs/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render "fafs/steps/form", path: fafs_path, verb: :post %>
</div>
</div>
9 changes: 9 additions & 0 deletions app/views/fafs/steps/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_with model: @faf_form, scope: :faf_form, url: path, method: verb do |form| %>
<%= form.govuk_error_summary %>

<%= form.hidden_field :step, value: @faf_form.step %>
<%= render "fafs/steps/step_#{@faf_form.step}", form: form %>

<%= form.submit I18n.t("generic.button.next"), class: "govuk-button", role: "button" %>
<% end %>

11 changes: 11 additions & 0 deletions app/views/fafs/steps/_step_1.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<span class="govuk-caption-l">
<%= I18n.t("faf.dsi_or_search.subtitle") %>
</span>
<h1 class="govuk-heading-l">
<%= I18n.t("faf.dsi_or_search.header") %>
</h1>

<%= form.govuk_radio_button :dsi, true, label: { text: I18n.t("faf.dsi_or_search.radios.dsi") } %>
<%= form.govuk_radio_button :dsi, false, label: { text: I18n.t("faf.dsi_or_search.radios.no_dsi") } %>

<br>
9 changes: 9 additions & 0 deletions app/views/fafs/steps/_step_2.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<span class="govuk-caption-l">
step 2
</span>
<h1 class="govuk-heading-l">
Step 2
</h1>


<br>
Comment thread
d-a-v-e marked this conversation as resolved.
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ en:
subheading: Before you start
you_can: You can

dsi_or_search:
header: Do you have a DfE Sign-in account linked to the school you're requesting support for?
subtitle: About your school
link_text: Create a new DfE Sign-in account
radios:
dsi: Yes, use my DfE Sign-in
no_dsi: No, continue without a DfE Sign-in account

#
# Supported ------------------------------------------------------------------
#
Expand Down
3 changes: 3 additions & 0 deletions config/locales/validation/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ en:
message_body: "" # Omitted
category_id: The type of procurement
school_urn: "" # Omitted
dsi: "" # Omitted

errors:
rules:
dsi:
missing: Select whether you want to use a DfE Sign-in account
phone_number:
missing: is missing
# format?: must start with a zero and only contain digits
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#
# FaF ------------------------------------------------------------------
#
resources :faf, only: %i[new], path: "procurement-support"
resources :fafs, except: %i[delete], path: "procurement-support"

#
# Supported ------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions spec/features/self-serve/faf/dsi_or_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
RSpec.feature "Faf - dsi or search" do
context "when the user is not signed in" do
before do
visit "/procurement-support/new"
end

it "loads the page" do
expect(find("h1")).to have_text "Do you have a DfE Sign-in account linked to the school you're requesting support for?"
end

it "errors if no selection is given" do
click_continue
expect(find(".govuk-error-summary__body")).to have_text "Select whether you want to use a DfE Sign-in account"
end
end

context "when the user is signed in" do
before do
user_is_signed_in
visit "/procurement-support/new"
end

it "loads the page" do
expect(find("h1")).to have_text "Do you have a DfE Sign-in account linked to the school you're requesting support for?"
end

it "errors if no selection is given" do
click_continue
expect(find(".govuk-error-summary__body")).to have_text "Select whether you want to use a DfE Sign-in account"
end
end
end
6 changes: 3 additions & 3 deletions spec/features/self-serve/faf/start_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.feature "Faf start page" do
RSpec.feature "Faf - start page" do
context "when the user is not signed in" do
before do
visit "/procurement-support/new"
visit "/procurement-support"
end

it "loads the page" do
Expand All @@ -12,7 +12,7 @@
context "when the user is signed in" do
before do
user_is_signed_in
visit "/procurement-support/new"
visit "/procurement-support"
end

it "loads the page" do
Expand Down