From 0824430da5e31b9f2b21af862c51640da5d328d5 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 24 Sep 2024 10:43:55 +1000 Subject: [PATCH] Add Vine connected app The connection/disconnection logic is yet to be implemented --- app/models/connected_app.rb | 3 ++- app/models/connected_apps/vine.rb | 15 +++++++++++ .../form/connected_apps/_vine.html.haml | 27 +++++++++++++++++++ app/webpacker/css/admin/connected_apps.scss | 23 +++++++++++++++- config/locales/en.yml | 17 ++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 app/models/connected_apps/vine.rb create mode 100644 app/views/admin/enterprises/form/connected_apps/_vine.html.haml diff --git a/app/models/connected_app.rb b/app/models/connected_app.rb index 966df543b5..faf1b0abe7 100644 --- a/app/models/connected_app.rb +++ b/app/models/connected_app.rb @@ -4,13 +4,14 @@ # # Here we store keys and links to access the app. class ConnectedApp < ApplicationRecord - TYPES = ['discover_regen', 'affiliate_sales_data'].freeze + TYPES = ['discover_regen', 'affiliate_sales_data', 'vine'].freeze belongs_to :enterprise after_destroy :disconnect scope :discover_regen, -> { where(type: "ConnectedApp") } scope :affiliate_sales_data, -> { where(type: "ConnectedApps::AffiliateSalesData") } + scope :vine, -> { where(type: "ConnectedApps::Vine") } scope :connecting, -> { where(data: nil) } scope :ready, -> { where.not(data: nil) } diff --git a/app/models/connected_apps/vine.rb b/app/models/connected_apps/vine.rb new file mode 100644 index 0000000000..46fad0f1c1 --- /dev/null +++ b/app/models/connected_apps/vine.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# An enterprise can opt-in to use VINE API to manage vouchers +# +module ConnectedApps + class Vine < ConnectedApp + def connect(api_key: ) + # TODO + end + + def disconnect + # TODO + end + end +end diff --git a/app/views/admin/enterprises/form/connected_apps/_vine.html.haml b/app/views/admin/enterprises/form/connected_apps/_vine.html.haml new file mode 100644 index 0000000000..1281a73e84 --- /dev/null +++ b/app/views/admin/enterprises/form/connected_apps/_vine.html.haml @@ -0,0 +1,27 @@ +%section.connected_app + .connected-app__head + %div + %h3= t ".title" + %p= t ".tagline" + .connected-app__vine + - if connected_app.nil? + = form_with url: admin_enterprise_connected_apps_path(enterprise.id) do |f| + .connected-app__vine-content + .vine-api-key + = f.hidden_field :type, value: "ConnectedApps::Vine" + = f.label :vine_api_key, t(".vine_api_key") + %span.required * + = f.text_field :vine_api_key, { disabled: !managed_by_user?(enterprise) } + %div + - disabled = managed_by_user?(enterprise) ? {} : { disabled: true, "data-disable-with": false } + = f.submit t(".enable"), disabled + + -# This is only seen by super-admins: + %em= t(".need_to_be_manager") unless managed_by_user?(enterprise) + - else + .connected-app__vine-content + .vine-disable + = button_to t(".disable"), admin_enterprise_connected_app_path(connected_app.id, enterprise_id: enterprise.id), method: :delete + %hr + .connected-app__description + = t ".description_html" diff --git a/app/webpacker/css/admin/connected_apps.scss b/app/webpacker/css/admin/connected_apps.scss index be3356009d..f68d902ad0 100644 --- a/app/webpacker/css/admin/connected_apps.scss +++ b/app/webpacker/css/admin/connected_apps.scss @@ -34,7 +34,9 @@ border: none; border-left: $border-radius solid $color-3; border-radius: $border-radius; - box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.05), 0px 2px 2px rgba(0, 0, 0, 0.07); + box-shadow: + 0px 1px 0px rgba(0, 0, 0, 0.05), + 0px 2px 2px rgba(0, 0, 0, 0.07); margin: 2em 0; padding: 0.5em 1em; @@ -47,3 +49,22 @@ flex-shrink: 1; } } + +.connected-app__vine { + margin: 1em 0; + + .connected-app__vine-content { + display: flex; + justify-content: space-between; + align-items: end; + + .vine-api-key { + width: 100%; + margin-right: 1em; + } + + .vine-disable { + margin-left: auto; + } + } +} diff --git a/config/locales/en.yml b/config/locales/en.yml index f1041c92bb..da1bbe8043 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -753,6 +753,7 @@ en: connected_apps_enabled: discover_regen: Discover Regenerative portal affiliate_sales_data: DFC anonymised orders API for research purposes + vine: Voucher Engine (VINE) update: resource: Connected app settings @@ -1418,6 +1419,22 @@ en: target="_blank">Learn more about Discover Regenerative

+ vine: + title: "Voucher Engine (VINE)" + tagline: "Enable the use of VINE api to handle vouchers" + enable: "Connect" + disable: "Disconnect" + need_to_be_manager: "Only managers can connect apps." + vine_api_key: "VINE API Key" + description_html: | +

+ To enable VINE for your enterprise, enter your API key. +

+

+ VINE + +

+ actions: edit_profile: Settings properties: Properties