mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
Added client-side validation check for post before opening publish/update flows
refs https://github.com/orgs/TryGhost/projects/59/views/20 - before the publish/update flow modals are opened, perform a `post.validate()` call, if it fails show the red error bar and don't open the modal - shows validation errors early rather than being hidden until a save occurs at the end of the publish flow
This commit is contained in:
parent
1c1dbc9310
commit
cf3f872fa6
1 changed files with 27 additions and 3 deletions
|
@ -370,12 +370,14 @@ export default class PublishManagement extends Component {
|
|||
}
|
||||
|
||||
@action
|
||||
openPublishFlow(event) {
|
||||
async openPublishFlow(event) {
|
||||
event?.preventDefault();
|
||||
|
||||
this.updateFlowModal?.close();
|
||||
|
||||
if (!this.publishFlowModal || this.publishFlowModal.isClosing) {
|
||||
const isValid = await this._validatePost();
|
||||
|
||||
if (isValid && !this.publishFlowModal || this.publishFlowModal.isClosing) {
|
||||
this.publishOptions.resetPastScheduledAt();
|
||||
|
||||
this.publishFlowModal = this.modals.open(PublishFlowModal, {
|
||||
|
@ -391,7 +393,9 @@ export default class PublishManagement extends Component {
|
|||
|
||||
this.publishFlowModal?.close();
|
||||
|
||||
if (!this.updateFlowModal || this.updateFlowModal.isClosing) {
|
||||
const isValid = await this._validatePost();
|
||||
|
||||
if (isValid && !this.updateFlowModal || this.updateFlowModal.isClosing) {
|
||||
this.updateFlowModal = this.modals.open(UpdateFlowModal, {
|
||||
publishOptions: this.publishOptions,
|
||||
saveTask: this.publishTask
|
||||
|
@ -406,6 +410,26 @@ export default class PublishManagement extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
async _validatePost() {
|
||||
this.notifications.closeAlerts('post.save');
|
||||
|
||||
try {
|
||||
await this.publishOptions.post.validate();
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (e === undefined && this.publishOptions.post.errors.length !== 0) {
|
||||
// validation error
|
||||
const validationError = this.publishOptions.post.errors.messages[0];
|
||||
const errorMessage = `Validation failed: ${validationError}`;
|
||||
|
||||
this.notifications.showAlert(errorMessage, {type: 'error', key: 'post.save'});
|
||||
return false;
|
||||
}
|
||||
|
||||
this.notifications.showAPIError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@task
|
||||
*publishTask({taskName = 'saveTask'} = {}) {
|
||||
const willEmail = this.publishOptions.willEmail;
|
||||
|
|
Loading…
Add table
Reference in a new issue