Files
sure/app/views/imports/new.html.erb
Juan José Mata 8264943f23 Show disabled import options when no accounts exist (#977)
* Show disabled import options before accounts exist

Keep account-dependent import choices visible on /imports/new and render them as disabled with guidance when no accounts are available.

* Refactor disabled import options: extract partial, fix accessibility (#986)

- Extract _import_option partial to eliminate duplicated enabled/disabled
  markup across TransactionImport, TradeImport, and MintImport (also
  used by AccountImport, CategoryImport, RuleImport for consistency)
- Replace misleading chevron-right with lock icon in disabled state
- Add aria-disabled="true" for screen reader accessibility
- Remove redundant default: parameter from t() call
- Fix locale key ordering (requires_account after import_* keys)
- Fix extra blank line in test file
- Add assertion for aria-disabled attribute in test

https://claude.ai/code/session_016j9tDYEBfWX9Dzd99rAYjX

Co-authored-by: Claude <noreply@anthropic.com>

* Tailwind fixes

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-14 01:10:25 +01:00

124 lines
5.1 KiB
Plaintext

<%= render DS::Dialog.new do |dialog| %>
<% dialog.with_header(title: t(".title"), subtitle: t(".description")) %>
<% dialog.with_body do %>
<% has_accounts = Current.family.accounts.any? %>
<% requires_account_message = t(".requires_account") %>
<div class="rounded-xl bg-container-inset p-1">
<h3 class="uppercase text-secondary text-xs font-medium px-3 py-1.5"><%= t(".sources") %></h3>
<ul class="bg-container shadow-border-xs rounded-lg">
<li>
<% if @pending_import.present? && (params[:type].nil? || params[:type] == @pending_import.type) %>
<%= link_to import_path(@pending_import), class: "flex items-center justify-between p-4 group cursor-pointer", data: { turbo: false } do %>
<div class="flex items-center gap-2">
<div class="bg-orange-500/5 rounded-md w-8 h-8 flex items-center justify-center">
<span class="text-orange-500">
<%= icon("loader", color: "current") %>
</span>
</div>
<span class="text-sm text-primary group-hover:text-secondary">
<%= t(".resume", type: @pending_import.type.titleize) %>
</span>
</div>
<%= icon("chevron-right") %>
<% end %>
<%= render "shared/ruler" %>
</li>
<% end %>
<% if params[:type].nil? || params[:type] == "TransactionImport" %>
<%= render "imports/import_option",
type: "TransactionImport",
icon_name: "file-spreadsheet",
icon_bg_class: "bg-indigo-500/5",
icon_text_class: "text-indigo-500",
label: t(".import_transactions"),
enabled: has_accounts,
disabled_message: requires_account_message %>
<% end %>
<% if params[:type].nil? || params[:type] == "TradeImport" %>
<%= render "imports/import_option",
type: "TradeImport",
icon_name: "square-percent",
icon_bg_class: "bg-yellow-500/5",
icon_text_class: "text-yellow-500",
label: t(".import_portfolio"),
enabled: has_accounts,
disabled_message: requires_account_message %>
<% end %>
<% if params[:type].nil? || params[:type] == "AccountImport" %>
<%= render "imports/import_option",
type: "AccountImport",
icon_name: "building",
icon_bg_class: "bg-violet-500/5",
icon_text_class: "text-violet-500",
label: t(".import_accounts"),
enabled: true %>
<% end %>
<% if params[:type].nil? || params[:type] == "CategoryImport" %>
<%= render "imports/import_option",
type: "CategoryImport",
icon_name: "shapes",
icon_bg_class: "bg-blue-500/5",
icon_text_class: "text-blue-500",
label: t(".import_categories"),
enabled: true %>
<% end %>
<% if params[:type].nil? || params[:type] == "RuleImport" %>
<%= render "imports/import_option",
type: "RuleImport",
icon_name: "workflow",
icon_bg_class: "bg-green-500/5",
icon_text_class: "text-green-500",
label: t(".import_rules"),
enabled: true %>
<% end %>
<% if params[:type].nil? || params[:type] == "MintImport" || params[:type] == "TransactionImport" %>
<%= render "imports/import_option",
type: "MintImport",
image: "mint-logo.jpeg",
label: t(".import_mint"),
enabled: has_accounts,
disabled_message: requires_account_message %>
<% end %>
<% if (params[:type].nil? || params[:type].in?(%w[DocumentImport PdfImport])) && @document_upload_extensions.any? %>
<li>
<%= styled_form_with url: imports_path, scope: :import, multipart: true, class: "w-full" do |form| %>
<%= form.hidden_field :type, value: "DocumentImport" %>
<label class="flex items-center justify-between p-4 group cursor-pointer w-full">
<div class="flex items-center gap-2">
<div class="bg-red-500/5 rounded-md w-8 h-8 flex items-center justify-center">
<span class="text-red-500">
<%= icon("file-text", color: "current") %>
</span>
</div>
<div class="text-left">
<span class="text-sm text-primary group-hover:text-secondary block">
<%= t(".import_file") %>
</span>
<span class="text-xs text-secondary">
<%= t(".import_file_description") %>
</span>
</div>
</div>
<%= icon("chevron-right") %>
<%= form.file_field :import_file, accept: @document_upload_extensions.join(","), class: "hidden", onchange: "this.form.submit()" %>
</label>
<% end %>
<%= render "shared/ruler" %>
</li>
<% end %>
</ul>
</div>
<% end %>
<% end %>