Activate Save Button in Client Scopes on first modification (#30269)

Signed-off-by: Ahana Mallik <ahanamallik@gmail.com>
This commit is contained in:
Ahana Mallik 2024-06-10 22:59:22 +02:00 committed by GitHub
parent 75925dcf6c
commit 51d80a42d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,6 +33,7 @@ export const ScopeForm = ({ clientScope, save }: ScopeFormProps) => {
const { t } = useTranslation();
const form = useForm<ClientScopeDefaultOptionalType>({ mode: "onChange" });
const { control, handleSubmit, setValue, formState } = form;
const { isDirty, isValid } = formState;
const { realm } = useRealm();
const providers = useLoginProviders();
@ -60,12 +61,12 @@ export const ScopeForm = ({ clientScope, save }: ScopeFormProps) => {
"attributes.dynamic.scope.regexp",
),
append ? `${value}:*` : value,
{ shouldDirty: true }, // Mark the field as dirty when we modify the field
);
useEffect(() => {
convertToFormValues(clientScope ?? {}, setValue);
}, [clientScope]);
return (
<FormAccess
role="manage-clients"
@ -187,7 +188,12 @@ export const ScopeForm = ({ clientScope, save }: ScopeFormProps) => {
min={0}
/>
<ActionGroup>
<FormSubmitButton formState={formState}>{t("save")}</FormSubmitButton>
<FormSubmitButton
formState={formState}
disabled={!isDirty || !isValid}
>
{t("save")}
</FormSubmitButton>
<Button
variant="link"
component={(props) => (