diff --git a/app/commands/add_user_to_company.rb b/app/commands/add_user_to_company.rb index e2bc6a91..bb46b3d0 100644 --- a/app/commands/add_user_to_company.rb +++ b/app/commands/add_user_to_company.rb @@ -2,7 +2,10 @@ class AddUserToCompany - attr_accessor :user + attr_accessor :user, :membership + attr_reader :errors + + class InvalidArguments < StandardError; end def initialize(email:, name:, role: "member", company:) @email = email @@ -12,8 +15,10 @@ def initialize(email:, name:, role: "member", company:) end def call - find_or_create_user - add_user_to_company + User.transaction do + find_or_create_user + add_user_to_company + end @user end @@ -25,10 +30,12 @@ def find_or_create_user user.name = @name user.current_company = @company end + + @user.save! end def add_user_to_company - @company.memberships.build(user: @user, role: @role, status: 'active') - @company.save! + @membership = @company.memberships.build(user: @user, role: @role, status: 'active') + @membership.save! end end \ No newline at end of file diff --git a/app/components/settings/tabs_component.html.erb b/app/components/settings/tabs_component.html.erb index ecffd362..4617ac37 100644 --- a/app/components/settings/tabs_component.html.erb +++ b/app/components/settings/tabs_component.html.erb @@ -1,15 +1,23 @@ -
-
- - +
+
+
+ <%= action_buttons %> +
-