Skip to content

Commit

Permalink
feat: add Quote profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasleger committed Nov 26, 2024
1 parent 0a83ff2 commit 33e5959
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/controllers/quotes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Controller for the Quotes resource
class QuotesController < ApplicationController
PROFILES = %i[artisan particulier mandataire conseiller].freeze

before_action :set_profile, only: %i[check]

def check
@quote_attributes = if params[:quote_file].present?
file_to_attributes(params[:quote_file])
Expand All @@ -15,8 +19,16 @@ def check
@quote_errors = [e.message]
end

def profiles
@profiles = PROFILES
end

protected

def set_profile
@profile ||= PROFILES.detect { |profile| profile == params[:profile].to_sym } if params[:profile]
end

def quote_fields
quote_validation = QuoteValidator::Global.new({})
quote_validation.validate!
Expand Down
4 changes: 2 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<h1>Prévalidation des devis</h1>

<p>
<%= link_to check_quotes_path, class: "fr-btn fr-btn--secondary fr-btn--lg" do %>
Vérifier un devis
<%= link_to profiles_path, class: "fr-btn fr-btn--secondary fr-btn--lg" do %>
<% t '.quote_check_cta' %>
<% end %>
</p>

Expand Down
3 changes: 1 addition & 2 deletions app/views/quotes/check.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<%# TODO: Form with file upload %>

<h1>Fichier du Devis :</h1>
<%= form_tag check_quotes_path, multipart: true do %>
<%= file_field_tag :quote_file %>
<%= hidden_field_tag :profile, @profile %>
<%= submit_tag "Vérifier", class: "fr-btn fr-btn--primary fr-btn--lg" %>
<% end %>

Expand Down
6 changes: 6 additions & 0 deletions app/views/quotes/profiles.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Vous êtes :</h1>
<ul>
<% @profiles.each do |profile| %>
<li><%= link_to t(".#{profile}"), check_quotes_path(profile: profile) %></li>
<% end %>
</ul>
10 changes: 10 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ fr:
sponsor: "Ministère\nde la transition\nécologique"
service_name: "Mon Devis Sans Oublis"
service_description: "La plateforme de pré-vérification des devis"
home:
index:
quote_check_cta: "Vérifier mon devis"
quotes:
profiles:
title:
artisan: Artisan
particulier: Particulier
mandataire: Mandataire
conseiller: Conseiller
14 changes: 11 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
# Defines the root path route ("/")
# root "articles#index"

root "home#index"
# Quotes

resources :quotes, only: [] do
get "profiles", to: "quotes#profiles"
resources :quotes, only: [], path: "" do
collection do
match :check, via: %i[get post], as: :check
match ":profile/devis/verifier",
to: "quotes#check",
via: %i[get post],
as: :check,
constraints: { profile: /#{QuotesController::PROFILES.join('|')}/ }
end
end

# Website static pages

root "home#index"

get "a_propos", to: "pages#a_propos"
get "contact", to: "pages#contact"
end

0 comments on commit 33e5959

Please sign in to comment.