Skip to content

Commit

Permalink
[fix] TypeScript warning & errors
Browse files Browse the repository at this point in the history
TypeScript was going crazy because... TypeScript.
I made an interface for the `report` localStorage, fixed some types problem...
  • Loading branch information
Azecko committed Nov 13, 2024
1 parent 96be676 commit 8130e2f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/responsable/page.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLInputElement | null>(null);
const [rapportStorage, setRapportStorage] = React.useState({});
const [rapportStorage, setRapportStorage] = React.useState<reportStorageInterface>({})

React.useEffect(() => {
const storedData = localStorage.getItem('rapport-de-stage');
Expand All @@ -13,7 +14,7 @@ export default function Page() {
}
}, []);

const handleFileUpload = e => {
const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
const confirm = window.confirm('Voulez-vous vraiment importer les données de ce fichier ?')
if(confirm) {
const { files } = e.target;
Expand All @@ -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()
Expand All @@ -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) {
Expand Down
54 changes: 54 additions & 0 deletions interfaces/reportStorageInterface.tsx
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 8130e2f

Please sign in to comment.