Skip to content

Commit

Permalink
fix: fixed bug with opening/closing the modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Olezhka-web committed Sep 14, 2023
1 parent 7c8c0bc commit 603b2e9
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions plugins/sanity-lighthouse/src/components/PageSpeedInsightsGui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ const PageSpeedInsightsGui = ({client}: {client: SanityClient}) => {
const [activeRefreshID, setActiveRefreshID] = useState('')
const [activeRefreshDevice, setActiveRefreshDevice] = useState('')
const [errorMessage, setErrorMessage] = useState('')
const [secretsLoading, setSecretsLoading] = useState(true)
const [apiKey, setApiKey] = useState('')

const handleSecrets = () => {
setApiKey(secrets ? secrets[SECRETS_PLUGIN_CONFIG_KEYS[0].key] : '')
}
const [showSecretsModal, setShowSecretsModal] = useState(false)

useEffect(() => {
if (!loading) {
handleSecrets()
}
}, [secrets])
const secretKey = secrets ? secrets[SECRETS_PLUGIN_CONFIG_KEYS[0].key] : ''

useEffect(() => {
setSecretsLoading(loading)
}, [loading])
setShowSecretsModal(!secretKey)

setApiKey(secretKey)
}
}, [secrets, loading])

useEffect(() => {
const getDocumentById = async () => {
Expand Down Expand Up @@ -241,7 +237,7 @@ const PageSpeedInsightsGui = ({client}: {client: SanityClient}) => {

return (
<Container>
{apiKey ? (
{apiKey && (
<>
<Flex
direction={'column'}
Expand All @@ -252,7 +248,7 @@ const PageSpeedInsightsGui = ({client}: {client: SanityClient}) => {
<ButtonResetAll
style={{marginTop: '5px'}}
type="button"
onClick={() => setApiKey('')}
onClick={() => setShowSecretsModal(true)}
disabled={state === STATE_TYPE.loading}
>
Change API Key
Expand Down Expand Up @@ -315,14 +311,13 @@ const PageSpeedInsightsGui = ({client}: {client: SanityClient}) => {
)}
{state === STATE_TYPE.loading && !data.length && <CustomSpinner />}
</>
) : secretsLoading ? (
<CustomSpinner />
) : (
)}
{showSecretsModal && (
<SettingsView
title={'API KEY'}
namespace={SECRETS_NAMESPACE}
keys={SECRETS_PLUGIN_CONFIG_KEYS}
onClose={handleSecrets}
onClose={() => setShowSecretsModal(false)}
/>
)}
</Container>
Expand Down

0 comments on commit 603b2e9

Please sign in to comment.