ui(admin): fix validation rules on UserForm
This commit is contained in:
parent
38ff35873e
commit
c7ab6b9e6c
3 changed files with 5 additions and 4 deletions
|
@ -12,6 +12,10 @@ export interface Values {
|
||||||
export default (id: number, values: Partial<Values>, include: string[] = []): Promise<User> => {
|
export default (id: number, values: Partial<Values>, include: string[] = []): Promise<User> => {
|
||||||
const data = {};
|
const data = {};
|
||||||
Object.keys(values).forEach(k => {
|
Object.keys(values).forEach(k => {
|
||||||
|
// Don't set password if it is empty.
|
||||||
|
if (k === 'password' && values[k] === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
data[k.replace(/[A-Z]/g, l => `_${l.toLowerCase()}`)] = values[k];
|
data[k.replace(/[A-Z]/g, l => `_${l.toLowerCase()}`)] = values[k];
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,7 +47,6 @@ const UserAboutContainer = () => {
|
||||||
}}
|
}}
|
||||||
onSubmit={submit}
|
onSubmit={submit}
|
||||||
role={user?.relationships.role || null}
|
role={user?.relationships.role || null}
|
||||||
exists
|
|
||||||
>
|
>
|
||||||
<div css={tw`flex`}>
|
<div css={tw`flex`}>
|
||||||
<UserDeleteButton
|
<UserDeleteButton
|
||||||
|
|
|
@ -32,12 +32,11 @@ export interface Params {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
|
||||||
onSubmit: (values: Values, helpers: FormikHelpers<Values>) => void;
|
onSubmit: (values: Values, helpers: FormikHelpers<Values>) => void;
|
||||||
exists?: boolean;
|
|
||||||
|
|
||||||
role: Role | null;
|
role: Role | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function UserForm ({ title, initialValues, children, onSubmit, exists, role }: Params) {
|
export default function UserForm ({ title, initialValues, children, onSubmit, role }: Params) {
|
||||||
const submit = (values: Values, helpers: FormikHelpers<Values>) => {
|
const submit = (values: Values, helpers: FormikHelpers<Values>) => {
|
||||||
onSubmit(values, helpers);
|
onSubmit(values, helpers);
|
||||||
};
|
};
|
||||||
|
@ -59,7 +58,6 @@ export default function UserForm ({ title, initialValues, children, onSubmit, ex
|
||||||
validationSchema={object().shape({
|
validationSchema={object().shape({
|
||||||
username: string().min(1).max(32),
|
username: string().min(1).max(32),
|
||||||
email: string(),
|
email: string(),
|
||||||
password: exists ? string() : string().required(),
|
|
||||||
rootAdmin: bool().required(),
|
rootAdmin: bool().required(),
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue