From 93df766eb572d31c30e66578a3eccd5484945280 Mon Sep 17 00:00:00 2001 From: eglehelms Date: Thu, 1 Dec 2022 12:44:36 +0100 Subject: [PATCH] fix access conditionals --- src/containers/internal/navi/index.tsx | 12 +++++++-- .../internal/views/carriers/form.tsx | 18 ++++++++++++- .../internal/views/speech-services/form.tsx | 26 +++++++++++++------ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/containers/internal/navi/index.tsx b/src/containers/internal/navi/index.tsx index b8f0431..5146c36 100644 --- a/src/containers/internal/navi/index.tsx +++ b/src/containers/internal/navi/index.tsx @@ -177,7 +177,11 @@ export const Navi = ({ {naviTop.map((item) => { if (item.label === "Settings") { return ( - + + { + if (user?.scope === USER_ACCOUNT) { + if (carrier && carrier.data?.account_sid) { + return false; + } + if (!carrier) { + return false; + } + if (carrier && !carrier.data?.account_sid) { + return true; + } + } + return true; + }; + return (
@@ -706,7 +721,8 @@ export const CarrierForm = ({ account={[accountSid, setAccountSid]} label="Used By" required={false} - defaultOption={user?.scope !== USER_ACCOUNT} + defaultOption={checkOptions()} + disabled={!!checkOptions()} /> {accountSid && hasLength(applications) && ( <> diff --git a/src/containers/internal/views/speech-services/form.tsx b/src/containers/internal/views/speech-services/form.tsx index 5cda4cd..a1bb5ec 100644 --- a/src/containers/internal/views/speech-services/form.tsx +++ b/src/containers/internal/views/speech-services/form.tsx @@ -95,7 +95,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - if (user?.scope === USER_ACCOUNT && user.account_sid === accountSid) { + if (user?.scope === USER_ACCOUNT && user.account_sid !== accountSid) { toastError( "You do not have permissions to make changes to these Speech Credentials" ); @@ -105,12 +105,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { if (currentServiceProvider) { const payload: Partial = { vendor, - account_sid: - user?.scope === USER_ACCOUNT - ? user?.account_sid - : accountSid - ? accountSid - : null, + account_sid: accountSid || null, service_provider_sid: currentServiceProvider.service_provider_sid || null, use_for_tts: ttsCheck ? 1 : 0, @@ -175,6 +170,21 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { } }; + const checkOptions = () => { + if (user?.scope === USER_ACCOUNT) { + if (credential && credential.data?.account_sid) { + return false; + } + if (!credential) { + return false; + } + if (credential && !credential.data?.account_sid) { + return true; + } + } + return true; + }; + useEffect(() => { if (credential && credential.data) { if (credential.data.vendor) { @@ -285,7 +295,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => { } account={[accountSid, setAccountSid]} required={false} - defaultOption={user?.scope !== USER_ACCOUNT} + defaultOption={checkOptions()} disabled={credential ? true : false} />