From 536b183535b7ccbbd192a691aa6ee18ee700871e Mon Sep 17 00:00:00 2001 From: Conner Luzier <37819611+cluzier@users.noreply.github.com> Date: Thu, 21 Apr 2022 13:33:04 -0400 Subject: [PATCH] regions field added to aws, default to us-east-1 (#50) * regions field added to aws, default to us-east-1 * added aws_region to post request * no default setting on aws region * aws_region required before saving * no longer showing default on dropdown Co-authored-by: Conner Luzier --- .env | 1 + src/components/forms/SpeechForm.js | 131 ++++++++++++++++++----------- 2 files changed, 85 insertions(+), 47 deletions(-) diff --git a/.env b/.env index 5afc927..9e38faf 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ REACT_APP_API_BASE_URL=http://127.0.0.1:3002/v1 +GENERATE_SOURCEMAP=false \ No newline at end of file diff --git a/src/components/forms/SpeechForm.js b/src/components/forms/SpeechForm.js index c9f0198..11d1fe0 100644 --- a/src/components/forms/SpeechForm.js +++ b/src/components/forms/SpeechForm.js @@ -21,6 +21,7 @@ import Button from '../elements/Button'; import Loader from '../blocks/Loader'; import { ServiceProviderValueContext } from '../../contexts/ServiceProviderContext'; +import AwsRegions from '../../data/AwsRegions'; import MicrosoftAzureRegions from '../../data/MicrosoftAzureRegions'; import { APP_API_BASE_URL } from "../../constants"; @@ -78,39 +79,42 @@ const SpeechServicesAddEdit = (props) => { const refUseForStt = useRef(null); const refApiKey = useRef(null); const refRegion = useRef(null); + const refAwsRegion = useRef(null); // Form inputs - const [ vendor, setVendor ] = useState(''); - const [ serviceKey, setServiceKey ] = useState(''); - const [ displayedServiceKey, setDisplayedServiceKey ] = useState(''); - const [ accessKeyId, setAccessKeyId ] = useState(''); - const [ secretAccessKey, setSecretAccessKey ] = useState(''); - const [ useForTts, setUseForTts ] = useState(false); - const [ useForStt, setUseForStt ] = useState(false); - const [ accounts, setAccounts ] = useState([]); - const [ accountSid, setAccountSid ] = useState(''); - const [ apiKey, setApiKey ] = useState(''); - const [ region, setRegion ] = useState(''); + const [vendor, setVendor] = useState(''); + const [serviceKey, setServiceKey] = useState(''); + const [displayedServiceKey, setDisplayedServiceKey] = useState(''); + const [accessKeyId, setAccessKeyId] = useState(''); + const [secretAccessKey, setSecretAccessKey] = useState(''); + const [useForTts, setUseForTts] = useState(false); + const [useForStt, setUseForStt] = useState(false); + const [accounts, setAccounts] = useState([]); + const [accountSid, setAccountSid] = useState(''); + const [apiKey, setApiKey] = useState(''); + const [region, setRegion] = useState(''); + const [awsregion, setAwsRegion] = useState(''); // Invalid form inputs - const [ invalidVendorGoogle, setInvalidVendorGoogle ] = useState(false); - const [ invalidVendorAws, setInvalidVendorAws ] = useState(false); - const [ invalidVendorMs, setInvalidVendorMs ] = useState(false); - const [ invalidVendorWellSaid, setInvalidVendorWellSaid ] = useState(false); - const [ invalidAccessKeyId, setInvalidAccessKeyId ] = useState(false); - const [ invalidSecretAccessKey, setInvalidSecretAccessKey ] = useState(false); - const [ invalidUseForTts, setInvalidUseForTts ] = useState(false); - const [ invalidUseForStt, setInvalidUseForStt ] = useState(false); - const [ invalidApiKey, setInvalidApiKey ] = useState(false); - const [ invalidRegion, setInvalidRegion ] = useState(false); + const [invalidVendorGoogle, setInvalidVendorGoogle] = useState(false); + const [invalidVendorAws, setInvalidVendorAws] = useState(false); + const [invalidVendorMs, setInvalidVendorMs] = useState(false); + const [invalidVendorWellSaid, setInvalidVendorWellSaid] = useState(false); + const [invalidAccessKeyId, setInvalidAccessKeyId] = useState(false); + const [invalidSecretAccessKey, setInvalidSecretAccessKey] = useState(false); + const [invalidUseForTts, setInvalidUseForTts] = useState(false); + const [invalidUseForStt, setInvalidUseForStt] = useState(false); + const [invalidApiKey, setInvalidApiKey] = useState(false); + const [invalidRegion, setInvalidRegion] = useState(false); + const [invalidAwsRegion, setInvalidAwsRegion] = useState(false); - const [ originalTtsValue, setOriginalTtsValue ] = useState(null); - const [ originalSttValue, setOriginalSttValue ] = useState(null); + const [originalTtsValue, setOriginalTtsValue] = useState(null); + const [originalSttValue, setOriginalSttValue] = useState(null); - const [ validServiceKey, setValidServiceKey ] = useState(false); + const [validServiceKey, setValidServiceKey] = useState(false); - const [ showLoader, setShowLoader ] = useState(true); - const [ errorMessage, setErrorMessage ] = useState(''); + const [showLoader, setShowLoader] = useState(true); + const [errorMessage, setErrorMessage] = useState(''); useEffect(() => { const getAPIData = async () => { @@ -146,18 +150,19 @@ const SpeechServicesAddEdit = (props) => { } catch (err) { } - setAccountSid( speechCredential.data.account_sid || ''); - setVendor( speechCredential.data.vendor || undefined); - setServiceKey( serviceKeyJson || ''); - setDisplayedServiceKey( displayedServiceKeyJson || ''); - setAccessKeyId( speechCredential.data.access_key_id || ''); - setSecretAccessKey( speechCredential.data.secret_access_key || ''); - setApiKey( speechCredential.data.api_key || ''); - setRegion( speechCredential.data.region || ''); - setUseForTts( speechCredential.data.use_for_tts || false); - setUseForStt( speechCredential.data.use_for_stt || false); - setOriginalTtsValue( speechCredential.data.use_for_tts || false); - setOriginalSttValue( speechCredential.data.use_for_stt || false); + setAccountSid(speechCredential.data.account_sid || ''); + setVendor(speechCredential.data.vendor || undefined); + setServiceKey(serviceKeyJson || ''); + setDisplayedServiceKey(displayedServiceKeyJson || ''); + setAccessKeyId(speechCredential.data.access_key_id || ''); + setSecretAccessKey(speechCredential.data.secret_access_key || ''); + setApiKey(speechCredential.data.api_key || ''); + setRegion(speechCredential.data.region || ''); + setAwsRegion(speechCredential.data.aws_region || ''); + setUseForTts(speechCredential.data.use_for_tts || false); + setUseForStt(speechCredential.data.use_for_stt || false); + setOriginalTtsValue(speechCredential.data.use_for_tts || false); + setOriginalSttValue(speechCredential.data.use_for_stt || false); } setShowLoader(false); } catch (err) { @@ -265,6 +270,15 @@ const SpeechServicesAddEdit = (props) => { } } + if (vendor === 'aws' && !awsregion) { + errorMessages.push('Please select a region.'); + setInvalidAwsRegion(true); + if (!focusHasBeenSet) { + refAwsRegion.current.focus(); + focusHasBeenSet = true; + } + } + if (vendor === 'microsoft' && !apiKey) { errorMessages.push('Please provide an API key.'); setInvalidApiKey(true); @@ -323,6 +337,7 @@ const SpeechServicesAddEdit = (props) => { service_key: vendor === 'google' ? JSON.stringify(serviceKey) : null, access_key_id: vendor === 'aws' ? accessKeyId : null, secret_access_key: vendor === 'aws' ? secretAccessKey : null, + aws_region: vendor === 'aws' ? awsregion : null, api_key: ['microsoft', 'wellsaid'].includes(vendor) ? apiKey : null, region: vendor === 'microsoft' ? region : null, use_for_tts: useForTts, @@ -463,7 +478,7 @@ const SpeechServicesAddEdit = (props) => { return ( showLoader ? ( - + ) : (
{ ref={refSecretAccessKey} disabled={type === 'edit'} /> + + + ) : vendor === 'microsoft' ? ( <> @@ -619,7 +656,7 @@ const SpeechServicesAddEdit = (props) => { ))} - ) : vendor === 'wellsaid' ? ( + ) : vendor === 'wellsaid' ? ( <> { {['google', 'aws', 'microsoft', 'wellsaid'].includes(vendor) ? ( <> -
+
{ invalid={invalidUseForTts} ref={refUseForTts} /> -
+
{ /> ) : - ( - null - )} + ( + null + )} {errorMessage && ( @@ -682,7 +719,7 @@ const SpeechServicesAddEdit = (props) => { dispatch({ type: 'ADD', level: 'info', - message: type === 'add' ? 'New speech service canceled' :'Changes canceled', + message: type === 'add' ? 'New speech service canceled' : 'Changes canceled', }); }} > @@ -701,4 +738,4 @@ const SpeechServicesAddEdit = (props) => { ); }; -export default SpeechServicesAddEdit; +export default SpeechServicesAddEdit; \ No newline at end of file