Redirect away from forms when dependencies not met

This commit is contained in:
James Nuanez committed 2020-04-22 14:56:15 -07:00
1 parent 7ab0aa7c2a
commit 838611607a
2 files changed
+34

No files matched your search

+10
View File
@@ -115,6 +115,16 @@ const ApplicationForm = props => {
setAccounts(accounts);
setApplications(applications);
if (accounts.length === 0) {
history.push('/internal/accounts');
dispatch({
type: 'ADD',
level: 'error',
message: 'You must create an account before you can create an application.',
});
return;
}
if (
(props.type === 'setup' && accounts.length > 1) ||
(props.type === 'setup' && applications.length > 1)
+24
View File
@@ -108,6 +108,30 @@ const PhoneNumberForm = props => {
setApplicationValues(applications);
setPhoneNumbers(phoneNumbers);
if (!accounts.length) {
dispatch({
type: 'ADD',
level: 'error',
message: 'You must create an account before you can create a phone number.',
});
}
if (!sipTrunks.length) {
dispatch({
type: 'ADD',
level: 'error',
message: 'You must create a SIP trunk before you can create a phone number.',
});
}
if (!accounts.length) {
history.push('/internal/accounts');
return;
} else if (!sipTrunks.length) {
history.push('/internal/sip-trunks');
return;
}
if (props.type === 'edit') {
const phoneNumberData = promiseAllValues[3] && promiseAllValues[3].data.filter(p => {
return p.phone_number_sid === props.phone_number_sid;