Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
41 changes: 37 additions & 4 deletions app/controllers/fafs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
class FafsController < ApplicationController
skip_before_action :authenticate_user!
before_action :faf, only: %i[show edit update]
before_action :faf_form, only: %i[create update]
before_action :faf_presenter, only: %i[show]

def index; end

def show; end
# check answers before submission
def show
if @faf.submitted?
# TODO: redirect to faf_submissions_controller
end
end

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

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

def edit
@faf_form = FafForm.new(step: params[:step], **@faf.to_h)
end

def update
if validation.success?
@faf.update!(**@faf.to_h, **@faf_form.to_h)
redirect_to faf_path(params[:id])
else
render :edit
end
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)
def faf_form
@faf_form = FafForm.new(
step: form_params[:step],
messages: validation.errors(full: true).to_h,
**validation.to_h,
)
end

def form_params
Expand All @@ -30,4 +54,13 @@ def form_params
def validation
FafFormSchema.new.call(**form_params)
end

def faf_presenter
@faf_presenter = FafPresenter.new(@faf)
end

# @return [FrameworkRequest]
def faf
@faf = FrameworkRequest.find(params[:id])
end
end
3 changes: 3 additions & 0 deletions app/models/framework_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class FrameworkRequest < ApplicationRecord
validates :first_name, :last_name, :email, :school_urn, :message_body, presence: true
end
11 changes: 11 additions & 0 deletions app/presenters/faf_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class FafPresenter < BasePresenter
# @return [String]
def full_name
"#{first_name} #{last_name}"
end

# @return [String]
def school_name
Support::Organisation.find_by(urn: school_urn)&.name || "n/a"
end
end
60 changes: 60 additions & 0 deletions app/views/fafs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<h1 class="govuk-heading-l"><%= I18n.t("faf.check_answers.header") %></h1>

<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.check_answers.details.name") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @faf_presenter.full_name %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to I18n.t("generic.button.change_answer"), edit_faf_path(@faf, step: 0), class: "govuk-link", id: "edit-name" %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.check_answers.details.email") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @faf_presenter.email %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to I18n.t("generic.button.change_answer"), edit_faf_path(@faf, step: 0), class: "govuk-link", id: "edit-email" %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.check_answers.details.school") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @faf_presenter.school_name %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to I18n.t("generic.button.change_answer"), edit_faf_path(@faf, step: 0), class: "govuk-link", id: "edit-school" %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.check_answers.details.problem") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @faf_presenter.message_body %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to I18n.t("generic.button.change_answer"), edit_faf_path(@faf, step: 0), class: "govuk-link", id: "edit-message" %>
</dd>
</div>
</dl>

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

<%= button_to I18n.t("faf.check_answers.button.send"), faf_submission_path(@faf), class: "govuk-button", method: :patch, data: { disable_with: "Submitting..." } %>

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

<br>
<%= content_for :title, I18n.t("faf.contact_info.title") %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l"><%= I18n.t("faf.contact_info.caption") %></span>
<h1 class="govuk-heading-l"><%= I18n.t("faf.contact_info.heading") %></h1>
<p class="govuk-body"><%= I18n.t("faf.contact_info.body.if_incorrect") %></p>

<ul class="govuk-list govuk-list--bullet">
<li><%= I18n.t("faf.contact_info.body.login_correct_account") %></li>
<li><%= link_to I18n.t("faf.contact_info.body.amend_details"), dsi_url(subdomain: "profile", path: "/edit-details"), class: "govuk-link" %></li>
</ul>

<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.contact_info.body.description_list.name") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @current_user.full_name if @current_user %>
</dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("faf.contact_info.body.description_list.email") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @current_user.email if @current_user %>
</dd>
</div>
</dl>

<%= form.submit I18n.t("faf.contact_info.button.continue"), class: "govuk-button", role: "button" %>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, although is there perhaps some value in creating some logic in the _form.html.erb as a conditional for which button type to display, to prevent duplication across the step pages?

</div>
</div>
8 changes: 8 additions & 0 deletions app/views/fafs/steps/_step_3.hml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="govuk-caption-l">
step 3
</span>
<h1 class="govuk-heading-l">
Step 3
</h1>

<br>
27 changes: 27 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ en:
subheading: Before you start
you_can: You can

contact_info:
title: Is this your contact information? - Get help buying for schools - GOV.UK
caption: About you
heading: Is this your contact information?
body:
if_incorrect: "If these details are not correct, you can either:"
login_correct_account: log in with the correct account, or
amend_details: amend your DfE Sign-in account details
description_list:
name: Name
email: Email address
button:
continue: Yes, continue

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
Expand All @@ -299,6 +313,19 @@ en:
dsi: Yes, use my DfE Sign-in
no_dsi: No, continue without a DfE Sign-in account

check_answers:
header: Send your request
sent: Your request has been submitted
response_time: Once you send this request, we will review it and get in touch within 2 working days.
button:
send: Send request
details:
name: Your name
email: Your email address
school: Your school
problem: Description of problem


#
# Supported ------------------------------------------------------------------
#
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
end

#
# FaF ------------------------------------------------------------------
# Framework Requests ------------------------------------------------------------------
#
resources :fafs, except: %i[delete], path: "procurement-support"
resources :faf_submission, only: %i[update show], path: "procurement-support-submissions"

#
# Supported ------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20220118122456_create_framework_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateFrameworkRequests < ActiveRecord::Migration[6.1]
def change
create_table :framework_requests, id: :uuid do |t|
t.timestamps

t.string :first_name
t.string :last_name
t.string :email
t.string :school_urn
t.string :message_body
t.boolean :submitted, default: false
end
end
end
20 changes: 15 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_01_17_121023) do

ActiveRecord::Schema.define(version: 2022_01_18_122456) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -73,7 +72,7 @@
t.datetime "created_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.integer "journeys_count"
t.string "slug"
t.string "slug", null: false
t.index ["contentful_id"], name: "index_categories_on_contentful_id", unique: true
end

Expand All @@ -95,6 +94,17 @@
t.index ["step_id"], name: "index_currency_answers_on_step_id"
end

create_table "framework_requests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "school_urn"
t.string "message_body"
t.boolean "submitted", default: false
end

create_table "journeys", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
Expand Down Expand Up @@ -232,12 +242,12 @@
t.uuid "organisation_id"
t.uuid "existing_contract_id"
t.uuid "new_contract_id"
t.uuid "procurement_id"
t.integer "savings_status"
t.integer "savings_estimate_method"
t.integer "savings_actual_method"
t.decimal "savings_estimate", precision: 9, scale: 2
t.decimal "savings_actual", precision: 9, scale: 2
t.uuid "procurement_id"
t.index ["category_id"], name: "index_support_cases_on_category_id"
t.index ["existing_contract_id"], name: "index_support_cases_on_existing_contract_id"
t.index ["new_contract_id"], name: "index_support_cases_on_new_contract_id"
Expand All @@ -255,7 +265,7 @@
t.string "slug"
t.string "description"
t.uuid "parent_id"
t.index ["slug"], name: "index_support_categories_on_slug"
t.index ["slug"], name: "index_support_categories_on_slug", unique: true
t.index ["title", "parent_id"], name: "index_support_categories_on_title_and_parent_id", unique: true
end

Expand Down
10 changes: 10 additions & 0 deletions spec/factories/framework_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryBot.define do
factory :framework_request do
first_name { "David" }
last_name { "Georgiou" }
school_urn { "000001" }
email { "email@example.com" }
message_body { "please help!" }
submitted { false }
end
end
22 changes: 22 additions & 0 deletions spec/features/self-serve/faf/check_your_answers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
RSpec.feature "FaF - check your answers" do
before do
faf = create(:framework_request)
visit "/procurement-support/#{faf.id}"
end

context "when the user is not signed in" do
it "loads the page" do
expect(find("h1")).to have_text "Send your request"
end
end

context "when the user is signed in" do
before do
user_is_signed_in
end

it "loads the page" do
expect(find("h1")).to have_text "Send your request"
end
end
end
11 changes: 11 additions & 0 deletions spec/models/self-serve/framework_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "rails_helper"

RSpec.describe FrameworkRequest, type: :model do
describe "validations" do
it { is_expected.to validate_presence_of(:first_name) }
it { is_expected.to validate_presence_of(:last_name) }
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_presence_of(:school_urn) }
it { is_expected.to validate_presence_of(:message_body) }
end
end