From 28c2b8cc435bba76c44cb14ae14165bb25b0558d Mon Sep 17 00:00:00 2001 From: Allan Amaral Date: Mon, 8 Jun 2020 10:53:36 -0300 Subject: [PATCH] #292 - Adjustments in the Admin --- admin/src/components/sidebar/index.tsx | 32 +++++++++--------- admin/src/pages/consumption/index.tsx | 2 +- admin/src/pages/families/list.tsx | 7 +--- admin/src/pages/user/form.tsx | 47 +++++++++++++++----------- backend/src/models/users.ts | 2 +- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/admin/src/components/sidebar/index.tsx b/admin/src/components/sidebar/index.tsx index c85b5e8c..601d508b 100644 --- a/admin/src/components/sidebar/index.tsx +++ b/admin/src/components/sidebar/index.tsx @@ -41,31 +41,36 @@ const routes: RouteItem[] = [ icon: () => , name: 'Validar Produtos' }, - // { - // path: '/relatorios', - // icon: () => , - // name: 'Relatórios' - // }, { - path: '/beneficios', + path: '/consumo', icon: () => , - name: 'Beneficios' + name: 'Informar consumo' }, { path: '/familias', icon: () => , name: 'Famílias' }, + { + path: '/beneficios', + icon: () => , + name: 'Beneficios' + }, { path: '/usuarios', icon: () => , name: 'Usuários' }, { - path: '/consumo', - icon: () => , - name: 'Informar consumo' - }, + path: '/instituicoes', + icon: () => , + name: 'Instituições' + } + // { + // path: '/relatorios', + // icon: () => , + // name: 'Relatórios' + // }, // { // path: '/lojas', // icon: () => , @@ -76,11 +81,6 @@ const routes: RouteItem[] = [ // icon: () => , // name: 'Estabelecimentos' // }, - { - path: '/instituicoes', - icon: () => , - name: 'Instituições' - } ]; const privateRoutes: RouteItem[] = [ diff --git a/admin/src/pages/consumption/index.tsx b/admin/src/pages/consumption/index.tsx index b69997de..c9bd2731 100644 --- a/admin/src/pages/consumption/index.tsx +++ b/admin/src/pages/consumption/index.tsx @@ -124,7 +124,7 @@ export const ConsumptionForm: React.FC> = () return ( - + Informar consumo}>
setFieldValue('familyId', id)} /> diff --git a/admin/src/pages/families/list.tsx b/admin/src/pages/families/list.tsx index 7f1c935f..966800f3 100644 --- a/admin/src/pages/families/list.tsx +++ b/admin/src/pages/families/list.tsx @@ -111,12 +111,7 @@ export const FamiliesList: React.FC<{}> = () => { - {`Famílias`} - - - - - + {`Famílias`}} loading={dashboardLoading}> + isCreating ? schema.required() : schema + ), cpf: yup.string().label('CPF').required(), email: yup.string().label('Email').required(), - role: yup.string().label('Cargo').required() + role: yup.string().label('Cargo').required(), + isCreating: yup.boolean().label('CriandoUsuario').nullable() }); /** @@ -57,10 +63,15 @@ export const UserForm: React.FC> = (props) = cpf: '', email: '', role: 'admin', - active: false + active: false, + isCreating }, validationSchema: schema, - onSubmit: (values, { setStatus }) => { + onSubmit: (formikValues, { setStatus }) => { + const values = { ...formikValues }; + // Prevent sending an empty password when editing an already existing user + if (!isCreating && user && !values.password) values.password = user.password; + setStatus(); dispatch( requestSaveUser( @@ -108,21 +119,19 @@ export const UserForm: React.FC> = (props) = - {isCreating && ( - - - - )} + + +