Skip to content

Commit

Permalink
render with turbo after send solicitation email
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMLD committed Dec 18, 2024
1 parent 1d9011a commit d42e48d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
8 changes: 4 additions & 4 deletions app/controllers/conseiller/solicitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def index
end

def processed
@solicitations = ordered_solicitations(:processed)
@solicitations = ordered_solicitations(:processed, :desc)
@facilities = get_and_format_facilities
@status = t('solicitations.header.processed')
render :index
end

def canceled
@solicitations = ordered_solicitations(:canceled)
@solicitations = ordered_solicitations(:canceled, :desc)
@facilities = get_and_format_facilities
@status = t('solicitations.header.canceled')
render :index
Expand Down Expand Up @@ -92,13 +92,13 @@ def mark_as_spam

private

def ordered_solicitations(status)
def ordered_solicitations(status, order = :asc)
Solicitation
.includes(:badge_badgeables, :badges, :landing, :diagnosis, :facility, feedbacks: { user: :antenne },
landing_subject: :subject, institution: :logo, subject_answers: :subject_question)
.where(status: status)
.apply_filters(index_search_params)
.order(:completed_at)
.order(completed_at: order)
.page(params[:page])
end

Expand Down
15 changes: 14 additions & 1 deletion app/controllers/emails/solicitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ def send_generic_email
if processor.valid?
processor.send_email
flash.notice = t('emails.sent')
render_turbo_stream_or_html
else
flash.alert = t('emails.not_sent')
render_turbo_stream_or_html(status: :unprocessable_entity)
end
redirect_to conseiller_solicitations_path(query: params[:query])
end

private

def render_turbo_stream_or_html(status: :ok)
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.remove(@solicitation),
turbo_stream.append('flash', partial: 'shared/flashes', locals: { flash: flash })
], status: status, layout: false
end
format.html { redirect_to conseiller_solicitations_path(query: params[:query]) }
end
end

def authorize_index_solicitation
authorize Solicitation, :index?
end
Expand Down
5 changes: 2 additions & 3 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
= render 'user_impersonate'
%main#content{ role: 'main' }
-# ajout d'un id pour turbo_stream
#flash
= render 'shared/flashes'
= render 'shared/flashes'
.fr-pt-5w
= content_for?(:content) ? yield(:content) : yield # :content is used by sub-layouts (e.g. side_menu)
- if user_signed_in?
Expand Down
25 changes: 13 additions & 12 deletions app/views/shared/_flashes.html.haml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
- if flash.present?
.fr-container.fr-mt-6v.fr-mb-1w
- flash.each do |type, message|
- case type
- when 'notice'
.fr-alert.fr-alert--success{ role: "alert" }
%h2.fr-alert__title
= message.html_safe
- when 'alert'
.fr-alert.fr-alert--error{ role: "alert" }
%h2.fr-alert__title
= message.html_safe
= turbo_frame_tag 'flash' do
- if flash.present?
.fr-container.fr-mt-6v.fr-mb-1w
- flash.each do |type, message|
- case type
- when 'notice'
.fr-alert.fr-alert--success{ role: "alert" }
%h2.fr-alert__title
= message.html_safe
- when 'alert'
.fr-alert.fr-alert--error{ role: "alert" }
%h2.fr-alert__title
= message.html_safe

0 comments on commit d42e48d

Please sign in to comment.