From 6d33112f903d597e86682ddb2934571a3071c78a Mon Sep 17 00:00:00 2001 From: gorbenco03 Date: Thu, 13 Jun 2024 08:06:30 +0200 Subject: [PATCH] fix issues' --- sections/details/details.tsx | 82 ++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/sections/details/details.tsx b/sections/details/details.tsx index 5323989..edb0041 100644 --- a/sections/details/details.tsx +++ b/sections/details/details.tsx @@ -2,9 +2,35 @@ import React, { useState, useEffect } from 'react'; import { v4 as uuidv4 } from 'uuid'; import InsurancePopOver from '../../components/popOver'; +type FormDataType = { + TipAsigurare: string; + Nume: string; + Prenume: string; + CNP: string; + DataNasterii: string; + PermisDeConducere: string; + Email: string; + NrDeTelefon: string; + Adresa: string; + MarcaMasinii: string; + Modelul: string; + CategoriaMasinii: string; + NumarulWIN: string; + AnProductie: string; + CapacitateCilindrica: string; + CategorieBonus: string; + NrInmatriculare: string; + NrCertificatInmatriculare: string; + NormaDePoluare: string; + TipCombustibil: string; + PerioadaDeAsigurare: string; + StatusAsigurare: string; + PretAsigurare?: number; +}; + const Details: React.FC = () => { const [open, setOpen] = useState(false); - const [formData, setFormData] = useState>({ + const [formData, setFormData] = useState({ TipAsigurare: '', Nume: '', Prenume: '', @@ -74,7 +100,7 @@ const Details: React.FC = () => { 'Perioada De Asigurare': 'PerioadaDeAsigurare', }; - const options: { [key: string]: string[] | { [key: string]: string[] } } = { + const options: Record> = { 'Marca Masinii': [ 'BMW', 'Mercedes', @@ -157,12 +183,14 @@ const Details: React.FC = () => { // Generare număr unic de serie folosind UUID const generateUniqueNumber = () => { - const prefix = { + const prefix: Record = { 'RCA': 'RCA', 'CASCO': 'CAS', 'CARTE VERDE': 'CV', - }[formData.TipAsigurare]; - return `${prefix}-${uuidv4()}`; + }; + + const insuranceType = formData.TipAsigurare as keyof typeof prefix; + return `${prefix[insuranceType]}-${uuidv4()}`; }; const requestData = { @@ -212,14 +240,14 @@ const Details: React.FC = () => { // Verifică dacă toate câmpurile sunt completate driverFields.forEach((field) => { const formDataFieldName = fieldMapping[field] || field; - if (!formData[formDataFieldName]) { + if (!(formData as any)[formDataFieldName]) { missingFields.push(field); } }); carFields.forEach((field) => { const formDataFieldName = fieldMapping[field] || field; - if (!formData[formDataFieldName]) { + if (!(formData as any)[formDataFieldName]) { missingFields.push(field); } }); @@ -249,7 +277,7 @@ const Details: React.FC = () => { }; // Extrage și validează categoria bonus ca număr - const bonusCategory = parseInt(formData['Categorie Bonus'], 10); + const bonusCategory = parseInt(formData['CategorieBonus'], 10); const bonusCategoryCoefficient = bonusCategory >= -8 && bonusCategory <= 8 ? 1.0 @@ -422,7 +450,7 @@ const Details: React.FC = () => { {field}
- {options[field] ? ( + {Array.isArray(options[field]) ? ( ) : ( - + formData['MarcaMasinii'] && + (options['Modelul'] as Record)[ + formData['MarcaMasinii'] + ]?.map((option) => ( + + )) )}