refactor(invites): use turbo

This commit is contained in:
Paul Chavard 2022-05-24 11:59:14 +02:00
parent 480c51cc80
commit 5ddda15961
7 changed files with 17 additions and 20 deletions

View file

@ -4,10 +4,10 @@ class InvitesController < ApplicationController
def create
email = params[:invite_email].downcase
dossier = current_user.dossiers.visible_by_user.find(params[:dossier_id])
@dossier = current_user.dossiers.visible_by_user.find(params[:dossier_id])
invite = Invite.create(
dossier: dossier,
dossier: @dossier,
user: User.find_by(email: email),
email: email,
message: params[:invite_message],
@ -22,23 +22,18 @@ class InvitesController < ApplicationController
end
respond_to do |format|
format.html { redirect_back(fallback_location: helpers.url_for_dossier(dossier)) }
format.js { @dossier = dossier }
format.html { redirect_back(fallback_location: helpers.url_for_dossier(@dossier)) }
format.turbo_stream
end
end
def show
if user_signed_in?
erase_user_location!
dossier = Dossier.joins(:invites)
.find_by!(invites: { email: current_user.email, id: params[:id] })
if dossier.brouillon?
redirect_to brouillon_dossier_path(dossier)
else
redirect_to dossier_path(dossier)
end
redirect_to helpers.url_for_dossier(dossier)
elsif params[:email].present? && !User.find_by(email: params[:email])
redirect_to new_user_registration_path(user: { email: params[:email] })
else
@ -51,8 +46,9 @@ class InvitesController < ApplicationController
def destroy
invite = Invite.find(params[:id])
dossier = invite.dossier
if dossier.user == current_user
@dossier = invite.dossier
if @dossier.user == current_user
invite.destroy!
flash.notice = "Lautorisation de #{invite.email} vient dêtre révoquée."
else
@ -60,8 +56,8 @@ class InvitesController < ApplicationController
end
respond_to do |format|
format.html { redirect_back(fallback_location: helpers.url_for_dossier(dossier)) }
format.js { @dossier = dossier }
format.html { redirect_back(fallback_location: helpers.url_for_dossier(@dossier)) }
format.turbo_stream
end
end

View file

@ -5,7 +5,8 @@
- dossier.invites.each do |invite|
%li
= invite.email
%small= link_to(t('views.invites.form.withdraw_permission'), invite_path(invite), data: { confirm: t('views.invites.form.want_to_withdraw_permission') }, method: :delete, remote: true)
%small{ 'data-turbo': 'true' }
= link_to t('views.invites.form.withdraw_permission'), invite_path(invite), data: { turbo_method: :delete, turbo_confirm: t('views.invites.form.want_to_withdraw_permission') }
%p= t('views.invites.form.edit_dossier')
- if dossier.brouillon?
%p= t('views.invites.form.submit_dossier_yourself')
@ -14,7 +15,7 @@
%p= t('views.invites.form.invite_to_edit_line1')
%p= t('views.invites.form.invite_to_edit_line2')
= form_tag dossier_invites_path(dossier), remote: true, method: :post, class: 'form' do
= form_tag dossier_invites_path(dossier), data: { turbo: true }, method: :post, class: 'form' do
.row
.col
%span

View file

@ -1,2 +0,0 @@
<%= render_to_element('#invites-form', partial: 'invites/form', locals: { dossier: @dossier }, outer: true) %>
<%= render_flash %>

View file

@ -1 +0,0 @@
<%= render 'redraw' %>

View file

@ -0,0 +1,2 @@
= turbo_stream.replace_all '.invite-user-action', partial: 'invites/dropdown', locals: { dossier: @dossier }
= turbo_stream.focus_all '.invite-user-action > button'

View file

@ -1 +0,0 @@
<%= render 'redraw' %>

View file

@ -0,0 +1,2 @@
= turbo_stream.replace_all '.invite-user-action', partial: 'invites/dropdown', locals: { dossier: @dossier }
= turbo_stream.focus_all '.invite-user-action > button'