disable save when all fields are readonly (#31535)

fixes: #31304

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-07-30 14:20:51 +02:00 committed by GitHub
parent ca2b6dc754
commit 814e958e11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -95,6 +95,11 @@ export const PersonalInfo = () => {
return <Spinner />;
}
const allFieldsReadOnly = () =>
userProfileMetadata?.attributes
?.map((a) => a.readOnly)
.reduce((p, c) => p && c, true);
const {
updateEmailFeatureEnabled,
updateEmailActionEnabled,
@ -132,24 +137,26 @@ export const PersonalInfo = () => {
) : undefined
}
/>
<ActionGroup>
<Button
data-testid="save"
type="submit"
id="save-btn"
variant="primary"
>
{t("save")}
</Button>
<Button
data-testid="cancel"
id="cancel-btn"
variant="link"
onClick={() => reset()}
>
{t("cancel")}
</Button>
</ActionGroup>
{!allFieldsReadOnly() && (
<ActionGroup>
<Button
data-testid="save"
type="submit"
id="save-btn"
variant="primary"
>
{t("save")}
</Button>
<Button
data-testid="cancel"
id="cancel-btn"
variant="link"
onClick={() => reset()}
>
{t("cancel")}
</Button>
</ActionGroup>
)}
{context.environment.features.deleteAccountAllowed && (
<ExpandableSection
data-testid="delete-account"