2021-05-17 18:14:38 +03:00
|
|
|
import ModalBase from 'ghost-admin/components/modal-base';
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
// TODO: update modals to work fully with Glimmer components
|
|
|
|
@classic
|
|
|
|
export default class ModalStripeConnect extends ModalBase {
|
|
|
|
@service settings;
|
2022-05-24 17:53:03 +03:00
|
|
|
@service membersUtils;
|
2021-05-17 18:14:38 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
setStripeConnectIntegrationTokenSetting(stripeConnectIntegrationToken) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.stripeConnectIntegrationToken = stripeConnectIntegrationToken;
|
2021-05-17 18:14:38 +03:00
|
|
|
}
|
2021-05-20 19:20:49 +03:00
|
|
|
|
2021-05-21 10:56:55 +03:00
|
|
|
@action
|
|
|
|
reset() {
|
|
|
|
// stripeConnectIntegrationToken is not a persisted value so we don't want
|
|
|
|
// to keep it around across transitions
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.stripeConnectIntegrationToken = undefined;
|
2021-05-21 10:56:55 +03:00
|
|
|
}
|
|
|
|
|
2021-06-18 13:54:18 +03:00
|
|
|
@action
|
|
|
|
close(event) {
|
|
|
|
event?.preventDefault?.();
|
|
|
|
this.closeModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
confirmAction() {
|
|
|
|
this.confirm();
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
|
2021-05-20 19:20:49 +03:00
|
|
|
@action
|
|
|
|
updateSuccessModifier() {
|
2022-05-24 17:53:03 +03:00
|
|
|
// Note, we should also check isStripeEnabled because stripeDirect option might be enabled
|
2022-10-07 16:23:21 +03:00
|
|
|
if (this.membersUtils.get('isStripeEnabled') && this.settings.stripeConnectAccountId) {
|
2021-05-20 19:20:49 +03:00
|
|
|
if (this.modifier?.indexOf('stripe-connected') === -1) {
|
|
|
|
this.updateModifier(`${this.modifier} stripe-connected`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this.modifier?.indexOf('stripe-connected') !== -1) {
|
|
|
|
this.updateModifier(this.modifier.replace(/\s?stripe-connected/, ''));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 12:12:36 +03:00
|
|
|
|
|
|
|
actions = {
|
|
|
|
confirm() {
|
2022-10-07 16:23:21 +03:00
|
|
|
if (this.settings.stripeConnectAccountId) {
|
2021-06-18 13:54:18 +03:00
|
|
|
return this.confirmAction();
|
2021-06-18 12:12:36 +03:00
|
|
|
}
|
|
|
|
// noop - enter key shouldn't do anything
|
2021-06-24 11:42:32 +03:00
|
|
|
},
|
|
|
|
// needed because ModalBase uses .send() for keyboard events
|
|
|
|
closeModal() {
|
|
|
|
this.close();
|
2021-06-18 12:12:36 +03:00
|
|
|
}
|
2022-02-10 13:41:36 +03:00
|
|
|
};
|
2021-05-17 18:14:38 +03:00
|
|
|
}
|