Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
3.1 KB
Raw Blame
<%
  # Parameters:
  # - configuration: Provider::Configurable::Configuration object
  # - provider_setup_encryption_warning: whether to warn before saving credentials
  provider_key = configuration.provider_key.to_s

  setup_steps_data =
    if %w[plaid plaid_eu].include?(provider_key)
      plaid_link = link_to("Plaid Dashboard", "https://dashboard.plaid.com/team/keys", target: "_blank", rel: "noopener noreferrer", class: "text-link underline")
      step_1_key = "settings.providers.#{provider_key}_panel.step_1_html"
      [
        t(step_1_key, link: plaid_link),
        t("settings.providers.plaid_panel.step_2"),
        t("settings.providers.plaid_panel.step_3")
      ]
    end
%>

<div class="space-y-4">
  <% if local_assigns[:provider_setup_encryption_warning] %>
    <%= render DS::Alert.new(
          variant: :warning,
          title: t("settings.providers.provider_setup_encryption_warning.title")
        ) do %>
      <p><%= t("settings.providers.provider_setup_encryption_warning.message") %></p>
      <%= render "settings/encryption_migration_guide" %>
    <% end %>
  <% end %>

  <% if setup_steps_data %>
    <%= render "settings/providers/setup_steps", steps: setup_steps_data %>
  <% elsif configuration.provider_description.present? %>
    <div class="text-sm text-secondary prose prose-sm">
      <%= markdown(configuration.provider_description).html_safe %>
    </div>
  <% end %>

  <% env_configured = configuration.fields.any? { |f| f.env_key && ENV[f.env_key].present? } %>
  <% if env_configured %>
    <p class="text-sm text-secondary">
      Configuration can be set via environment variables or overridden below.
    </p>
  <% end %>

  <%= styled_form_with model: Setting.new,
                       url: settings_providers_path,
                       method: :patch do |form| %>
    <div class="space-y-4">
      <% configuration.fields.each do |field| %>
        <%
          env_value = ENV[field.env_key] if field.env_key
          setting_value = Setting[field.setting_key]
          current_value = setting_value.presence || env_value

          display_value = if field.secret && current_value.present?
            "********"
          else
            current_value
          end

          input_type = field.secret ? "password" : "text"
        %>

        <div class="space-y-1">
          <%= form.text_field field.setting_key,
                              label: field.label,
                              type: input_type,
                              placeholder: field.default || (field.required ? "" : "Optional"),
                              value: display_value %>
          <% if field.description.present? %>
            <p class="text-xs text-secondary px-1"><%= field.description %></p>
          <% end %>
        </div>
      <% end %>

      <div class="flex justify-end">
        <%= form.submit t(".save_and_connect") %>
      </div>
    </div>
  <% end %>

  <% if local_assigns[:provider_setup_encryption_warning] %>
    <p class="text-xs text-secondary pt-3 border-t border-tertiary">
      <%= t("settings.providers.drawer_trust_statement_encryption_unconfigured") %>
    </p>
  <% end %>
</div>