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