From 8130e2f8a6baac61a311eb6ed630de0ff56103c5 Mon Sep 17 00:00:00 2001 From: Azecko Date: Wed, 13 Nov 2024 10:29:51 +0100 Subject: [PATCH] [fix] TypeScript warning & errors TypeScript was going crazy because... TypeScript. I made an interface for the `report` localStorage, fixed some types problem... --- app/responsable/page.tsx | 13 ++++--- interfaces/reportStorageInterface.tsx | 54 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 interfaces/reportStorageInterface.tsx diff --git a/app/responsable/page.tsx b/app/responsable/page.tsx index ad76ec6..b4658ae 100644 --- a/app/responsable/page.tsx +++ b/app/responsable/page.tsx @@ -1,10 +1,11 @@ "use client"; import React from "react"; import EtatDeVaudSignature from "../components/EtatDeVaudSignature"; +import { reportStorageInterface } from "@/interfaces/reportStorageInterface"; export default function Page() { const inputFile = React.useRef(null); - const [rapportStorage, setRapportStorage] = React.useState({}); + const [rapportStorage, setRapportStorage] = React.useState({}) React.useEffect(() => { const storedData = localStorage.getItem('rapport-de-stage'); @@ -13,7 +14,7 @@ export default function Page() { } }, []); - const handleFileUpload = e => { + const handleFileUpload = (e: React.ChangeEvent) => { const confirm = window.confirm('Voulez-vous vraiment importer les données de ce fichier ?') if(confirm) { const { files } = e.target; @@ -29,7 +30,7 @@ export default function Page() { const reader = new FileReader(); reader.onload = (event) => { try { - const fileContent = event.target.result; + const fileContent = event.target?.result as string; const jsonData = JSON.parse(fileContent); localStorage.setItem('rapport-de-stage', JSON.stringify(jsonData)) location.reload() @@ -46,13 +47,13 @@ export default function Page() { } }; - function updateStorageOnChange(element, elementValue) { - rapportStorage[element] = elementValue + function updateStorageOnChange(element:string, elementValue:string) { + rapportStorage[element as keyof reportStorageInterface] = elementValue localStorage.setItem('rapport-de-stage', JSON.stringify(rapportStorage)) } function onButtonClick() { - inputFile.current.click(); + inputFile.current?.click(); }; function download(filename:any, text:any) { diff --git a/interfaces/reportStorageInterface.tsx b/interfaces/reportStorageInterface.tsx new file mode 100644 index 0000000..954258e --- /dev/null +++ b/interfaces/reportStorageInterface.tsx @@ -0,0 +1,54 @@ +export interface reportStorageInterface { + internFirstName?: string, + internLastName?: string, + entrepriseName?: string, + responsibleMail?: string, + responsibleName?: string, + responsiblePostalAddress?: string, + responsiblePostalCode?: string, + responsibleLocality?: string, + responsiblePhone?: string, + internClass?: string, + internEstablishment?: string, + internPostalCode?: string, + internLocality?: string, + internPhone?: string, + internAddress?: string, + job?: string, + beginDate?: string, + endDate?: string, + firstImpression?: string, + ponctuality?: string, + selfConfidence?: string, + dynamism?: string, + concentrationSpan?: string, + curiosity?: string, + commitment?: string, + interestLearning?: string, + attitudeRemarks?: string, + skillful?: string, + fast?: string, + careful?: string, + methodical?: string, + persevering?: string, + attentive?: string, + followInstructions?: string, + tasksExecRemarks?: string, + comfortable?: string, + helpful?: string, + polite?: string, + smiling?: string, + confidentToAsk?: string, + showInterest?: string, + expressClairly?: string, + contactRemarks?: string, + apprenticeshipJob?: string, + opinionRemarks?: string, + adviceProject?: string, + advicesRemarks?: string, + considerCandidate?: string, + considerCandidatesRemarks?: string, + bilanStage?: string, + fillUpDate?: string, + signature?: string +} \ No newline at end of file