From 2c933cdd2df172da5922e2167a7c7905779ae541 Mon Sep 17 00:00:00 2001 From: Mateusz Pietryga Date: Sun, 14 Apr 2024 16:52:37 +0200 Subject: [PATCH] Feat: UI for OAuth2 Credentials independent of the Request Output pane #1999 #1003 --- .../Auth/OAuth2/AuthorizationCode/index.js | 21 ------- .../Auth/OAuth2/ClientCredentials/index.js | 20 ------- .../Auth/OAuth2/CredentialsPreview/index.js | 57 +++++++++++++++++++ .../Auth/OAuth2/Implicit/index.js | 20 ------- .../Auth/OAuth2/PasswordCredentials/index.js | 22 +------ .../CollectionSettings/Auth/OAuth2/index.js | 2 + .../Auth/OAuth2/AuthorizationCode/index.js | 20 ------- .../Auth/OAuth2/ClientCredentials/index.js | 20 ------- .../Auth/OAuth2/CredentialsPreview/index.js | 57 +++++++++++++++++++ .../RequestPane/Auth/OAuth2/Implicit/index.js | 8 --- .../Auth/OAuth2/PasswordCredentials/index.js | 22 +------ .../RequestPane/Auth/OAuth2/index.js | 2 + packages/bruno-app/src/utils/network/index.js | 7 +++ .../bruno-electron/src/ipc/network/index.js | 11 ++++ 14 files changed, 138 insertions(+), 151 deletions(-) create mode 100644 packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/CredentialsPreview/index.js create mode 100644 packages/bruno-app/src/components/RequestPane/Auth/OAuth2/CredentialsPreview/index.js diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/AuthorizationCode/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/AuthorizationCode/index.js index 674db53a89..52a391fd59 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/AuthorizationCode/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/AuthorizationCode/index.js @@ -7,8 +7,6 @@ import { saveCollectionRoot, sendCollectionOauth2Request } from 'providers/Redux import StyledWrapper from './StyledWrapper'; import { inputsConfig } from './inputsConfig'; import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections/index'; -import { clearOauth2Cache } from 'utils/network/index'; -import toast from 'react-hot-toast'; const OAuth2AuthorizationCode = ({ collection }) => { const dispatch = useDispatch(); @@ -62,17 +60,6 @@ const OAuth2AuthorizationCode = ({ collection }) => { }) ); }; - - const handleClearCache = (e) => { - clearOauth2Cache(collection?.uid) - .then(() => { - toast.success('cleared cache successfully'); - }) - .catch((err) => { - toast.error(err.message); - }); - }; - return ( {inputsConfig.map((input) => { @@ -102,14 +89,6 @@ const OAuth2AuthorizationCode = ({ collection }) => { onChange={handlePKCEToggle} /> -
- - -
); }; diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/ClientCredentials/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/ClientCredentials/index.js index 07e3a77ae3..4e3193bd36 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/ClientCredentials/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/ClientCredentials/index.js @@ -7,8 +7,6 @@ import { saveCollectionRoot, sendCollectionOauth2Request } from 'providers/Redux import StyledWrapper from './StyledWrapper'; import { inputsConfig } from './inputsConfig'; import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections/index'; -import { clearOauth2Cache } from 'utils/network'; -import toast from 'react-hot-toast'; const OAuth2ClientCredentials = ({ collection }) => { const dispatch = useDispatch(); @@ -41,16 +39,6 @@ const OAuth2ClientCredentials = ({ collection }) => { ); }; - const handleClearCache = (e) => { - clearOauth2Cache(collection?.uid) - .then(() => { - toast.success('cleared cache successfully'); - }) - .catch((err) => { - toast.error(err.message); - }); - }; - return ( {inputsConfig.map((input) => { @@ -71,14 +59,6 @@ const OAuth2ClientCredentials = ({ collection }) => { ); })} -
- - -
); }; diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/CredentialsPreview/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/CredentialsPreview/index.js new file mode 100644 index 0000000000..a6afbef0c4 --- /dev/null +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/CredentialsPreview/index.js @@ -0,0 +1,57 @@ +import React, { useEffect, useState } from 'react'; +import { clearOauth2Cache, readOauth2CachedCredentials } from 'utils/network'; +import { sendCollectionOauth2Request } from 'providers/ReduxStore/slices/collections/actions'; +import toast from 'react-hot-toast'; +import { useDispatch } from 'react-redux'; + +const CredentialsPreview = ({ collection }) => { + const oauth2CredentialsAreaRef = React.createRef(); + const [oauth2Credentials, setOauth2Credentials] = useState({}); + const dispatch = useDispatch(); + + useEffect(() => { + oauth2CredentialsAreaRef.current.value = oauth2Credentials; + readOauth2CachedCredentials(collection.uid).then((credentials) => setOauth2Credentials(credentials)); + }, [oauth2CredentialsAreaRef]); + + const handleRun = async () => { + dispatch(sendCollectionOauth2Request(collection.uid)); + }; + + const handleClearCache = (e) => { + clearOauth2Cache(collection?.uid) + .then(() => { + readOauth2CachedCredentials(collection.uid).then((credentials) => { + setOauth2Credentials(credentials); + toast.success('cleared cache successfully'); + }); + }) + .catch((err) => { + toast.error(err.message); + }); + }; + + return ( +
+
+ + +
+
+ + {Object.entries(oauth2Credentials).map(([key, value]) => ( +
+ +