From a045e7e50b012867cc3ad33cb9511f2525e09779 Mon Sep 17 00:00:00 2001 From: Sag Date: Mon, 14 Aug 2023 15:33:38 +0200 Subject: [PATCH] Added a preview link in Admin for Tips & Donations (#17711) closes https://github.com/TryGhost/Product/issues/3724 --- .../modals/confirm-unsaved-changes.hbs | 2 +- .../settings/tips-and-donations.hbs | 21 +++++---- .../components/settings/tips-and-donations.js | 47 ++++++++++++++----- ghost/admin/app/styles/layouts/settings.css | 15 ++++++ 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/ghost/admin/app/components/modals/confirm-unsaved-changes.hbs b/ghost/admin/app/components/modals/confirm-unsaved-changes.hbs index 2c996fbbca..6b85e41082 100644 --- a/ghost/admin/app/components/modals/confirm-unsaved-changes.hbs +++ b/ghost/admin/app/components/modals/confirm-unsaved-changes.hbs @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/ghost/admin/app/components/settings/tips-and-donations.hbs b/ghost/admin/app/components/settings/tips-and-donations.hbs index 0f63ffc3b2..83842f4a59 100644 --- a/ghost/admin/app/components/settings/tips-and-donations.hbs +++ b/ghost/admin/app/components/settings/tips-and-donations.hbs @@ -76,8 +76,8 @@ - -
+ + diff --git a/ghost/admin/app/components/settings/tips-and-donations.js b/ghost/admin/app/components/settings/tips-and-donations.js index 4f01eccfa2..30c35648c8 100644 --- a/ghost/admin/app/components/settings/tips-and-donations.js +++ b/ghost/admin/app/components/settings/tips-and-donations.js @@ -1,4 +1,5 @@ import Component from '@glimmer/component'; +import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes'; import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard'; import envConfig from 'ghost-admin/config/environment'; import {action} from '@ember/object'; @@ -22,6 +23,7 @@ export default class TipsAndDonations extends Component { @service settings; @service session; @service membersUtils; + @service modals; @inject config; @tracked tipsAndDonationsError = ''; @@ -42,16 +44,9 @@ export default class TipsAndDonations extends Component { return this.config.blogUrl; } - @task - *copyTipsAndDonationsLink() { - const link = document.getElementById('gh-tips-and-donations-link')?.value; - - if (link) { - copyTextToClipboard(link); - yield timeout(this.isTesting ? 50 : 500); - } - - return true; + get isConnectDisallowed() { + const siteUrl = this.config.blogUrl; + return envConfig.environment !== 'development' && !/^https:/.test(siteUrl); } @action @@ -91,8 +86,34 @@ export default class TipsAndDonations extends Component { this.showStripeConnect = false; } - get isConnectDisallowed() { - const siteUrl = this.config.blogUrl; - return envConfig.environment !== 'development' && !/^https:/.test(siteUrl); + @action + async showPreview(event) { + event.preventDefault(); + + const preview = () => window.open(`${this.siteUrl}/#/portal/support`, '_blank'); + const changedAttributes = this.settings.changedAttributes(); + + if (changedAttributes && Object.keys(changedAttributes).length > 0) { + const shouldClose = await this.modals.open(ConfirmUnsavedChangesModal); + + if (shouldClose) { + this.settings.rollbackAttributes(); + preview(); + } + } else { + preview(); + } + } + + @task + *copyTipsAndDonationsLink() { + const link = document.getElementById('gh-tips-and-donations-link')?.value; + + if (link) { + copyTextToClipboard(link); + yield timeout(this.isTesting ? 50 : 3000); + } + + return true; } } diff --git a/ghost/admin/app/styles/layouts/settings.css b/ghost/admin/app/styles/layouts/settings.css index 9871e6b3f8..d46606ab69 100644 --- a/ghost/admin/app/styles/layouts/settings.css +++ b/ghost/admin/app/styles/layouts/settings.css @@ -3208,6 +3208,21 @@ p.theme-validation-details { border-left: none !important; } +.gh-tips-and-donations-link-container { + position: relative; + display: flex; + align-items: center; + justify-content: space-between; + font-size: 1.4rem; + height: 38px; + background: var(--whitegrey-l2); + border-radius: 4px; + border: 1px solid var(--whitegrey); + color: var(--darkgrey); + font-weight: 500; + width: 100%; +} + /* History log /* ---------------------------------------------------------- */ .gh-history-filter-li {