diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index e2ebc5675..f765678f6 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -2,6 +2,20 @@ @import "common"; @import "constants"; +.give-avis { + h1 { + font-size: 18px; + font-weight: bold; + margin-bottom: $default-padding; + } + + .avis-notice { + font-size: 12px; + color: $grey; + margin-bottom: 2 * $default-padding; + } +} + .ask-avis { h1 { font-size: 18px; diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index e97768f0c..ce1337f41 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -24,10 +24,25 @@ module NewGestionnaire @dossier = avis.dossier end + def instruction + @avis = avis + @dossier = avis.dossier + end + + def update + avis.update_attributes(avis_params) + flash.notice = 'Votre réponse est enregistrée.' + redirect_to instruction_avis_path(avis) + end + private def avis current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id]) end + + def avis_params + params.require(:avis).permit(:answer) + end end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index e38916596..9a01c84af 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -7,3 +7,5 @@ %ul.tabs %li{ class: current_page?(avis_path(avis)) ? 'active' : nil } = link_to 'Demande', avis_path(avis) + %li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil } + = link_to 'Instruction', instruction_avis_path(avis) diff --git a/app/views/new_gestionnaire/avis/instruction.html.haml b/app/views/new_gestionnaire/avis/instruction.html.haml new file mode 100644 index 000000000..afcf61bb9 --- /dev/null +++ b/app/views/new_gestionnaire/avis/instruction.html.haml @@ -0,0 +1,47 @@ +#avis-show + = render partial: 'header', locals: { avis: @avis, dossier: @dossier } + +.container + %section.give-avis + %h1 Donner votre avis + %p.avis-notice= "#{@avis.claimant.email}: #{@avis.introduction}" + + = form_for @avis, url: avis_path(@avis), html: { class: 'form' } do |f| + = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true + .send-wrapper + = f.submit 'Envoyer votre avis', class: 'button send' + + %section.ask-avis + %h1 Inviter une personne à donner son avis + %p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier. + + = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| + = f.email_field :email, placeholder: 'Adresse email', required: true + = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' + + - if @dossier.avis.present? + %section.list-avis + %h1.title + Avis des invités + %span.count= @dossier.avis.count + + %ul + - @dossier.avis.each do |avis| + %li.one-avis + %h2.claimant + = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email + %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} + %p= avis.introduction + + .answer.flex.align-start + %i.bubble.avis-icon + .width-100 + %h2.gestionnaire + = avis.gestionnaire.email + - if avis.answer.present? + %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} + - else + %span.waiting En attente de réponse + %p= avis.answer diff --git a/config/routes.rb b/config/routes.rb index 5026843f1..25e54394b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,7 +258,11 @@ Rails.application.routes.draw do end end end - resources :avis, only: [:index, :show] + resources :avis, only: [:index, :show, :update] do + member do + get 'instruction' + end + end get "recherche" => "recherches#index" end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index b5874754a..624730a64 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -34,4 +34,23 @@ describe NewGestionnaire::AvisController, type: :controller do it { expect(assigns(:avis)).to eq(avis_without_answer) } it { expect(assigns(:dossier)).to eq(dossier) } end + + describe '#instruction' do + before { get :instruction, { id: avis_without_answer.id } } + + it { expect(response).to have_http_status(:success) } + it { expect(assigns(:avis)).to eq(avis_without_answer) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + + describe '#update' do + before do + patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } } + avis_without_answer.reload + end + + it { expect(response).to redirect_to(instruction_avis_path(avis_without_answer)) } + it { expect(avis_without_answer.answer).to eq('answer') } + it { expect(flash.notice).to eq('Votre réponse est enregistrée.') } + end end