Skip to content

Commit

Permalink
Complete fields validation
Browse files Browse the repository at this point in the history
Related to issue #4;
Related to issue #2;

Signed-off by: antoniocoj <_antonio_@hotmail.com>
Signed-off-by: Lucas Amoêdo <lucas_advc@outlook.com>
  • Loading branch information
antoniocoj committed Apr 28, 2017
1 parent 8fc345b commit 7cd6cb7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
30 changes: 15 additions & 15 deletions src/Categories/Owners/OwnerCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,41 @@ export class OwnerCreate extends Component {
contentType: 'application/json',
statusCode: {
200: (data) => {
// console.log(data);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'publicPlace',
`${data.tipoDeLogradouro} ${data.logradouro}`),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'neighborhood',
data.bairro,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'city',
data.cidade,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'district',
data.estado,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'addressNumber',
'',
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'complement',
Expand All @@ -108,22 +107,22 @@ export class OwnerCreate extends Component {
<TextInput
source="cpf"
label="CPF"
validate={ required }
validate={required}
/>
<TextInput
source="ownerName"
label="Primeiro Nome"
validate={ required }
validate={required}
/>
<TextInput
source="ownerLastName"
label="Sobrenome"
validate={ required }
validate={required}
/>
<TextInput
source="phoneNumber"
label="Telefone"
validate={ required }
validate={required}
/>
<TextInput
source="zipCode"
Expand All @@ -133,12 +132,12 @@ export class OwnerCreate extends Component {
<TextInput
source="publicPlace"
label="Endereço"
validate={ required }
validate={required}
/>
<TextInput
source="addressNumber"
label="Número"
validate={ required }
validate={required}
/>
<TextInput
source="complement"
Expand All @@ -147,17 +146,18 @@ export class OwnerCreate extends Component {
<TextInput
source="neighborhood"
label="Bairro"
validate={ required }
validate={required}
/>
<TextInput
source="city"
label="Cidade"
validate={ required }
validate={required}
/>
<SelectInput
source="district"
label="Estado"
choices={federalStates}
validate={required}
/>
</SimpleForm>
</Create>
Expand Down
25 changes: 17 additions & 8 deletions src/Categories/Owners/OwnerEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const federalStates = [
{ id: 'TO', name: 'Tocantins (TO)' },
];

const required = value => (value ? undefined : 'Campo obrigatório');

export class OwnerEdit extends Component {
constructor(props) {
super(props);
Expand All @@ -50,42 +52,41 @@ export class OwnerEdit extends Component {
contentType: 'application/json',
statusCode: {
200: (data) => {
// console.log(data);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'publicPlace',
`${data.tipoDeLogradouro} ${data.logradouro}`),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'neighborhood',
data.bairro,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'record-form',
'city',
data.cidade,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'district',
data.estado,
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'addressNumber',
'',
),
);
this.form.dispatchProps.dispatch(
this.form.store.dispatch(
change(
'record-form',
'complement',
Expand Down Expand Up @@ -114,14 +115,17 @@ export class OwnerEdit extends Component {
<TextInput
source="ownerName"
label="Primeiro Nome"
validate={required}
/>
<TextInput
source="ownerLastName"
label="Sobrenome"
validate={required}
/>
<TextInput
source="phoneNumber"
label="Telefone"
validate={required}
/>
<TextInput
source="zipCode"
Expand All @@ -131,10 +135,12 @@ export class OwnerEdit extends Component {
<TextInput
source="publicPlace"
label="Endereço"
validate={required}
/>
<TextInput
source="addressNumber"
label="Número"
validate={required}
/>
<TextInput
source="complement"
Expand All @@ -143,15 +149,18 @@ export class OwnerEdit extends Component {
<TextInput
source="neighborhood"
label="Bairro"
validate={required}
/>
<TextInput
source="city"
label="Cidade"
validate={required}
/>
<SelectInput
source="district"
label="Estado"
choices={federalStates}
validate={required}
/>
</SimpleForm>
</Edit>
Expand Down
2 changes: 1 addition & 1 deletion src/Categories/Owners/OwnerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const OwnerList = props => (
small={
<SimpleList
primaryText={owner => `Nome: ${owner.ownerName}`}
secondaryText={owner => `Sobrenome: ${owner.lastName}`}
secondaryText={owner => `Sobrenome: ${owner.ownerLastName}`}
tertiaryText={owner => `Telefone: ${owner.phoneNumber}`}
/>
}
Expand Down

0 comments on commit 7cd6cb7

Please sign in to comment.