Skip to content

Commit

Permalink
Merge pull request #296 from app-masters/292-ajustes-no-admin
Browse files Browse the repository at this point in the history
Ajustes no Admin
  • Loading branch information
jfbaraky authored Jun 9, 2020
2 parents 8c2f325 + 28c2b8c commit a9ea9e3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 43 deletions.
32 changes: 16 additions & 16 deletions admin/src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,36 @@ const routes: RouteItem[] = [
icon: () => <BookOutlined />,
name: 'Validar Produtos'
},
// {
// path: '/relatorios',
// icon: () => <BarChartOutlined />,
// name: 'Relatórios'
// },
{
path: '/beneficios',
path: '/consumo',
icon: () => <CarryOutOutlined />,
name: 'Beneficios'
name: 'Informar consumo'
},
{
path: '/familias',
icon: () => <IdcardOutlined />,
name: 'Famílias'
},
{
path: '/beneficios',
icon: () => <CarryOutOutlined />,
name: 'Beneficios'
},
{
path: '/usuarios',
icon: () => <UserOutlined />,
name: 'Usuários'
},
{
path: '/consumo',
icon: () => <CarryOutOutlined />,
name: 'Informar consumo'
},
path: '/instituicoes',
icon: () => <BankOutlined />,
name: 'Instituições'
}
// {
// path: '/relatorios',
// icon: () => <BarChartOutlined />,
// name: 'Relatórios'
// },
// {
// path: '/lojas',
// icon: () => <ShopOutlined />,
Expand All @@ -76,11 +81,6 @@ const routes: RouteItem[] = [
// icon: () => <SolutionOutlined />,
// name: 'Estabelecimentos'
// },
{
path: '/instituicoes',
icon: () => <BankOutlined />,
name: 'Instituições'
}
];

const privateRoutes: RouteItem[] = [
Expand Down
2 changes: 1 addition & 1 deletion admin/src/pages/consumption/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const ConsumptionForm: React.FC<RouteComponentProps<{ id: string }>> = ()

return (
<PageContainer>
<Card title="Informar consumo">
<Card title={<Typography.Title>Informar consumo</Typography.Title>}>
<form style={{ marginBottom: 20 }} onSubmit={handleSubmit}>
<Form layout="vertical">
<ConsumptionFamilySearch onFamilySelect={(id) => setFieldValue('familyId', id)} />
Expand Down
7 changes: 1 addition & 6 deletions admin/src/pages/families/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ export const FamiliesList: React.FC<{}> = () => {
<PageContainer>
<Row gutter={[16, 16]}>
<Col span={24}>
<Typography.Title>{`Famílias`}</Typography.Title>
</Col>
</Row>
<Row gutter={[16, 16]}>
<Col span={24}>
<Card loading={dashboardLoading}>
<Card title={<Typography.Title>{`Famílias`}</Typography.Title>} loading={dashboardLoading}>
<Row gutter={[16, 16]}>
<Col span={8}>
<Statistic
Expand Down
47 changes: 28 additions & 19 deletions admin/src/pages/user/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ const { Option } = Select;

const schema = yup.object().shape({
name: yup.string().label('Nome').required(),
password: yup.string().label('Senha').required(),
password: yup
.string()
.label('Senha')
.when('isCreating', (isCreating: boolean | null | undefined, schema: yup.StringSchema) =>
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()
});

/**
Expand Down Expand Up @@ -57,10 +63,15 @@ export const UserForm: React.FC<RouteComponentProps<{ id: string }>> = (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(
Expand Down Expand Up @@ -108,21 +119,19 @@ export const UserForm: React.FC<RouteComponentProps<{ id: string }>> = (props) =
<Input id="email" name="email" onChange={handleChange} value={values.email} onPressEnter={submitForm} />
</Form.Item>

{isCreating && (
<Form.Item
label={'Senha'}
validateStatus={!!passwordMeta.error && !!passwordMeta.touched ? 'error' : ''}
help={!!passwordMeta.error && !!passwordMeta.touched ? passwordMeta.error : undefined}
>
<Input
id="password"
name="password"
onChange={handleChange}
value={values.password}
onPressEnter={submitForm}
/>
</Form.Item>
)}
<Form.Item
label={'Senha'}
validateStatus={!!passwordMeta.error && !!passwordMeta.touched ? 'error' : ''}
help={!!passwordMeta.error && !!passwordMeta.touched ? passwordMeta.error : undefined}
>
<Input
id="password"
name="password"
onChange={handleChange}
value={passwordMeta.touched ? values.password : undefined}
onPressEnter={submitForm}
/>
</Form.Item>

<Form.Item
label={'CPF'}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const updateById = async (
const cityItem = getById(id, cityId);
if (cityItem) {
// The update return an array [count, item[]], so I'm destructuring to get the updated user
const [, [item]] = await db.users.update(values, { where: { id }, returning: true });
const [, [item]] = await db.users.update(values, { where: { id }, returning: true, individualHooks: true });
return item;
}
return null;
Expand Down

0 comments on commit a9ea9e3

Please sign in to comment.