Skip to content

Commit

Permalink
Cleanup partner api credentials + add banner instructions etc
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo committed Sep 13, 2023
1 parent b6de173 commit a42caa2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 46 deletions.
7 changes: 7 additions & 0 deletions app/helpers/partner_api_credentials_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
module PartnerApiCredentialsHelper
def partner_api_credential_path_for(current_user)
if current_user.partner_api_credential&.persisted?
edit_partner_api_credential_path(current_user.partner_api_credential)
else
new_partner_api_credential_path
end
end
end
12 changes: 12 additions & 0 deletions app/views/imports/_api_credentials_banner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= polaris_banner(
title: t(".title"),
status: :info
) do |banner| %>
<p>
<%= t(".message") %>
</p>

<% banner.with_action(
url: new_partner_api_credential_path
) { t("actions.add", resource: resource_name_for(PartnerApiCredential, true)) } %>
<% end %>
33 changes: 19 additions & 14 deletions app/views/imports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
subtitle: t(".subtitle")
) do |page| %>

<%= render "shared/page_actions", page: page %>

<% page.with_primary_action(url: new_import_path, disabled: @imports.in_progress.any?) { "New import" } %>

<% page.with_action_group(
title: t("actions.more_actions"),
actions: [
{ content: t("rename_apps.rename"), url: rename_apps_path },
{ content: t("actions.delete_all", resource: resource_name_for(Import, true)), url: destroy_all_imports_path, data: { turbo_method: :delete, turbo_confirm: t("imports.confirm_destroy") }, destructive: true }
]
) %>


<% if @imports.any? %>
<%= render "table", imports: @imports %>

<%= polaris_page_actions do |actions| %>
<% actions.with_secondary_action(
destructive: true,
outline: true,
url: destroy_all_imports_path,
data: {
turbo_method: :delete,
turbo_confirm: t("imports.confirm_destroy")
},
) { t("actions.delete_all", resource: resource_name_for(Import, true)) } %>

<%= polaris_vertical_stack(gap: "5") do %>

<% if current_user.partner_api_credential.blank? %>
<%= render "api_credentials_banner" %>
<% end %>

<%= render "table", imports: @imports %>

<% end %>

<% else %>
<%= render "shared/empty_state", resource: Import %>
<% end %>
Expand Down
29 changes: 18 additions & 11 deletions app/views/imports/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
subtitle: @import.created_at.to_fs(:long),
id: dom_id(@import),
back_url: imports_path,
secondary_actions: [
{
content: t("actions.delete", resource: resource_name_for(Import)),
url: @import,
destructive: true,
data: {
turbo_method: :delete,
turbo_confirm: t("imports.confirm_destroy")
},
}
],
) do |page| %>

<% page.with_title_metadata do %>
<%= render "shared/status", resource: @import %>
<% end %>

<%= render @import %>
<%= polaris_vertical_stack(gap: "5") do %>

<% if current_user.partner_api_credential.blank? %>
<%= render "api_credentials_banner" %>
<% end %>

<%= render @import %>

<%= polaris_page_actions do |actions| %>
<% actions.with_secondary_action(
destructive: true,
outline: true,
url: @import,
data: {
turbo_method: :delete,
turbo_confirm: t("imports.confirm_destroy"),
},
) { t("actions.delete", resource: resource_name_for(Import)) } %>
<% end %>

<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/frame/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
link_arguments: {}
) %>
<% section.with_item(
url: new_partner_api_credential_path,
label: "Partner API",
url: partner_api_credential_path_for(current_user),
label: "Partner API Credentials",
icon: "InsertDynamicSourceMajor",
selected: nav_item_selected?(new_partner_api_credential_path),
selected: nav_item_selected?(partner_api_credential_path_for(current_user)),
link_arguments: {}
) %>
<% end %>
Expand Down
24 changes: 12 additions & 12 deletions app/views/partner_api_credentials/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
<%= polaris_page(
narrow_width: true,
title: t(".title"),
subtitle: t(".subtitle")
subtitle: t(".subtitle"),
secondary_actions: [
{
content: t("actions.delete", resource: nil),
url: partner_api_credential_path,
destructive: true,
data: {
turbo_method: :delete,
turbo_confirm: t(".confirm_destroy")
},
}
],
) do |page| %>

<% page.with_title_metadata do %>
Expand All @@ -12,15 +23,4 @@

<%= render "form", partner_api_credential: @partner_api_credential %>

<%= polaris_page_actions do |actions| %>
<% actions.with_secondary_action(
destructive: true,
outline: true,
url: partner_api_credential_path,
data: {
turbo_method: :delete,
turbo_confirm: t(".confirm_destroy"),
},
) { t("actions.delete", resource: nil) } %>
<% end %>
<% end %>
8 changes: 6 additions & 2 deletions app/views/partner_api_credentials/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
<%= polaris_page(
narrow_width: true,
title: t(".title"),
subtitle: t(".subtitle")
subtitle: t(".subtitle", instructions_link: link_to("wiki article for instructions", "https://github.com/forsbergplustwo/partner-metrics/wiki/How-to-create-your-Shopify-Partner-API-credentials", target: "_blank")).html_safe
) do |page| %>

<% page.with_title_metadata do %>
<%= render "shared/status", resource: @partner_api_credential %>
<% end %>

<%= render "form", partner_api_credential: @partner_api_credential %>
<%= polaris_vertical_stack(gap: "5") do %>

<%= render "form", partner_api_credential: @partner_api_credential %>

<% end %>

<% end %>
16 changes: 12 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ en:
delete: "Delete %{resource}"
delete_all: "Delete all %{resource}"
more_actions: "More actions"
add: "Add %{resource}"
statuses:
draft: "Draft"
scheduled: "Scheduled"
Expand Down Expand Up @@ -98,21 +99,28 @@ en:
no_imports: "No imports have been made yet."
form:
payouts_file_help_text: "Export your payouts from the Shopify Partners Dashboard, then drop the received ZIP file above."
api_credentials_banner:
title: "Connect your Shopify Partner account"
message: "Connect your Shopify Partner account to automatically import new data daily."
rename_apps:
rename: "Rename app"
from: "Old app name"
to: "Current app name"
subtitle: "If you have renamed your app in the Shopify Partners Dashboard, merge the data by renaming the old app to the new app name."
partner_api_credentials:
new:
title: "Add credentials"
subtitle: "Connect your Shopify Partner account to automatically import new data daily."
title: "Add your Shopify Partner API credentials"
subtitle: "Add your Shopify Partner API credentials to automatically import new data daily. View the %{instructions_link} if needed."
edit:
title: "Edit credentials"
subtitle: "Edit your Shopify Partner API credentials."
title: "Edit your Shopify Partner API credentials"
subtitle: "Your API credentials are used to automatically import new data daily."
confirm_destroy: "Are you sure? This will remove your credentials and stop automatic imports."
form:
organization_id: "Shopify organization ID"
organization_id_help_text: "Find your organization ID in the Shopify Partners Dashboard."
access_token: "Shopify access token"
organization_id_help_text: "Generate an access token in the Shopify Partners Dashboard."
instructions_banner:
title: "Instructions"
message: "View the wiki article for instructions on how to set up your Shopify Partner API credentials."
button_text: "View wiki article"

0 comments on commit a42caa2

Please sign in to comment.