From 838611607a7a22da441f213de8fa6a53bfa28a44 Mon Sep 17 00:00:00 2001 From: James Nuanez Date: Wed, 22 Apr 2020 14:56:15 -0700 Subject: [PATCH] Redirect away from forms when dependencies not met --- src/components/forms/ApplicationForm.js | 10 ++++++++++ src/components/forms/PhoneNumberForm.js | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/components/forms/ApplicationForm.js b/src/components/forms/ApplicationForm.js index e659d93..bbbe2a3 100644 --- a/src/components/forms/ApplicationForm.js +++ b/src/components/forms/ApplicationForm.js @@ -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) diff --git a/src/components/forms/PhoneNumberForm.js b/src/components/forms/PhoneNumberForm.js index 6263207..24cb8a2 100644 --- a/src/components/forms/PhoneNumberForm.js +++ b/src/components/forms/PhoneNumberForm.js @@ -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;