diff --git a/app/assets/svg/icons/lucide/outline/chevron-left.svg b/app/assets/svg/icons/lucide/outline/chevron-left.svg new file mode 100644 index 00000000..47bdb982 --- /dev/null +++ b/app/assets/svg/icons/lucide/outline/chevron-left.svg @@ -0,0 +1 @@ + diff --git a/app/assets/svg/icons/lucide/outline/chevron-right.svg b/app/assets/svg/icons/lucide/outline/chevron-right.svg new file mode 100644 index 00000000..4c0ff5ee --- /dev/null +++ b/app/assets/svg/icons/lucide/outline/chevron-right.svg @@ -0,0 +1 @@ + diff --git a/app/controllers/family_invitations_controller.rb b/app/controllers/family_invitations_controller.rb index 80634dc4..65193987 100644 --- a/app/controllers/family_invitations_controller.rb +++ b/app/controllers/family_invitations_controller.rb @@ -78,17 +78,19 @@ class FamilyInvitationsController < ApplicationController def destroy authorize @family, :manage_invitations? - if @invitation.update(status: :cancelled) + begin + if @invitation.update(status: :cancelled) + redirect_to family_path(@family), + notice: 'Invitation cancelled' + else + redirect_to family_path(@family), + alert: 'Failed to cancel invitation. Please try again' + end + rescue StandardError => e + Rails.logger.error "Error cancelling family invitation: #{e.message}" redirect_to family_path(@family), - notice: 'Invitation cancelled' - else - redirect_to family_path(@family), - alert: 'Failed to cancel invitation. Please try again' + alert: 'An unexpected error occurred while cancelling the invitation' end - rescue StandardError => e - Rails.logger.error "Error cancelling family invitation: #{e.message}" - redirect_to family_path(@family), - alert: 'An unexpected error occurred while cancelling the invitation' end private diff --git a/app/services/families/leave.rb b/app/services/families/leave.rb index 59b53eda..7adcb8c6 100644 --- a/app/services/families/leave.rb +++ b/app/services/families/leave.rb @@ -12,10 +12,14 @@ module Families def call return false unless validate_can_leave + # Store family info before removing membership + @family_name = user.family.name + @family_owner = user.family.owner + ActiveRecord::Base.transaction do handle_ownership_transfer if user.family_owner? remove_membership - send_notification + send_notifications end true @@ -68,18 +72,26 @@ module Families user.family_membership.destroy! end - def send_notification + def send_notifications return unless defined?(Notification) + # Notify the user who left Notification.create!( user: user, kind: :info, title: 'Left Family', - content: "You've left the family" + content: "You've left the family \"#{@family_name}\"" + ) + + # Notify the family owner + return unless @family_owner&.persisted? + + Notification.create!( + user: @family_owner, + kind: :info, + title: 'Family Member Left', + content: "#{user.email} has left the family \"#{@family_name}\"" ) - rescue StandardError => e - # Don't fail the entire operation if notification fails - Rails.logger.warn "Failed to send family leave notification: #{e.message}" end def handle_record_invalid_error(error) diff --git a/app/views/families/edit.html.erb b/app/views/families/edit.html.erb index dbd28303..e9f6e4ff 100644 --- a/app/views/families/edit.html.erb +++ b/app/views/families/edit.html.erb @@ -88,7 +88,7 @@ method: :delete, data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' }, class: "btn btn-outline btn-error" do %> - <%= icon 'trash-2', class: "inline-block w-4 h-4 mr-2 -mt-1" %> + <%= icon 'trash-2', class: "inline-block w-4" %> Delete Family <% end %> <% end %> diff --git a/app/views/families/show.html.erb b/app/views/families/show.html.erb index 408085d5..a47c1e9a 100644 --- a/app/views/families/show.html.erb +++ b/app/views/families/show.html.erb @@ -17,8 +17,7 @@ <% if policy(@family).update? %> <%= link_to edit_family_path(@family), class: "btn btn-outline btn-info" do %> - <%= icon 'square-pen', class: "inline-block w-4 h-4 mr-2 -mt-1" %> - <%= t('families.show.edit', default: 'Edit') %> + <%= icon 'square-pen', class: "inline-block w-4" %><%= t('families.show.edit', default: 'Edit') %> <% end %> <% end %> @@ -36,7 +35,7 @@ method: :delete, data: { confirm: 'Are you sure you want to delete this family? This action cannot be undone.', turbo_confirm: 'Are you sure you want to delete this family? This action cannot be undone.' }, class: "btn btn-outline btn-error" do %> - <%= icon 'trash-2', class: "inline-block w-4 h-4 mr-2 -mt-1" %> + <%= icon 'trash-2', class: "inline-block w-4" %> Delete <% end %> <% end %> diff --git a/app/views/map/index.html.erb b/app/views/map/index.html.erb index b28d5b95..3f7e3046 100644 --- a/app/views/map/index.html.erb +++ b/app/views/map/index.html.erb @@ -9,7 +9,7 @@