From a42caa2182cd621d8ce22f84901e1e497b126516 Mon Sep 17 00:00:00 2001 From: Bjorn Forsberg Date: Wed, 13 Sep 2023 16:23:32 +0200 Subject: [PATCH] Cleanup partner api credentials + add banner instructions etc --- app/helpers/partner_api_credentials_helper.rb | 7 ++++ .../imports/_api_credentials_banner.html.erb | 12 +++++++ app/views/imports/index.html.erb | 33 +++++++++++-------- app/views/imports/show.html.erb | 29 +++++++++------- app/views/layouts/frame/_navigation.html.erb | 6 ++-- .../partner_api_credentials/edit.html.erb | 24 +++++++------- .../partner_api_credentials/new.html.erb | 8 +++-- config/locales/en.yml | 16 ++++++--- 8 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 app/views/imports/_api_credentials_banner.html.erb diff --git a/app/helpers/partner_api_credentials_helper.rb b/app/helpers/partner_api_credentials_helper.rb index 0281f39..3fe5a21 100644 --- a/app/helpers/partner_api_credentials_helper.rb +++ b/app/helpers/partner_api_credentials_helper.rb @@ -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 diff --git a/app/views/imports/_api_credentials_banner.html.erb b/app/views/imports/_api_credentials_banner.html.erb new file mode 100644 index 0000000..325381a --- /dev/null +++ b/app/views/imports/_api_credentials_banner.html.erb @@ -0,0 +1,12 @@ +<%= polaris_banner( + title: t(".title"), + status: :info +) do |banner| %> +

+ <%= t(".message") %> +

+ + <% banner.with_action( + url: new_partner_api_credential_path + ) { t("actions.add", resource: resource_name_for(PartnerApiCredential, true)) } %> +<% end %> diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb index 30fe0f5..be0aad0 100644 --- a/app/views/imports/index.html.erb +++ b/app/views/imports/index.html.erb @@ -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 %> diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb index afd8210..55cae6c 100644 --- a/app/views/imports/show.html.erb +++ b/app/views/imports/show.html.erb @@ -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 %> diff --git a/app/views/layouts/frame/_navigation.html.erb b/app/views/layouts/frame/_navigation.html.erb index 6f90aaa..1c562b9 100644 --- a/app/views/layouts/frame/_navigation.html.erb +++ b/app/views/layouts/frame/_navigation.html.erb @@ -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 %> diff --git a/app/views/partner_api_credentials/edit.html.erb b/app/views/partner_api_credentials/edit.html.erb index 38aec81..41592dc 100644 --- a/app/views/partner_api_credentials/edit.html.erb +++ b/app/views/partner_api_credentials/edit.html.erb @@ -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 %> @@ -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 %> diff --git a/app/views/partner_api_credentials/new.html.erb b/app/views/partner_api_credentials/new.html.erb index 896aa0d..2f99d5c 100644 --- a/app/views/partner_api_credentials/new.html.erb +++ b/app/views/partner_api_credentials/new.html.erb @@ -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 %> diff --git a/config/locales/en.yml b/config/locales/en.yml index cf6952f..ee441bf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" @@ -98,6 +99,9 @@ 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" @@ -105,14 +109,18 @@ en: 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"