Move React Hook Form errors to formState (#2412)
This commit is contained in:
parent
818b8cdbb9
commit
4a7c0436cc
42 changed files with 208 additions and 59 deletions
|
@ -43,8 +43,12 @@ export const ExecutionConfigModal = ({
|
|||
const [configDescription, setConfigDescription] =
|
||||
useState<AuthenticatorConfigInfoRepresentation>();
|
||||
|
||||
const { register, errors, setValue, handleSubmit } =
|
||||
useForm<ExecutionConfigModalForm>();
|
||||
const {
|
||||
register,
|
||||
setValue,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<ExecutionConfigModalForm>();
|
||||
|
||||
const setupForm = (
|
||||
configDescription: AuthenticatorConfigInfoRepresentation,
|
||||
|
|
|
@ -40,7 +40,12 @@ export const AddSubFlowModal = ({
|
|||
onCancel,
|
||||
}: AddSubFlowProps) => {
|
||||
const { t } = useTranslation("authentication");
|
||||
const { register, control, errors, handleSubmit } = useForm<Flow>();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<Flow>();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [openProvider, setOpenProvider] = useState(false);
|
||||
const [formProviders, setFormProviders] =
|
||||
|
|
|
@ -12,7 +12,10 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|||
|
||||
export const NameDescription = () => {
|
||||
const { t } = useTranslation("authentication");
|
||||
const { register, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -41,10 +41,9 @@ export const OtpPolicy = ({ realm, realmUpdated }: OtpPolicyProps) => {
|
|||
const {
|
||||
control,
|
||||
register,
|
||||
errors,
|
||||
reset,
|
||||
handleSubmit,
|
||||
formState: { isDirty },
|
||||
formState: { isDirty, errors },
|
||||
} = useForm({ mode: "onChange" });
|
||||
const adminClient = useAdminClient();
|
||||
const { realm: realmName } = useRealm();
|
||||
|
|
|
@ -27,7 +27,11 @@ export const PolicyRow = ({
|
|||
onRemove,
|
||||
}: PolicyRowProps) => {
|
||||
const { t } = useTranslation("authentication");
|
||||
const { control, register, errors } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
return (
|
||||
<FormGroup
|
||||
label={displayName}
|
||||
|
|
|
@ -37,10 +37,15 @@ type ScopeFormProps = {
|
|||
export const ScopeForm = ({ clientScope, save }: ScopeFormProps) => {
|
||||
const { t } = useTranslation("client-scopes");
|
||||
const { t: tc } = useTranslation("clients");
|
||||
const { register, control, handleSubmit, errors, setValue } =
|
||||
useForm<ClientScopeRepresentation>({
|
||||
defaultValues: { attributes: { "display.on.consent.screen": "true" } },
|
||||
});
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<ClientScopeRepresentation>({
|
||||
defaultValues: { attributes: { "display.on.consent.screen": "true" } },
|
||||
});
|
||||
const { realm } = useRealm();
|
||||
|
||||
const providers = useLoginProviders();
|
||||
|
|
|
@ -19,7 +19,11 @@ type ClientDescriptionProps = {
|
|||
|
||||
export const ClientDescription = ({ protocol }: ClientDescriptionProps) => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { register, errors, control } = useFormContext<ClientRepresentation>();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext<ClientRepresentation>();
|
||||
return (
|
||||
<FormAccess role="manage-clients" unWrap>
|
||||
<FormGroup
|
||||
|
|
|
@ -38,8 +38,12 @@ export const ClientSettings = ({
|
|||
save,
|
||||
reset,
|
||||
}: ClientSettingsProps) => {
|
||||
const { register, control, watch, errors } =
|
||||
useFormContext<ClientRepresentation>();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useFormContext<ClientRepresentation>();
|
||||
const { t } = useTranslation("clients");
|
||||
const { realm } = useRealm();
|
||||
|
||||
|
|
|
@ -16,7 +16,10 @@ import { getProtocolName } from "../utils";
|
|||
|
||||
export const GeneralSettings = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { errors, control } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const providers = useLoginProviders();
|
||||
const [open, isOpen] = useState(false);
|
||||
|
|
|
@ -32,7 +32,10 @@ export const ResourcesPolicySelect = ({
|
|||
const { t } = useTranslation("clients");
|
||||
const adminClient = useAdminClient();
|
||||
|
||||
const { control, errors } = useFormContext<PolicyRepresentation>();
|
||||
const {
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext<PolicyRepresentation>();
|
||||
const [items, setItems] = useState<Policies[]>([]);
|
||||
const [search, setSearch] = useState("");
|
||||
const [open, setOpen] = useState(false);
|
||||
|
|
|
@ -35,10 +35,14 @@ export default function ScopeDetails() {
|
|||
|
||||
const [deleteDialog, toggleDeleteDialog] = useToggle();
|
||||
const [scope, setScope] = useState<ScopeRepresentation>();
|
||||
const { register, errors, reset, handleSubmit } =
|
||||
useForm<ScopeRepresentation>({
|
||||
mode: "onChange",
|
||||
});
|
||||
const {
|
||||
register,
|
||||
reset,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<ScopeRepresentation>({
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
useFetch(
|
||||
async () => {
|
||||
|
|
|
@ -20,7 +20,11 @@ export const ScopeSelect = ({
|
|||
const { t } = useTranslation("clients");
|
||||
const adminClient = useAdminClient();
|
||||
|
||||
const { control, errors, setValue } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const [scopes, setScopes] = useState<ScopeRepresentation[]>([]);
|
||||
const [search, setSearch] = useState("");
|
||||
|
|
|
@ -15,7 +15,11 @@ import { useTranslation } from "react-i18next";
|
|||
|
||||
export const Client = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { control, getValues, errors } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const values: string[] | undefined = getValues("clients");
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
|
|
@ -25,7 +25,12 @@ export type RequiredIdValue = {
|
|||
|
||||
export const ClientScope = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { control, getValues, setValue, errors } = useFormContext<{
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useFormContext<{
|
||||
clientScopes: RequiredIdValue[];
|
||||
}>();
|
||||
|
||||
|
|
|
@ -24,7 +24,13 @@ export type GroupValue = {
|
|||
|
||||
export const Group = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { control, register, getValues, setValue, errors } = useFormContext<{
|
||||
const {
|
||||
control,
|
||||
register,
|
||||
getValues,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useFormContext<{
|
||||
groups?: GroupValue[];
|
||||
}>();
|
||||
const values = getValues("groups");
|
||||
|
|
|
@ -16,7 +16,10 @@ type NameDescriptionProps = {
|
|||
|
||||
export const NameDescription = ({ prefix }: NameDescriptionProps) => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { register, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -7,7 +7,10 @@ import { HelpItem } from "../../../components/help-enabler/HelpItem";
|
|||
|
||||
export const Regex = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { register, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -20,7 +20,12 @@ import { AddRoleMappingModal } from "../../../components/role-mapping/AddRoleMap
|
|||
|
||||
export const Role = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { control, getValues, setValue, errors } = useFormContext<{
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useFormContext<{
|
||||
roles?: RequiredIdValue[];
|
||||
}>();
|
||||
const values = getValues("roles");
|
||||
|
|
|
@ -15,7 +15,11 @@ import { useTranslation } from "react-i18next";
|
|||
|
||||
export const User = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { control, getValues, errors } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const values: string[] | undefined = getValues("users");
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
|
|
@ -11,7 +11,11 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|||
|
||||
export const X509 = () => {
|
||||
const { t } = useTranslation("clients");
|
||||
const { register, control, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
return (
|
||||
<>
|
||||
<FormGroup
|
||||
|
|
|
@ -27,8 +27,7 @@ export default function CreateInitialAccessToken() {
|
|||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
errors,
|
||||
formState: { isValid },
|
||||
formState: { isValid, errors },
|
||||
} = useForm({ mode: "onChange" });
|
||||
|
||||
const adminClient = useAdminClient();
|
||||
|
|
|
@ -34,7 +34,11 @@ export const RoleComponent = ({
|
|||
|
||||
const adminClient = useAdminClient();
|
||||
const { realm } = useRealm();
|
||||
const { control, errors, getValues } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const [roleOpen, setRoleOpen] = useState(false);
|
||||
const [clientsOpen, setClientsOpen] = useState(false);
|
||||
|
|
|
@ -33,7 +33,11 @@ export const GroupsModal = ({
|
|||
const { t } = useTranslation("groups");
|
||||
const adminClient = useAdminClient();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
const { register, errors, handleSubmit } = useForm({
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
defaultValues: { name: rename },
|
||||
});
|
||||
|
||||
|
|
|
@ -24,7 +24,11 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
|
|||
const { t } = useTranslation("identity-providers");
|
||||
const { t: th } = useTranslation("identity-providers-help");
|
||||
|
||||
const { register, control, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const [namedPolicyDropdownOpen, setNamedPolicyDropdownOpen] = useState(false);
|
||||
const [principalTypeDropdownOpen, setPrincipalTypeDropdownOpen] =
|
||||
useState(false);
|
||||
|
|
|
@ -19,7 +19,11 @@ type DiscoverySettingsProps = {
|
|||
|
||||
const Fields = ({ readOnly }: DiscoverySettingsProps) => {
|
||||
const { t } = useTranslation("identity-providers");
|
||||
const { register, control, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const validateSignature = useWatch({
|
||||
control: control,
|
||||
|
|
|
@ -14,7 +14,10 @@ export const OIDCGeneralSettings = ({ id }: { id: string }) => {
|
|||
const { t } = useTranslation("identity-providers");
|
||||
const { tab } = useParams<IdentityProviderParams>();
|
||||
|
||||
const { register, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -17,7 +17,12 @@ export const OpenIdConnectSettings = () => {
|
|||
|
||||
const adminClient = useAdminClient();
|
||||
const { realm } = useRealm();
|
||||
const { setValue, errors, setError, clearErrors } = useFormContext();
|
||||
const {
|
||||
setValue,
|
||||
setError,
|
||||
clearErrors,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const setupForm = (result: any) => {
|
||||
Object.keys(result).map((k) => setValue(`config.${k}`, result[k]));
|
||||
|
|
|
@ -20,8 +20,13 @@ export const SamlConnectSettings = () => {
|
|||
|
||||
const adminClient = useAdminClient();
|
||||
const { realm } = useRealm();
|
||||
const { setValue, register, errors, setError, clearErrors } =
|
||||
useFormContext();
|
||||
const {
|
||||
setValue,
|
||||
register,
|
||||
setError,
|
||||
clearErrors,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const setupForm = (result: IdentityProviderRepresentation) => {
|
||||
Object.entries(result).map(([key, value]) =>
|
||||
|
|
|
@ -20,7 +20,11 @@ export const SamlGeneralSettings = ({ id }: { id: string }) => {
|
|||
const { realm } = useRealm();
|
||||
const { tab } = useParams<IdentityProviderParams>();
|
||||
|
||||
const { register, errors, watch } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
const alias = watch("alias");
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ export const ClientIdSecret = ({
|
|||
}) => {
|
||||
const { t } = useTranslation("identity-providers");
|
||||
|
||||
const { register, errors } = useFormContext();
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -22,8 +22,14 @@ export const DiscoveryEndpointField = ({
|
|||
|
||||
const adminClient = useAdminClient();
|
||||
|
||||
const { setValue, register, errors, setError, watch, clearErrors } =
|
||||
useFormContext();
|
||||
const {
|
||||
setValue,
|
||||
register,
|
||||
setError,
|
||||
watch,
|
||||
clearErrors,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const discoveryUrl = watch("discoveryEndpoint");
|
||||
|
||||
const [discovery, setDiscovery] = useState(true);
|
||||
|
|
|
@ -30,7 +30,11 @@ export const AddMessageBundleModal = ({
|
|||
save,
|
||||
}: AddMessageBundleModalProps) => {
|
||||
const { t } = useTranslation("realm-settings");
|
||||
const { register, errors, handleSubmit } = useForm();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
|
|
@ -30,7 +30,12 @@ export const AddUserEmailModal = ({ callback }: AddUserEmailModalProps) => {
|
|||
const { t } = useTranslation("groups");
|
||||
const adminClient = useAdminClient();
|
||||
const { whoAmI } = useWhoAmI();
|
||||
const { register, errors, handleSubmit, watch } = useForm<AddUserEmailForm>({
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useForm<AddUserEmailForm>({
|
||||
defaultValues: { email: "" },
|
||||
});
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ export default function ClientProfileForm() {
|
|||
handleSubmit,
|
||||
setValue,
|
||||
register,
|
||||
errors,
|
||||
formState: { isDirty },
|
||||
formState: { isDirty, errors },
|
||||
} = useForm<ClientProfileForm>({
|
||||
defaultValues,
|
||||
mode: "onChange",
|
||||
|
|
|
@ -44,10 +44,10 @@ export const RealmSettingsEmailTab = ({
|
|||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
errors,
|
||||
watch,
|
||||
reset: resetForm,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<RealmRepresentation>({ defaultValues: realm });
|
||||
|
||||
const reset = () => resetForm(realm);
|
||||
|
|
|
@ -65,7 +65,10 @@ type PolicyDetailAttributes = {
|
|||
|
||||
export default function NewClientPolicyForm() {
|
||||
const { t } = useTranslation("realm-settings");
|
||||
const { errors, reset: resetForm } = useForm<NewClientPolicyForm>({
|
||||
const {
|
||||
reset: resetForm,
|
||||
formState: { errors },
|
||||
} = useForm<NewClientPolicyForm>({
|
||||
defaultValues,
|
||||
});
|
||||
const { realm } = useRealm();
|
||||
|
|
|
@ -14,7 +14,10 @@ export const Time = ({
|
|||
style?: CSSProperties;
|
||||
}) => {
|
||||
const { t } = useTranslation("realm-settings");
|
||||
const { control, errors } = useFormContext();
|
||||
const {
|
||||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
return (
|
||||
<FormGroup
|
||||
style={style}
|
||||
|
|
|
@ -29,8 +29,13 @@ export default function NewRealmForm() {
|
|||
const adminClient = useAdminClient();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
|
||||
const { register, handleSubmit, control, errors, setValue } =
|
||||
useForm<RealmRepresentation>({ mode: "onChange" });
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
control,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<RealmRepresentation>({ mode: "onChange" });
|
||||
|
||||
const handleFileChange = (obj: object) => {
|
||||
const defaultRealm = { id: "", realm: "", enabled: true };
|
||||
|
|
|
@ -37,7 +37,11 @@ export const RevocationModal = ({
|
|||
|
||||
const { realm: realmName } = useRealm();
|
||||
const adminClient = useAdminClient();
|
||||
const { register, errors, handleSubmit } = useForm();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm();
|
||||
const [realm, setRealm] = useState<RealmRepresentation>();
|
||||
|
||||
const [key, setKey] = useState(0);
|
||||
|
|
|
@ -60,8 +60,14 @@ export const UserForm = ({
|
|||
const adminClient = useAdminClient();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
|
||||
const { handleSubmit, register, errors, watch, control, reset } =
|
||||
useFormContext();
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
watch,
|
||||
control,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const watchUsernameInput = watch("username");
|
||||
const [selectedGroups, setSelectedGroups] = useState<GroupRepresentation[]>(
|
||||
[]
|
||||
|
|
|
@ -35,7 +35,11 @@ export const UserIdpModal = ({
|
|||
const { t } = useTranslation("users");
|
||||
const adminClient = useAdminClient();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
const { register, errors, handleSubmit, formState } = useForm({
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { isValid, errors },
|
||||
} = useForm({
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
|
@ -71,7 +75,7 @@ export const UserIdpModal = ({
|
|||
variant="primary"
|
||||
type="submit"
|
||||
form="group-form"
|
||||
isDisabled={!formState.isValid}
|
||||
isDisabled={!isValid}
|
||||
>
|
||||
{t("link")}
|
||||
</Button>,
|
||||
|
|
|
@ -50,8 +50,7 @@ export const ResetPasswordDialog = ({
|
|||
const {
|
||||
register,
|
||||
control,
|
||||
errors,
|
||||
formState: { isValid },
|
||||
formState: { isValid, errors },
|
||||
watch,
|
||||
handleSubmit,
|
||||
} = useForm<CredentialsForm>({
|
||||
|
|
Loading…
Reference in a new issue