only enable form save button when config has changed
This commit is contained in:
parent
0fa68a2d50
commit
30558ad3bd
|
@ -6,6 +6,7 @@
|
||||||
import OktaLogo from "assets/okta-logo.png"
|
import OktaLogo from "assets/okta-logo.png"
|
||||||
import OneLoginLogo from "assets/onelogin-logo.png"
|
import OneLoginLogo from "assets/onelogin-logo.png"
|
||||||
import OidcLogoPng from "assets/oidc-logo.png"
|
import OidcLogoPng from "assets/oidc-logo.png"
|
||||||
|
import { isEqual, cloneDeep } from "lodash/fp"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
@ -91,18 +92,22 @@
|
||||||
let google
|
let google
|
||||||
let oidc
|
let oidc
|
||||||
const providers = { google, oidc }
|
const providers = { google, oidc }
|
||||||
|
|
||||||
|
// control the state of the save button depending on whether form has changed
|
||||||
|
let originalGoogleDoc
|
||||||
|
let originalOidcDoc
|
||||||
let googleSaveButtonDisabled
|
let googleSaveButtonDisabled
|
||||||
let oidcSaveButtonDisabled
|
let oidcSaveButtonDisabled
|
||||||
|
$: {
|
||||||
$: googleSaveButtonDisabled =
|
isEqual(providers.google, originalGoogleDoc)
|
||||||
providers.google?.config && !providers.google?.config.activated && true
|
? (googleSaveButtonDisabled = true)
|
||||||
$: oidcSaveButtonDisabled =
|
: (googleSaveButtonDisabled = false)
|
||||||
providers.oidc?.config.configs[0] &&
|
isEqual(providers.oidc, originalOidcDoc)
|
||||||
!providers.oidc?.config.configs[0].activated &&
|
? (oidcSaveButtonDisabled = true)
|
||||||
true
|
: (oidcSaveButtonDisabled = false)
|
||||||
|
}
|
||||||
|
|
||||||
// Create a flag so that it will only try to save completed forms
|
// Create a flag so that it will only try to save completed forms
|
||||||
|
|
||||||
$: partialGoogle =
|
$: partialGoogle =
|
||||||
providers.google?.config?.clientID ||
|
providers.google?.config?.clientID ||
|
||||||
providers.google?.config?.clientSecret ||
|
providers.google?.config?.clientSecret ||
|
||||||
|
@ -138,22 +143,6 @@
|
||||||
iconDropdownOptions.unshift({ label: fileName, value: fileName })
|
iconDropdownOptions.unshift({ label: fileName, value: fileName })
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleGoogle = ({ detail }) => {
|
|
||||||
// Only save on de-activation, as the user can save themselves when toggle is active
|
|
||||||
if (!detail) {
|
|
||||||
providers.google.config.activated = detail
|
|
||||||
save([providers.google])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleOidc = ({ detail }) => {
|
|
||||||
// Only save on de-activation, as the user can save themselves when toggle is active
|
|
||||||
if (!detail) {
|
|
||||||
providers.oidc.config.configs[0].activated = detail
|
|
||||||
save([providers.oidc])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function save(docs) {
|
async function save(docs) {
|
||||||
// only if the user has provided an image, upload it.
|
// only if the user has provided an image, upload it.
|
||||||
image && uploadLogo(image)
|
image && uploadLogo(image)
|
||||||
|
@ -225,6 +214,7 @@
|
||||||
config: { activated: true },
|
config: { activated: true },
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
originalGoogleDoc = googleDoc
|
||||||
providers.google = googleDoc
|
providers.google = googleDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,13 +237,15 @@
|
||||||
}
|
}
|
||||||
const oidcResponse = await api.get(`/api/admin/configs/${ConfigTypes.OIDC}`)
|
const oidcResponse = await api.get(`/api/admin/configs/${ConfigTypes.OIDC}`)
|
||||||
const oidcDoc = await oidcResponse.json()
|
const oidcDoc = await oidcResponse.json()
|
||||||
|
console.log("teaste")
|
||||||
if (!oidcDoc._id) {
|
if (!oidcDoc._id) {
|
||||||
providers.oidc = {
|
providers.oidc = {
|
||||||
type: ConfigTypes.OIDC,
|
type: ConfigTypes.OIDC,
|
||||||
config: { configs: [{ activated: true }] },
|
config: { configs: [{ activated: true }] },
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log("hello")
|
||||||
|
originalOidcDoc = cloneDeep(oidcDoc)
|
||||||
providers.oidc = oidcDoc
|
providers.oidc = oidcDoc
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -303,11 +295,7 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Activated</Label>
|
<Label size="L">Activated</Label>
|
||||||
<span class="alignedToggle">
|
<span class="alignedToggle">
|
||||||
<Toggle
|
<Toggle text="" bind:value={providers.google.config.activated} />
|
||||||
text=""
|
|
||||||
on:change={toggleGoogle}
|
|
||||||
bind:value={providers.google.config.activated}
|
|
||||||
/>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -377,7 +365,6 @@
|
||||||
<span class="alignedToggle">
|
<span class="alignedToggle">
|
||||||
<Toggle
|
<Toggle
|
||||||
text=""
|
text=""
|
||||||
on:change={toggleOidc}
|
|
||||||
bind:value={providers.oidc.config.configs[0].activated}
|
bind:value={providers.oidc.config.configs[0].activated}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue