Add redirect when segment doesn't exist

[MAILPOET-3477]
This commit is contained in:
Jan Lysý
2021-04-07 14:41:40 +02:00
committed by Veljko V
parent 57900f46e6
commit 99eff6129c
2 changed files with 11 additions and 6 deletions

View File

@@ -52,7 +52,6 @@ class Form extends React.Component {
loadItem = (id) => {
this.setState({ loading: true });
if (!this.props.endpoint) return;
MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
@@ -74,7 +73,7 @@ class Form extends React.Component {
loading: false,
item: {},
}, function failSetStateCallback() {
this.props.history.push('/new');
this.props.history.push('/lists');
});
});
};

View File

@@ -108,16 +108,22 @@ const DynamicSegmentForm: React.FunctionComponent = () => {
},
})
.done((response) => {
setItem(convertSavedData(response.data));
setSegmentType(findSegmentType(response.data));
if (response.data.is_plugin_missing) {
history.push('/segments');
} else {
setItem(convertSavedData(response.data));
setSegmentType(findSegmentType(response.data));
}
})
.fail(compose([setErrors, prop('errors')]));
.fail(() => {
history.push('/segments');
});
}
if (match.params.id !== undefined) {
loadSegment(match.params.id);
}
}, [segmentFilters, match.params.id]);
}, [segmentFilters, match.params.id, history]);
function handleSave(e): void {
e.preventDefault();