From c7ab6b9e6c264caf71666537b2d9641c95bed928 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sun, 12 Sep 2021 17:24:31 -0600 Subject: [PATCH] ui(admin): fix validation rules on UserForm --- resources/scripts/api/admin/users/updateUser.ts | 4 ++++ .../scripts/components/admin/users/UserAboutContainer.tsx | 1 - resources/scripts/components/admin/users/UserForm.tsx | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/scripts/api/admin/users/updateUser.ts b/resources/scripts/api/admin/users/updateUser.ts index 7b7657aa6..806a62618 100644 --- a/resources/scripts/api/admin/users/updateUser.ts +++ b/resources/scripts/api/admin/users/updateUser.ts @@ -12,6 +12,10 @@ export interface Values { export default (id: number, values: Partial, include: string[] = []): Promise => { const data = {}; Object.keys(values).forEach(k => { + // Don't set password if it is empty. + if (k === 'password' && values[k] === '') { + return; + } // @ts-ignore data[k.replace(/[A-Z]/g, l => `_${l.toLowerCase()}`)] = values[k]; }); diff --git a/resources/scripts/components/admin/users/UserAboutContainer.tsx b/resources/scripts/components/admin/users/UserAboutContainer.tsx index b0363b2d6..0449c9d46 100644 --- a/resources/scripts/components/admin/users/UserAboutContainer.tsx +++ b/resources/scripts/components/admin/users/UserAboutContainer.tsx @@ -47,7 +47,6 @@ const UserAboutContainer = () => { }} onSubmit={submit} role={user?.relationships.role || null} - exists >
) => void; - exists?: boolean; 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) => { onSubmit(values, helpers); }; @@ -59,7 +58,6 @@ export default function UserForm ({ title, initialValues, children, onSubmit, ex validationSchema={object().shape({ username: string().min(1).max(32), email: string(), - password: exists ? string() : string().required(), rootAdmin: bool().required(), })} >