diff --git a/app/models/import.rb b/app/models/import.rb index 04a9b09e..314091fe 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -113,8 +113,12 @@ class Import < ApplicationRecord cleaned? && mappings.all?(&:valid?) end + def has_unassigned_account? + mappings.accounts.where(key: "").any? + end + def requires_account? - family.accounts.empty? && mappings.accounts.where(key: "").any? + family.accounts.empty? && has_unassigned_account? end private diff --git a/app/views/import/confirms/_mappings.html.erb b/app/views/import/confirms/_mappings.html.erb index 1c798931..75f50532 100644 --- a/app/views/import/confirms/_mappings.html.erb +++ b/app/views/import/confirms/_mappings.html.erb @@ -3,12 +3,20 @@ <% mappings = mapping_class.for_import(import) %> <% is_last_step = step_idx == import.mapping_steps.count - 1 %> -<% if import.requires_account? && mapping_class == Import::AccountMapping %> -
- <%= tag.p t(".no_accounts"), class: "text-sm" %> +<% if mapping_class == Import::AccountMapping %> + <% if import.requires_account? %> +
+ <%= tag.p t(".no_accounts"), class: "text-sm" %> - <%= link_to t(".create_account"), new_account_path, class: "btn btn--primary whitespace-nowrap", data: { turbo_frame: :modal } %> -
+ <%= link_to t(".create_account"), new_account_path, class: "btn btn--primary whitespace-nowrap", data: { turbo_frame: :modal } %> +
+ <% elsif import.has_unassigned_account? %> +
+ <%= tag.p t(".unassigned_account"), class: "text-sm" %> + + <%= link_to t(".create_account"), new_account_path, class: "btn btn--primary whitespace-nowrap", data: { turbo_frame: :modal } %> +
+ <% end %> <% end %>
diff --git a/config/locales/views/imports/en.yml b/config/locales/views/imports/en.yml index 85bebab8..7227a9f2 100644 --- a/config/locales/views/imports/en.yml +++ b/config/locales/views/imports/en.yml @@ -18,6 +18,7 @@ en: no_accounts: You don't have any accounts yet. Please create an account that we can use for (unassigned) rows in your CSV or go back to the Clean step and provide an account name we can use. + unassigned_account: Need to create a new account for unassigned rows? rows_label: Rows show: account_mapping_description: Assign all of your imported file's accounts to