2023-05-11 16:12:25 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
2023-05-16 15:16:57 +03:00
|
|
|
export default class FeedbackLexicalSendButtonComponent extends Component {
|
2023-05-11 16:12:25 +03:00
|
|
|
@service ajax;
|
|
|
|
@service ghostPaths;
|
|
|
|
@service session;
|
|
|
|
@service notifications;
|
|
|
|
|
|
|
|
@inject config;
|
|
|
|
|
2023-05-17 15:09:29 +03:00
|
|
|
get isDisabled() {
|
|
|
|
return !this.args.feedbackMessage;
|
|
|
|
}
|
|
|
|
|
2023-05-11 16:12:25 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*submitFeedback() {
|
|
|
|
let url = `https://submit-form.com/us6uBWv8`;
|
2023-05-16 15:16:57 +03:00
|
|
|
|
2023-05-11 16:12:25 +03:00
|
|
|
let postData;
|
2023-05-16 15:16:57 +03:00
|
|
|
if (this.args?.post) {
|
2023-05-11 16:12:25 +03:00
|
|
|
postData = {
|
2023-05-16 15:16:57 +03:00
|
|
|
PostId: this.args.post?.id,
|
|
|
|
PostTitle: this.args.post?.title
|
2023-05-11 16:12:25 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let ghostData = {
|
|
|
|
Site: this.config.blogUrl,
|
|
|
|
StaffMember: this.session.user.name,
|
|
|
|
StaffMemberEmail: this.session.user.email,
|
|
|
|
StaffAccessLevel: this.session.user.role?.description,
|
|
|
|
UserAgent: navigator.userAgent,
|
2023-06-06 20:55:51 +03:00
|
|
|
GhostVersion: this.config.version,
|
|
|
|
KoenigLexicalVersion: window['@tryghost/koenig-lexical'].version,
|
2023-05-16 15:16:57 +03:00
|
|
|
Feedback: this.args.feedbackMessage
|
2023-05-11 16:12:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
...ghostData,
|
|
|
|
...postData
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = yield this.ajax.post(url, {data});
|
|
|
|
|
|
|
|
if (response.status < 200 || response.status >= 300) {
|
|
|
|
throw new Error('api failed ' + response.status + ' ' + response.statusText);
|
|
|
|
}
|
|
|
|
|
2023-05-16 15:16:57 +03:00
|
|
|
this.args.onSuccess?.();
|
2023-05-11 16:12:25 +03:00
|
|
|
|
|
|
|
this.notifications.showNotification('Feedback sent',
|
|
|
|
{
|
|
|
|
icon: 'send-email',
|
|
|
|
description: 'Thank you!'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2023-05-16 15:16:57 +03:00
|
|
|
}
|