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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"luxon": "^3.7.2"
},
"peerDependencies": {
"@sysvale/cuida": "^3.152.0",
"@sysvale/cuida": "^3.154.7",
"@sysvale/foundry": "^1.7.0",
"vee-validate": "^4.15.1",
"vue": "^3.5.13"
Expand All @@ -57,7 +57,7 @@
"@semantic-release/github": "^12.0.0",
"@semantic-release/npm": "^13.1.1",
"@semantic-release/release-notes-generator": "^14.1.0",
"@sysvale/cuida": "^3.152.0",
"@sysvale/cuida": "^3.154.7",
"@sysvale/foundry": "^1.7.0",
"@tsconfig/node22": "^22.0.1",
"@types/jsdom": "^21.1.7",
Expand Down
41 changes: 36 additions & 5 deletions src/components/InternalComponents/CitizenForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@
</CdsSpacer>
</template>
</CdsTextInput>
<CdsDateInput
v-else-if="formField.name === 'birth_date'"
:model-value="field.value"
v-bind="{
...formField,
}"
mode="typing"
:data-testid="`test-${formField.name}`"
:disabled="resolveDisabledState(formField.name) || isLoadingCities"
fluid
:state="resolveInputState(meta)"
:error-message="errors[0]"
@update:model-value="(event: any) => handleFieldInput(formField.name, event)"
/>
<component
:is="formField.component"
v-else
Expand Down Expand Up @@ -271,6 +285,12 @@ function handleUfSelect(ibgeCode: string | number) {
.then((response: { data: Array<{ nome: string }> }) => {
cities.value = response.data.map((city) => ({ id: city.nome, value: city.nome }));

const selectedCity = formRef.value?.values.city;

if (!selectedCity || !cities.value.find(({ id }) => id === selectedCity?.value)) {
clearValidationRefs([validationCityRef]);
}

if (!props.allowedCities) return;

cities.value = cities.value.filter(({ id }) => props.allowedCities?.includes(id));
Expand Down Expand Up @@ -304,11 +324,14 @@ async function handleCitySelect(cityName: string) {
.then((response: { data: Array<{ id: string, name: string }> }) => {
neighborhoods.value = response.data.map((neighborhood) => ({ id: neighborhood.name, value: neighborhood.name }));

if (!internalCitizen.value.neighborhood || !neighborhoods.value.find(({ id }) => id === internalCitizen.value.neighborhood?.id)) {
const selectedNeighborhood = formRef.value?.values.neighborhood;

if (!selectedNeighborhood || !neighborhoods.value.find(({ id }) => id === selectedNeighborhood?.value)) {
clearValidationRefs([validationNeighborhoodRef]);
return;
}

handleNeighborhoodSelect(internalCitizen.value.neighborhood);
handleNeighborhoodSelect(selectedNeighborhood);
}).catch(() => {
// @ts-ignore
useToast().fire({
Expand Down Expand Up @@ -338,6 +361,14 @@ async function handleNeighborhoodSelect(neighborhood: { id: string, value: strin
getStreetsFromNeighborhoods(neighborhoodCityUfObject)
.then((response: { data: Array<{ name: string }> }) => {
streets.value = response.data.map((street) => ({ id: street.name, value: street.name }));

const selectedStreet = formRef.value?.values.street;

if (selectedStreet && streets.value.find(({ id }) => id === selectedStreet?.value)) {
return;
}

clearValidationRefs([validationStreetRef]);
}).catch(() => {
// @ts-ignore
useToast().fire({
Expand All @@ -362,17 +393,17 @@ function handleFieldInput(fieldName: string, fieldValue: any) {
handleGenderChange(fieldValue.value);
break;
case 'uf':
clearValidationRefs([validationCityRef, validationNeighborhoodRef, validationStreetRef]);
handleUfSelect(fieldValue.ibgeCode);
break;
case 'city':
clearValidationRefs([validationNeighborhoodRef, validationStreetRef]);
handleCitySelect(fieldValue.value);
break;
case 'neighborhood':
clearValidationRefs([validationStreetRef]);
handleNeighborhoodSelect(fieldValue);
break;
case 'birth_date':
formRef.value?.setFieldValue('birth_date', fieldValue);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`CitizenForm > is rendered correctly 1`] = `
<cds-text-input-stub data-v-1916aed6="" label="CPF" disabled="false" state="default" inputtype="text" required="true" placeholder="000.000.000-00" errormessage="Valor inválido" fluid="true" mask="###.###.###-##" tooltipicon="info-outline" supportingtext="" lazy="false" mobile="false" floatinglabel="false" disableautocomplete="false" name="cpf" rules="cpf|required_without:@cns" colspan="6" component="CdsTextInput" data-testid="test-cpf"></cds-text-input-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-date-input-stub data-v-1916aed6="" label="Data de nascimento" variant="green" state="default" mode="picking" range="false" required="true" disabled="false" fluid="true" mobile="false" floatinglabel="false" showtodaydot="false" highlighttoday="false" placeholder="Selecione uma data" errormessage="Valor inválido" mindate="" maxdate="2025-12-04" tooltipicon="info-outline" supportingtext="" name="birth_date" rules="required" colspan="6" component="CdsDateInput" data-testid="test-birth_date" class="field__container"></cds-date-input-stub>
<cds-date-input-stub data-v-1916aed6="" label="Data de nascimento" variant="green" state="default" mode="typing" range="false" required="true" disabled="false" fluid="true" mobile="false" floatinglabel="false" showtodaydot="false" highlighttoday="false" placeholder="Selecione uma data" errormessage="Valor inválido" mindate="" maxdate="2025-12-04" tooltipicon="info-outline" supportingtext="" name="birth_date" rules="required|maxDate:2025-12-04" colspan="6" component="CdsDateInput" data-testid="test-birth_date"></cds-date-input-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-text-input-stub data-v-1916aed6="" label="CPF do responsável" disabled="false" state="default" inputtype="text" required="false" placeholder="000.000.000-00" errormessage="Valor inválido" fluid="true" mask="###.###.###-##" tooltipicon="info-outline" supportingtext="" lazy="false" mobile="false" floatinglabel="false" disableautocomplete="false" name="cpf_responsible" rules="cpf" colspan="6" component="CdsTextInput" data-testid="test-cpf_responsible" class="field__container"></cds-text-input-stub>
Expand All @@ -26,10 +26,10 @@ exports[`CitizenForm > is rendered correctly 1`] = `
<cds-text-input-stub data-v-1916aed6="" label="Orgão emissor" disabled="false" state="default" inputtype="text" required="false" placeholder="Ex.: SSP" errormessage="Valor inválido" fluid="true" tooltipicon="info-outline" supportingtext="" lazy="false" mobile="false" floatinglabel="false" disableautocomplete="false" name="issuing_agency" rules="" colspan="6" component="CdsTextInput" data-testid="test-issuing_agency" class="field__container"></cds-text-input-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="Raça/Cor" placeholder="Selecione..." options="[object Object],[object Object],[object Object],[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="name" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" name="race" rules="required" colspan="4" component="CdsSelect" data-testid="test-race" class="field__container"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="Raça/Cor" placeholder="Selecione..." options="[object Object],[object Object],[object Object],[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="name" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" ghost="false" name="race" rules="required" colspan="4" component="CdsSelect" data-testid="test-race" class="field__container"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="Sexo" placeholder="Selecione..." options="[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="name" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" name="gender" rules="required" colspan="4" component="CdsSelect" data-testid="test-gender" class="field__container"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="Sexo" placeholder="Selecione..." options="[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="name" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" ghost="false" name="gender" rules="required" colspan="4" component="CdsSelect" data-testid="test-gender" class="field__container"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item pregnant__container">
<cds-checkbox-stub data-v-1916aed6="" modelvalue="false" label="Está gestante" variant="green" indeterminate="false" prominent="false" disabled="true" name="pregnant" required="false" rules="" colspan="4" component="CdsCheckbox" data-testid="test-pregnant" state="default" class="field__container" fluid=""></cds-checkbox-stub>
Expand All @@ -47,16 +47,16 @@ exports[`CitizenForm > is rendered correctly 1`] = `
<cds-text-input-stub data-v-1916aed6="" label="E-mail" disabled="false" state="default" inputtype="text" required="false" placeholder="seu.email@exemplo.com" errormessage="Valor inválido" fluid="true" tooltipicon="info-outline" supportingtext="" lazy="false" mobile="false" floatinglabel="false" disableautocomplete="false" name="email" rules="" colspan="6" component="CdsTextInput" data-testid="test-email" class="field__container"></cds-text-input-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="UF" placeholder="Selecione..." options="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="shortName" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" name="uf" rules="required" colspan="3" component="CdsSelect" data-testid="test-uf"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="UF" placeholder="Selecione..." options="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" state="default" required="true" errormessage="Valor inválido" searchable="false" deepsearch="false" width="" fluid="true" disabled="false" tooltipicon="info-outline" optionsfield="shortName" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" ghost="false" name="uf" rules="required" colspan="3" component="CdsSelect" data-testid="test-uf"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="Cidade" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" name="city" rules="required" colspan="3" component="CdsSelect" data-testid="test-city"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="Cidade" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="false" ghost="false" name="city" rules="required" colspan="3" component="CdsSelect" data-testid="test-city"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="Bairro" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="true" name="neighborhood" rules="required" colspan="6" component="CdsSelect" data-testid="test-neighborhood"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="Bairro" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="true" ghost="false" name="neighborhood" rules="required" colspan="6" component="CdsSelect" data-testid="test-neighborhood"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-select-stub data-v-1916aed6="" label="Rua" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="true" name="street" rules="required" colspan="4" component="CdsSelect" data-testid="test-street"></cds-select-stub>
<cds-select-stub data-v-1916aed6="" label="Rua" placeholder="Selecione..." options="" state="default" required="true" errormessage="Valor inválido" searchable="true" deepsearch="true" width="" fluid="true" disabled="true" tooltipicon="info-outline" optionsfield="value" returnvalue="false" supportingtext="" mobile="false" floatinglabel="false" addable="true" ghost="false" name="street" rules="required" colspan="4" component="CdsSelect" data-testid="test-street"></cds-select-stub>
</div>
<div data-v-051eccea="" data-v-1916aed6="" class="grid-item">
<cds-text-input-stub data-v-1916aed6="" label="Número" disabled="false" state="default" inputtype="text" required="true" placeholder="00" errormessage="Valor inválido" fluid="true" tooltipicon="info-outline" supportingtext="" lazy="false" mobile="false" floatinglabel="false" disableautocomplete="false" name="number" rules="required" colspan="3" component="CdsTextInput" data-testid="test-number" class="field__container"></cds-text-input-stub>
Expand Down
2 changes: 1 addition & 1 deletion src/constants/citizenFormFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default (hiddenFields: string[]): CitizenFormField[] => {
name: 'birth_date',
label: 'Data de nascimento',
required: true,
rules: 'required',
rules: `required|maxDate:${new Date().toISOString().split('T')[0]}`,
colSpan: 6,
component: 'CdsDateInput',
maxDate: new Date().toISOString().split('T')[0],
Expand Down
18 changes: 18 additions & 0 deletions src/utils/rules/citizenFormRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { localize, setLocale } from '@vee-validate/i18n';
// @ts-ignore
import { cpfValidator, cnsValidator } from '@sysvale/foundry';
import requiredWithout from './requiredWithout';
import maxDate from './maxDate';
import { dmyFormatter } from '../dmyFormatter';

setLocale('pt-BR');

Expand All @@ -30,6 +32,22 @@ defineRule('required_without', (value: string, target: string[]) => {
return true;
});

defineRule('maxDate', (value: string, target: string[]) => {
const res = maxDate(value, target);

if (!res) {
const formattedMaxDate = dmyFormatter(target?.[0]?.trim?.() ?? '');

if (formattedMaxDate !== '--') {
return `A data deve ser menor ou igual a ${formattedMaxDate}`;
}

return 'A data deve ser menor ou igual à data máxima permitida';
}

return true;
});

defineRule('cpf', (value: string) => {
const res = cpfValidator(value ?? '');

Expand Down
37 changes: 37 additions & 0 deletions src/utils/rules/maxDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const isValidYmdDate = (date: string) => {
const match = date.match(/^(\d{4})-(\d{2})-(\d{2})$/);

if (!match) {
return false;
}

const [, yearRaw, monthRaw, dayRaw] = match;
const year = Number(yearRaw);
const month = Number(monthRaw);
const day = Number(dayRaw);
const parsedDate = new Date(Date.UTC(year, month - 1, day));

return (
parsedDate.getUTCFullYear() === year
&& parsedDate.getUTCMonth() === month - 1
&& parsedDate.getUTCDate() === day
);
};

const maxDate = (value: string, target: string[]) => {
const normalizedValue = value?.trim?.() ?? '';

if (!normalizedValue) {
return true;
}

const max = target?.[0]?.trim?.() ?? '';

if (!max || !isValidYmdDate(normalizedValue) || !isValidYmdDate(max)) {
return false;
}

return normalizedValue <= max;
};

export default maxDate;