Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/CitizenSummaryViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
<SummarySection
v-if="internalCitizen"
title="Dados pessoais"
:items="internalCitizen.getPersonalInfo(hiddenFields)"
:items="internalCitizen.getPersonalInfo(hiddenFields, requiredFields)"
/>
<SummarySection
v-if="internalCitizen"
title="Informações de contato"
:items="internalCitizen?.getContactInfo(hiddenFields)"
:items="internalCitizen?.getContactInfo(hiddenFields, requiredFields)"
/>
</CdsFlexbox>
</CdsBox>
Expand Down Expand Up @@ -142,6 +142,15 @@ const emits = defineEmits(['create', 'edit', 'close']);
const internalCitizen = ref<CitizenModel>();
const emptyStateImage = emptyState;
const hasMissingFields = ref(false);
const requiredFields = [
'cpf',
'cns',
'address',
'gender',
'race',
'mother_name',
'birth_date',
];

onMounted(() => {
checkMissingRequiredFields(props.citizen);
Expand Down
24 changes: 17 additions & 7 deletions src/components/InternalComponents/SummarySection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@
:key="item.label"
:col-span="item.fill ? 3 : 1"
>
<CdsText
as="caption"
color="n-600"
font-weight="semibold"
>
{{ item.label }}
</CdsText>
<CdsFlexbox gap="1">
<CdsText
as="caption"
color="n-600"
font-weight="semibold"
>
{{ item.label }}
</CdsText>
<CdsIcon
v-if="item.incomplete"
height="16"
width="16"
name="warning-outline"
color="#EDA831"
/>
</CdsFlexbox>
<CdsSpacer margin-top="1">
<CdsText
as="body-2"
Expand All @@ -47,6 +56,7 @@ defineProps<{
label: string,
value: Nullable<string>,
fill?: boolean,
incomplete?: boolean,
}>,
}>()
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`CitizenSummaryViewer > is rendered correctly 1`] = `
<cds-icon-button-stub data-v-07590091="" size="sm" icon="x-outline" disabled="false" tooltiptext="Fechar" feedbackonclick="false" feedbackicon="check-outline" variant="white" data-testid="close-button"></cds-icon-button-stub>
</div>
</div>
<summary-section-stub data-v-07590091="" title="Dados pessoais" items="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"></summary-section-stub>
<summary-section-stub data-v-07590091="" title="Dados pessoais" items="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"></summary-section-stub>
<summary-section-stub data-v-07590091="" title="Informações de contato" items="[object Object],[object Object],[object Object],[object Object]"></summary-section-stub>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/models/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ export class Address {
${resolveFancyField(this.city?.value)} - ${resolveFancyField(this.uf?.shortName)}`;
}

get isIncomplete(): boolean {
return (
!this.street ||
!this.number ||
!this.neighborhood ||
!this.city ||
!this.uf
);
}

get asFormData() {
return {
street: this.street,
Expand Down
33 changes: 17 additions & 16 deletions src/models/Citizen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,33 @@ describe('Citizen model', () => {
const fancyGender = genderFromType(citizenFixture.gender as string).name;
const fancyRace = raceByValue(citizenFixture.race).name;

const fieldsToHide = ['race'];
const fieldsToHide = ['race', 'mother_name'];

expect(citizen.getPersonalInfo()).toEqual([
{ label: 'CPF', value: maskCpf(citizenFixture.cpf), field: 'cpf' },
{ label: 'CNS', value: maskCns(citizenFixture.cns), field: 'cns' },
{ label: 'RG', value: 'Não informado', field: 'identification_document' },
{ label: 'Data de nascimento', value: DateTime.fromISO(citizenFixture.birth_date).toFormat('dd/MM/yyyy'), field: 'birth_date' },
{ label: 'Sexo', value: fancyGender, field: 'gender' },
{ label: 'Raça/Cor', value: fancyRace, field: 'race' },
{ label: 'CPF', value: maskCpf(citizenFixture.cpf), field: 'cpf', incomplete: false },
{ label: 'CNS', value: maskCns(citizenFixture.cns), field: 'cns', incomplete: false },
{ label: 'RG', value: 'Não informado', field: 'identification_document', incomplete: false },
{ label: 'Data de nascimento', value: DateTime.fromISO(citizenFixture.birth_date).toFormat('dd/MM/yyyy'), field: 'birth_date', incomplete: false },
{ label: 'Sexo', value: fancyGender, field: 'gender', incomplete: false },
{ label: 'Raça/Cor', value: fancyRace, field: 'race', incomplete: false },
{ label: 'Nome da mãe', value: citizenFixture.mother_name, field: 'mother_name', fill: true, incomplete: false },
]);

expect(citizen.getPersonalInfo(fieldsToHide)).toEqual([
{ label: 'CPF', value: maskCpf(citizenFixture.cpf), field: 'cpf' },
{ label: 'CNS', value: maskCns(citizenFixture.cns), field: 'cns' },
{ label: 'RG', value: 'Não informado', field: 'identification_document' },
{ label: 'Data de nascimento', value: DateTime.fromISO(citizenFixture.birth_date).toFormat('dd/MM/yyyy'), field: 'birth_date' },
{ label: 'Sexo', value: fancyGender, field: 'gender' },
{ label: 'CPF', value: maskCpf(citizenFixture.cpf), field: 'cpf', incomplete: false },
{ label: 'CNS', value: maskCns(citizenFixture.cns), field: 'cns', incomplete: false },
{ label: 'RG', value: 'Não informado', field: 'identification_document', incomplete: false },
{ label: 'Data de nascimento', value: DateTime.fromISO(citizenFixture.birth_date).toFormat('dd/MM/yyyy'), field: 'birth_date', incomplete: false },
{ label: 'Sexo', value: fancyGender, field: 'gender', incomplete: false },
]);
});

test('contactInfo is resolved correctly', () => {
expect(citizen.getContactInfo()).toEqual([
{ label: 'Telefone', value: 'Não informado', field: 'phone' },
{ label: 'Celular', value: maskPhone(citizenFixture.cellphone), field: 'cellphone' },
{ label: 'E-mail', value: 'Não informado', field: 'email' },
{ label: 'Endereço', value: citizen.fancyAddress, fill: true, field: 'address' },
{ label: 'Telefone', value: 'Não informado', field: 'phone', incomplete: false },
{ label: 'Celular', value: maskPhone(citizenFixture.cellphone), field: 'cellphone', incomplete: false },
{ label: 'E-mail', value: 'Não informado', field: 'email', incomplete: false },
{ label: 'Endereço', value: citizen.fancyAddress, fill: true, field: 'address', incomplete: false },
]);
});

Expand Down
84 changes: 70 additions & 14 deletions src/models/Citizen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,83 @@ export class Citizen {
return this._gender;
}

getPersonalInfo(fieldsToHide?: string[]): { label: string; value: string; fill?: boolean, field?: string }[] {
getPersonalInfo(fieldsToHide?: string[], requiredFields: string[] = []): { label: string; value: string; fill?: boolean, field?: string }[] {
const fields = [
{ label: 'CPF', value: this.cpf ? maskCpf(this.cpf) : 'Não informado', field: 'cpf' },
{ label: 'CNS', value: this.cns ? maskCns(this.cns) : 'Não informado', field: 'cns' },
{ label: 'RG', value: this.identification_document || 'Não informado', field: 'identification_document' },
{ label: 'Data de nascimento', value: this.birth_date
? DateTime.fromISO(this.birth_date).toFormat('dd/MM/yyyy')
: 'Não informada', field: 'birth_date' },
{ label: 'Sexo', value: this._gender ? this._gender.name : 'Não informado', field: 'gender' },
{ label: 'Raça/Cor', value: this.race?.name || 'Não informado', field: 'race' },
{
label: 'CPF',
value: this.cpf ? maskCpf(this.cpf) : 'Não informado',
field: 'cpf',
incomplete: !this.cpf && requiredFields?.includes('cpf')
},
{
label: 'CNS',
value: this.cns ? maskCns(this.cns) : 'Não informado',
field: 'cns',
incomplete: !this.cns && requiredFields?.includes('cns')
},
{
label: 'RG',
value: this.identification_document || 'Não informado',
field: 'identification_document',
incomplete: !this.identification_document && requiredFields?.includes('identification_document')
},
{
label: 'Data de nascimento',
value: this.birth_date ? DateTime.fromISO(this.birth_date).toFormat('dd/MM/yyyy') : 'Não informada',
field: 'birth_date',
incomplete: !this.birth_date && requiredFields?.includes('birth_date')
},
{
label: 'Sexo',
value: this._gender ? this._gender.name : 'Não informado',
field: 'gender',
incomplete: !this._gender && requiredFields?.includes('gender')
},
{
label: 'Raça/Cor',
value: this.race?.name || 'Não informado',
field: 'race',
incomplete: !this.race && requiredFields?.includes('race')
},
{
label: 'Nome da mãe',
value: this.mother_name || 'Não informado',
fill: true,
field: 'mother_name',
incomplete: !this.mother_name && requiredFields?.includes('mother_name')
},
];

return fields.filter(({ field }) => !fieldsToHide?.includes(field));
}

getContactInfo(fieldsToHide?: string[]): { label: string; value: Nullable<string>; fill?: boolean, field?: string }[] {
getContactInfo(fieldsToHide?: string[], requiredFields: string[] = []): { label: string; value: Nullable<string>; fill?: boolean, field?: string }[] {
const fields = [
{ label: 'Telefone', value: this.phone ? maskPhone(this.phone) : 'Não informado', field: 'phone' },
{ label: 'Celular', value: this.cellphone ? maskPhone(this.cellphone) : 'Não informado', field: 'cellphone' },
{ label: 'E-mail', value: this.email || 'Não informado', field: 'email' },
{ label: 'Endereço', value: this.fancyAddress, fill: true, field: 'address' },
{
label: 'Telefone',
value: this.phone ? maskPhone(this.phone) : 'Não informado',
field: 'phone',
incomplete: !this.phone && requiredFields?.includes('phone')
},
{
label: 'Celular',
value: this.cellphone ? maskPhone(this.cellphone) : 'Não informado',
field: 'cellphone',
incomplete: !this.cellphone && requiredFields?.includes('cellphone')
},
{
label: 'E-mail',
value: this.email || 'Não informado',
field: 'email',
incomplete: !this.email && requiredFields?.includes('email')
},
{
label: 'Endereço',
value: this.fancyAddress,
fill: true,
field: 'address',
incomplete: this.address?.isIncomplete && requiredFields?.includes('address')
},
];

return fields.filter(({ field }) => !fieldsToHide?.includes(field));
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface Address {
shortName: string;
id: string;
};
isIncomplete: boolean;
asFormData?: any;
asRequestPayload?: any;
fancyAddress: string;
Expand Down