feat: enhance IntestazioneMaker to handle missing comuni gracefully and improve name formatting
This commit is contained in:
parent
4ac90699b6
commit
37b5c01846
1 changed files with 7 additions and 7 deletions
|
|
@ -212,17 +212,17 @@ const IntestazioneMaker = () => {
|
||||||
const comune_residenza = comuni.find(
|
const comune_residenza = comuni.find(
|
||||||
(c) => c.catasto === data.comune_residenza,
|
(c) => c.catasto === data.comune_residenza,
|
||||||
);
|
);
|
||||||
if (!comune_nascita || !comune_residenza) {
|
|
||||||
toast.error("Errore comune non trovato");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format names
|
// Format names
|
||||||
const cognome = data.cognome.toUpperCase();
|
const cognome = data.cognome.toUpperCase();
|
||||||
const nome = data.nome.toUpperCase();
|
const nome = data.nome.toUpperCase();
|
||||||
const viaResidenza = titleCase(data.via_residenza);
|
const viaResidenza = titleCase(data.via_residenza);
|
||||||
const comuneNascita = titleCase(comune_nascita.nome);
|
const comuneNascita = comune_nascita
|
||||||
const comuneResidenza = titleCase(comune_residenza.nome);
|
? titleCase(comune_nascita.nome)
|
||||||
|
: data.luogo_nascita;
|
||||||
|
const comuneResidenza = comune_residenza
|
||||||
|
? titleCase(comune_residenza.nome)
|
||||||
|
: data.comune_residenza;
|
||||||
|
|
||||||
// Determine article
|
// Determine article
|
||||||
const isMale = data.sesso === "M";
|
const isMale = data.sesso === "M";
|
||||||
|
|
@ -236,7 +236,7 @@ const IntestazioneMaker = () => {
|
||||||
const frase = [
|
const frase = [
|
||||||
`${articolo} ${cognome} ${nome}`,
|
`${articolo} ${cognome} ${nome}`,
|
||||||
`${natoNata} il ${format(data.data_nascita, "dd/MM/yyyy")}`,
|
`${natoNata} il ${format(data.data_nascita, "dd/MM/yyyy")}`,
|
||||||
`${preposizione} ${comuneNascita} (${comune_nascita.sigla}),`,
|
`${preposizione} ${comuneNascita}${comune_nascita ? ` (${comune_nascita.sigla})` : ""},`,
|
||||||
`residente in ${viaResidenza}, ${data.civico_residenza}`,
|
`residente in ${viaResidenza}, ${data.civico_residenza}`,
|
||||||
`a ${comuneResidenza} (${data.provincia_residenza})`,
|
`a ${comuneResidenza} (${data.provincia_residenza})`,
|
||||||
`CAP ${data.cap_residenza},`,
|
`CAP ${data.cap_residenza},`,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue