Skip to content

Commit 1e89e85

Browse files
committed
upgraded eslint and fixed errors
1 parent e76e6f5 commit 1e89e85

File tree

7 files changed

+45
-107
lines changed

7 files changed

+45
-107
lines changed

client/eslint.config.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
import js from '@eslint/js';
1+
import { globalIgnores } from 'eslint/config';
22
import globals from 'globals';
3+
import js from '@eslint/js';
34
import reactHooks from 'eslint-plugin-react-hooks';
45
import reactRefresh from 'eslint-plugin-react-refresh';
56
import tseslint from 'typescript-eslint';
6-
import { globalIgnores } from 'eslint/config';
77

88
export default tseslint.config([
99
globalIgnores(['dist', 'node_modules']),
10+
js.configs.recommended,
11+
...tseslint.configs.recommended,
1012
{
1113
files: ['**/*.{ts,tsx}'],
12-
extends: [
13-
js.configs.recommended,
14-
tseslint.configs.recommended,
15-
reactHooks.configs['recommended-latest'],
16-
reactRefresh.configs.vite,
17-
],
14+
plugins: {
15+
'react-hooks': reactHooks,
16+
'react-refresh': reactRefresh,
17+
},
1818
languageOptions: {
1919
ecmaVersion: 2020,
2020
globals: {
2121
...globals.browser,
2222
},
23+
parserOptions: {
24+
ecmaFeatures: {
25+
jsx: true,
26+
},
27+
},
2328
},
2429
rules: {
30+
...reactHooks.configs.recommended.rules,
2531
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
2632
},
2733
},

client/src/features/trainee-profile/education/strikes/StrikeDetailsModal.tsx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
Typography,
1616
} from '@mui/material';
1717
import { Strike, StrikeReason } from '../../../../data/types/Trainee';
18-
import { useEffect, useState } from 'react';
1918

2019
import { LoadingButton } from '@mui/lab';
2120
import { formatDate } from '../../utils/dateHelper';
21+
import { useState } from 'react';
2222

2323
interface StrikeDetailsModalProps {
2424
isOpen: boolean;
@@ -40,44 +40,19 @@ export const StrikeDetailsModal = ({
4040
strikeToEdit,
4141
}: StrikeDetailsModalProps) => {
4242
const [strikeFields, setStrikeFields] = useState<Strike>({
43-
id: '',
44-
date: new Date(),
45-
reporterID: '',
46-
comments: '',
47-
reason: null,
43+
id: strikeToEdit?.id || '',
44+
date: strikeToEdit?.date || new Date(),
45+
reporterID: strikeToEdit?.reporterID || '',
46+
comments: strikeToEdit?.comments || '',
47+
reason: strikeToEdit?.reason || null,
4848
} as Strike);
4949

5050
const [commentsRequiredError, setCommentsRequiredError] = useState<boolean>(false);
5151
const [reasonRequiredError, setReasonRequiredError] = useState<boolean>(false);
52-
const [isEditMode, setIsEditMode] = useState<boolean>(false);
53-
54-
useEffect(() => {
55-
if (strikeToEdit) {
56-
setStrikeFields(strikeToEdit);
57-
setIsEditMode(true);
58-
return;
59-
} else {
60-
setIsEditMode(false);
61-
}
62-
resetForm();
63-
}, [strikeToEdit]);
64-
65-
const resetForm = () => {
66-
setStrikeFields({
67-
id: '',
68-
date: new Date(),
69-
reporterID: '',
70-
reason: null,
71-
comments: '',
72-
} as Strike);
73-
74-
setCommentsRequiredError(false);
75-
setReasonRequiredError(false);
76-
};
52+
const isEditMode = Boolean(strikeToEdit);
7753

7854
const handleClose = () => {
7955
onClose();
80-
resetForm();
8156
};
8257
const handleStrikeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
8358
const { name, value } = e.target;
@@ -113,7 +88,6 @@ export const StrikeDetailsModal = ({
11388
onConfirmEdit(strikeFields);
11489
} else {
11590
onConfirmAdd(strikeFields);
116-
resetForm();
11791
}
11892
};
11993

client/src/features/trainee-profile/education/strikes/StrikesComponent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useTraineeProfileContext } from '../../context/useTraineeProfileContext
1212

1313
export const StrikesComponent = () => {
1414
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
15+
const [modalKeyCounter, setModalKeyCounter] = useState(0); //unique key to force remounting of the modal
1516

1617
const [modalError, setModalError] = useState<string>('');
1718
const [strikeToEdit, setStrikeToEdit] = useState<Strike | null>(null);
@@ -67,6 +68,7 @@ export const StrikesComponent = () => {
6768
* Function to enable adding strikes.
6869
*/
6970
const onClickAdd = () => {
71+
setModalKeyCounter((prevKey) => prevKey + 1); // Increment the key to force remount
7072
setStrikeToEdit(null);
7173
setIsModalOpen(true);
7274
};
@@ -128,6 +130,7 @@ export const StrikesComponent = () => {
128130
<StrikesList strikes={strikes || []} onClickEdit={onClickEdit} onClickDelete={onClickDelete} />
129131
)}
130132
<StrikeDetailsModal
133+
key={strikeToEdit ? strikeToEdit.id : modalKeyCounter} // Use strike ID for edit mode, counter for add mode
131134
isLoading={addStrikeLoading || editStrikeLoading}
132135
error={modalError}
133136
isOpen={isModalOpen}

client/src/features/trainee-profile/education/tests/TestDetailsModal.tsx

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
Typography,
1616
} from '@mui/material';
1717
import { Test, TestResult, TestType } from '../../../../data/types/Trainee';
18-
import { useEffect, useState } from 'react';
1918

2019
import { LoadingButton } from '@mui/lab';
2120
import { formatDate } from '../../utils/dateHelper';
21+
import { useState } from 'react';
2222

2323
type TestDetailsModalProps = {
2424
isOpen: boolean;
@@ -40,12 +40,12 @@ export const TestDetailsModal = ({
4040
testToEdit,
4141
}: TestDetailsModalProps) => {
4242
const [testFields, setTestFields] = useState<Partial<Test>>({
43-
id: '',
44-
date: new Date(),
45-
type: undefined,
46-
score: undefined,
47-
result: undefined,
48-
comments: '',
43+
id: testToEdit?.id || '',
44+
date: testToEdit?.date || new Date(),
45+
type: testToEdit?.type || undefined,
46+
score: testToEdit?.score || undefined,
47+
result: testToEdit?.result || undefined,
48+
comments: testToEdit?.comments || '',
4949
});
5050

5151
const [typeError, setTypeError] = useState(false);
@@ -54,31 +54,8 @@ export const TestDetailsModal = ({
5454

5555
const isEditMode = Boolean(testToEdit);
5656

57-
useEffect(() => {
58-
if (testToEdit) {
59-
setTestFields(testToEdit);
60-
} else {
61-
resetForm();
62-
}
63-
}, [testToEdit]);
64-
65-
const resetForm = () => {
66-
setTestFields({
67-
id: '',
68-
date: new Date(),
69-
type: undefined,
70-
score: undefined,
71-
result: undefined,
72-
comments: '',
73-
});
74-
setTypeError(false);
75-
setResultError(false);
76-
setScoreError(false);
77-
};
78-
7957
const handleClose = () => {
8058
onClose();
81-
resetForm();
8259
};
8360

8461
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -121,7 +98,6 @@ export const TestDetailsModal = ({
12198

12299
if (isEditMode) onConfirmEdit(testFields as Test);
123100
else onConfirmAdd(testFields as Test);
124-
resetForm();
125101
};
126102

127103
return (

client/src/features/trainee-profile/education/tests/TestsComponent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useTraineeProfileContext } from '../../context/useTraineeProfileContext
1212

1313
export const TestsComponent = () => {
1414
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
15+
const [modalKeyCounter, setModalKeyCounter] = useState(0);
1516

1617
const [modalError, setModalError] = useState<string>('');
1718
const [testToEdit, setTestToEdit] = useState<Test | null>(null);
@@ -68,6 +69,7 @@ export const TestsComponent = () => {
6869
* Function to enable adding tests.
6970
*/
7071
const onClickAdd = () => {
72+
setModalKeyCounter((prev) => prev + 1);
7173
setIsModalOpen(true);
7274
};
7375

@@ -127,6 +129,7 @@ export const TestsComponent = () => {
127129
)}
128130

129131
<TestDetailsModal
132+
key={testToEdit ? testToEdit.id : `newTest-${modalKeyCounter}`} // Force remount to reset internal state when opening for a new test
130133
isLoading={addTestLoading || editTestLoading}
131134
error={modalError}
132135
isOpen={isModalOpen}

client/src/features/trainee-profile/interactions/InteractionsInfo.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useState } from 'react';
99
import { useTraineeProfileContext } from '../context/useTraineeProfileContext';
1010

1111
const InteractionsInfo = () => {
12+
const [modalKeyCounter, setModalKeyCounter] = useState(0); //unique key to force remounting of the modal
1213
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
1314
const [modalError, setModalError] = useState<string>('');
1415
const [interactionToEdit, setInteractionToEdit] = useState<Interaction | null>(null);
@@ -56,6 +57,7 @@ const InteractionsInfo = () => {
5657
};
5758

5859
const onClickAdd = () => {
60+
setModalKeyCounter((prev) => prev + 1); // Force remounting of the modal to reset its internal state
5961
setIsModalOpen(true);
6062
};
6163

@@ -90,6 +92,7 @@ const InteractionsInfo = () => {
9092
)}
9193

9294
<InteractionDetailsModal
95+
key={interactionToEdit ? `edit-${interactionToEdit.id}` : `addInteraction-${modalKeyCounter}`}
9396
isLoading={addInteractionLoading || editInteractionLoading}
9497
error={modalError}
9598
isOpen={isModalOpen}

client/src/features/trainee-profile/interactions/components/InteractionDetailsModal.tsx

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212
Typography,
1313
} from '@mui/material';
1414
import { Interaction, InteractionType } from '../Interactions';
15-
import { useEffect, useState } from 'react';
1615

1716
import FormSelect from './FormSelect';
1817
import FormTextField from './FormTextField';
1918
import { LoadingButton } from '@mui/lab';
2019
import { formatDate } from '../../utils/dateHelper';
20+
import { useState } from 'react';
2121

2222
const types = Object.values(InteractionType);
2323

@@ -41,48 +41,22 @@ export const InteractionDetailsModal = ({
4141
interactionToEdit,
4242
}: InteractionDetailsModalProps) => {
4343
const [interactionFields, setInteractionFields] = useState<Partial<Interaction>>({
44-
id: '',
45-
date: new Date(),
46-
type: undefined,
47-
title: '',
48-
details: '',
49-
reporter: undefined,
44+
id: interactionToEdit?.id || '',
45+
date: interactionToEdit?.date || new Date(),
46+
type: interactionToEdit?.type || undefined,
47+
title: interactionToEdit?.type || '',
48+
details: interactionToEdit?.details || '',
49+
reporter: interactionToEdit?.reporter || undefined,
5050
});
5151

5252
const [typeError, setTypeError] = useState(false);
5353
const [detailsError, setDetailsError] = useState(false);
5454
const [titleError, setTitleError] = useState(false);
5555

56-
const [isEditMode, setIsEditMode] = useState<boolean>(false);
57-
58-
useEffect(() => {
59-
if (interactionToEdit) {
60-
setInteractionFields(interactionToEdit);
61-
setIsEditMode(true);
62-
return;
63-
} else {
64-
setIsEditMode(false);
65-
}
66-
resetForm();
67-
}, [interactionToEdit]);
68-
69-
const resetForm = () => {
70-
setInteractionFields({
71-
id: '',
72-
date: new Date(),
73-
type: undefined,
74-
title: '',
75-
details: '',
76-
reporter: undefined,
77-
});
78-
setTypeError(false);
79-
setDetailsError(false);
80-
setTitleError(false);
81-
};
56+
const isEditMode = Boolean(interactionToEdit);
8257

8358
const handleClose = () => {
8459
onClose();
85-
resetForm();
8660
};
8761

8862
const handleChange = (field: keyof Interaction) => (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -132,7 +106,6 @@ export const InteractionDetailsModal = ({
132106
onConfirmEdit(interactionFields as Interaction);
133107
} else {
134108
onConfirmAdd(interactionFields as Interaction);
135-
resetForm();
136109
}
137110
};
138111

0 commit comments

Comments
 (0)