From e1730f25d6eb3da15a37327be097d957bb3c4d05 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 14 Dec 2023 12:57:28 +1100 Subject: [PATCH] Show app connection state and update link --- .../form/_connected_apps.html.haml | 12 ++++- app/webpacker/css/admin/connected_apps.scss | 12 +++++ config/locales/en.yml | 2 + .../Connected_Apps/can_be_enabled.yml | 54 +++++++++++++++++++ .../admin/enterprises/connected_apps_spec.rb | 7 ++- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml diff --git a/app/views/admin/enterprises/form/_connected_apps.html.haml b/app/views/admin/enterprises/form/_connected_apps.html.haml index 7ca2b5cfd3..8298c1307c 100644 --- a/app/views/admin/enterprises/form/_connected_apps.html.haml +++ b/app/views/admin/enterprises/form/_connected_apps.html.haml @@ -10,7 +10,17 @@ .connected-app__connection - if @enterprise.connected_apps.present? .connected-app__note - = t ".note" + - link = @enterprise.connected_apps[0].data&.fetch("link", false) + - if link + %p= t ".note" + %div + %a{ href: link, target: "_blank", class: "button" } + = t ".link_label" + - else + %p + %i.spinner.fa.fa-spin.fa-circle-o-notch +   + = t ".saving_changes" %hr .connected-app__description diff --git a/app/webpacker/css/admin/connected_apps.scss b/app/webpacker/css/admin/connected_apps.scss index 205c6c0d6c..b487089182 100644 --- a/app/webpacker/css/admin/connected_apps.scss +++ b/app/webpacker/css/admin/connected_apps.scss @@ -15,6 +15,9 @@ } .connected-app__note { + display: flex; + justify-content: space-between; + background-color: #f8f9fa; border: none; border-left: 4px solid #008397; @@ -22,4 +25,13 @@ 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; + + align-items: center; + gap: 1em; + * { + flex-shrink: 0; + } + p { + flex-shrink: 1; + } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 8cf2d41487..b9df0ba1f9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1284,9 +1284,11 @@ en: title: "Discover Regenerative" tagline: "Allow website to publish your enterprise information." action: "Share data" + saving_changes: "Saving changes" note: | In order for this enterprise to be published, you need to include regenerative details and accept the Terms and Conditions. + link_label: "Update details" description_html: |

Discover Regenerative makes it easier for buyers to discover diff --git a/spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml b/spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml new file mode 100644 index 0000000000..b968963b7b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Connected_Apps/can_be_enabled.yml @@ -0,0 +1,54 @@ +--- +http_interactions: +- request: + method: post + uri: https://n8n.openfoodnetwork.org.uk/webhook/regen/connect-enterprise + body: + encoding: UTF-8 + string: '{"id":"4da377c8-0c8f-4aaa-8f85-f2a218a13d6e","at":"2023-12-14 12:52:53 + +1100","event":"connect-app","data":{"enterprise_id":45,"access_token":"2c5f828a1da2f5a87798e6d3ee44daee6729b2963db6d264"}}' + headers: + User-Agent: + - openfoodnetwork_webhook/1.0 + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 14 Dec 2023 01:52:55 GMT + Content-Type: + - text/html; charset=utf-8 + Content-Length: + - '35' + Connection: + - keep-alive + Etag: + - W/"23-GW39X6dSljjgz4GPY7ICa+eNupE" + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=63072000 + X-Xss-Protection: + - 1; mode=block + X-Download-Options: + - noopen + X-Content-Type-Options: + - nosniff + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - same-origin + body: + encoding: UTF-8 + string: '{"link":"https://example.net/edit"}' + recorded_at: Thu, 14 Dec 2023 01:52:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/system/admin/enterprises/connected_apps_spec.rb b/spec/system/admin/enterprises/connected_apps_spec.rb index b9e0f2cb9c..f7b2ddb81e 100644 --- a/spec/system/admin/enterprises/connected_apps_spec.rb +++ b/spec/system/admin/enterprises/connected_apps_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -describe "Connected Apps", feature: :connected_apps do +describe "Connected Apps", feature: :connected_apps, vcr: true do let(:enterprise) { create(:enterprise) } before do @@ -37,6 +37,11 @@ describe "Connected Apps", feature: :connected_apps do click_button "Share data" expect(page).to_not have_button "Share data" + expect(page).to have_content "Saving changes" + + perform_enqueued_jobs(only: ConnectAppJob) + page.refresh # TODO: update via cable_ready expect(page).to have_content "include regenerative details" + expect(page).to have_link "Update details" end end