Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
12.0 KB
Raw Blame
<%= render DS::Dialog.new do |dialog| %>
  <% dialog.with_header(title: t(".title"), subtitle: t(".description")) %>

  <% dialog.with_body do %>
    <% has_accounts = accessible_accounts.any? %>
    <% requires_account_message = t(".requires_account") %>

    <% if @pending_import.present? && params[:type].nil? %>
      <div class="rounded-xl bg-container-inset p-1 mb-4">
        <ul class="bg-container shadow-border-xs rounded-lg">
          <li>
            <%= 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>
        </ul>
      </div>
    <% end %>

    <%
      financial_tool_types = %w[MintImport ActualImport YnabImport MonarchImport QifImport SureImport DocumentImport PdfImport]
      import_type = params[:type].presence || @pending_import&.type
      active_tab = import_type.present? && !import_type.in?(financial_tool_types) ? "raw_data" : "financial_tools"
    %>
    <%= render DS::Tabs.new(active_tab: active_tab) do |tabs| %>
      <% tabs.with_nav do |nav| %>
        <% nav.with_btn(id: "financial_tools", label: t(".tab_financial_tools")) %>
        <% nav.with_btn(id: "raw_data", label: t(".tab_raw_data")) %>
      <% end %>

      <% tabs.with_panel(tab_id: "financial_tools") do %>
        <div class="rounded-xl bg-container-inset p-1">
          <ul class="bg-container shadow-border-xs rounded-lg">
            <% if @pending_import.present? && params[:type].present? && params[:type].in?(financial_tool_types) %>
              <li>
                <%= 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] == "SureImport") && !Current.user&.guest? %>
              <li>
                <%= styled_form_with url: imports_path, scope: :import, multipart: true, class: "w-full", data: { turbo_frame: "_top", controller: "auto-submit-form" } do |form| %>
                  <%= form.hidden_field :type, value: "SureImport" %>
                  <label class="flex items-center justify-between p-4 group cursor-pointer w-full">
                    <div class="flex items-center gap-2">
                      <div class="bg-cyan-500/5 rounded-md w-8 h-8 flex items-center justify-center">
                        <span class="text-cyan-500">
                          <%= icon("file-braces", color: "current") %>
                        </span>
                      </div>
                      <div class="text-left">
                        <span class="text-sm text-primary group-hover:text-secondary block">
                          <%= t(".import_sure") %>
                        </span>
                        <span class="text-xs text-secondary">
                          <%= t(".import_sure_description") %>
                        </span>
                      </div>
                    </div>
                    <%= icon("chevron-right") %>
                    <%= form.file_field :import_file, accept: ".ndjson,.json", class: "hidden", data: { auto_submit_form_target: "auto", autosubmit_trigger_event: "change" } %>
                  </label>
                <% end %>

                <%= render "shared/ruler" %>
              </li>
            <% 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: true %>
            <% end %>

            <% if params[:type].nil? || params[:type] == "ActualImport" %>
              <%= render "imports/import_option",
                type: "ActualImport",
                icon_name: "wallet",
                icon_bg_class: "bg-emerald-500/5",
                icon_text_class: "text-emerald-500",
                label: t(".import_actual"),
                enabled: true %>
            <% end %>

            <% if params[:type].nil? || params[:type] == "QifImport" %>
              <%= render "imports/import_option",
                type: "QifImport",
                icon_name: "file-clock",
                icon_bg_class: "bg-teal-500/5",
                icon_text_class: "text-teal-500",
                label: t(".import_qif"),
                enabled: true %>
            <% end %>

            <% if params[:type].nil? || params[:type] == "YnabImport" %>
              <%= render "imports/import_option",
                type: "YnabImport",
                image: "ynab-logo.png",
                label: t(".import_ynab"),
                enabled: true %>
            <% end %>

            <% if (params[:type].nil? || params[:type] == "MonarchImport") && !Current.user&.guest? %>
              <%= render "imports/import_option",
                type: "MonarchImport",
                image: "monarch-logo.png",
                label: t(".import_monarch"),
                enabled: true %>
            <% 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", data: { turbo_frame: "_top", controller: "auto-submit-form" } 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", data: { auto_submit_form_target: "auto", autosubmit_trigger_event: "change" } %>
                  </label>
                <% end %>

                <%= render "shared/ruler" %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>

      <% tabs.with_panel(tab_id: "raw_data") do %>
        <div class="rounded-xl bg-container-inset p-1">
          <ul class="bg-container shadow-border-xs rounded-lg">
            <% if @pending_import.present? && params[:type].present? && !params[:type].in?(financial_tool_types) %>
              <li>
                <%= 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: !Current.user&.guest?,
                disabled_message: t("shared.require_non_guest") %>
            <% end %>

            <% if params[:type].nil? || params[:type] == "MerchantImport" %>
              <%= render "imports/import_option",
                type: "MerchantImport",
                icon_name: "store",
                icon_bg_class: "bg-orange-500/5",
                icon_text_class: "text-orange-500",
                label: t(".import_merchants"),
                enabled: !Current.user&.guest?,
                disabled_message: t("shared.require_non_guest") %>
            <% 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: !Current.user&.guest?,
                disabled_message: t("shared.require_non_guest") %>
            <% end %>
          </ul>
        </div>
      <% end %>
    <% end %>
  <% end %>
<% end %>