Skip to content

Commit deb3ed5

Browse files
committed
upgraded eslint and fixed errors
1 parent d648796 commit deb3ed5

File tree

7 files changed

+61
-122
lines changed

7 files changed

+61
-122
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: 10 additions & 36 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;
@@ -27,7 +27,7 @@ interface StrikeDetailsModalProps {
2727
onClose: () => void;
2828
onConfirmAdd: (strike: Strike) => void;
2929
onConfirmEdit: (strike: Strike) => void;
30-
strikeToEdit: Strike | null;
30+
initialStrike: Strike | null;
3131
}
3232

3333
export const StrikeDetailsModal = ({
@@ -37,47 +37,22 @@ export const StrikeDetailsModal = ({
3737
onClose,
3838
onConfirmAdd,
3939
onConfirmEdit,
40-
strikeToEdit,
40+
initialStrike,
4141
}: StrikeDetailsModalProps) => {
4242
const [strikeFields, setStrikeFields] = useState<Strike>({
43-
id: '',
44-
date: new Date(),
45-
reporterID: '',
46-
comments: '',
47-
reason: null,
43+
id: initialStrike?.id || '',
44+
date: initialStrike?.date || new Date(),
45+
reporterID: initialStrike?.reporterID || '',
46+
comments: initialStrike?.comments || '',
47+
reason: initialStrike?.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(initialStrike);
7753

7854
const handleClose = () => {
7955
onClose();
80-
resetForm();
8156
};
8257
const handleStrikeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
8358
const { name, value } = e.target;
@@ -109,11 +84,10 @@ export const StrikeDetailsModal = ({
10984
return;
11085
}
11186

112-
if (strikeToEdit) {
87+
if (initialStrike) {
11388
onConfirmEdit(strikeFields);
11489
} else {
11590
onConfirmAdd(strikeFields);
116-
resetForm();
11791
}
11892
};
11993

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const StrikesComponent = () => {
4141
};
4242

4343
const onConfirmAdd = async (strike: Strike) => {
44+
if (modalError) setModalError('');
4445
addStrike(strike, {
4546
onSuccess: handleSuccess,
4647
onError: (e) => {
@@ -50,6 +51,7 @@ export const StrikesComponent = () => {
5051
};
5152

5253
const onConfirmEdit = (strike: Strike) => {
54+
if (modalError) setModalError('');
5355
editStrike(strike, {
5456
onSuccess: handleSuccess,
5557
onError: (e) => {
@@ -128,13 +130,14 @@ export const StrikesComponent = () => {
128130
<StrikesList strikes={strikes || []} onClickEdit={onClickEdit} onClickDelete={onClickDelete} />
129131
)}
130132
<StrikeDetailsModal
133+
key={strikeToEdit?.id || `add-strike-${isModalOpen}`} // Use strike ID for edit mode, and a unique key for add mode to force remounting
131134
isLoading={addStrikeLoading || editStrikeLoading}
132135
error={modalError}
133136
isOpen={isModalOpen}
134137
onClose={closeModal}
135138
onConfirmAdd={onConfirmAdd}
136139
onConfirmEdit={onConfirmEdit}
137-
strikeToEdit={strikeToEdit}
140+
initialStrike={strikeToEdit}
138141
/>
139142
</div>
140143
</>

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

Lines changed: 10 additions & 34 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;
@@ -27,7 +27,7 @@ type TestDetailsModalProps = {
2727
onClose: () => void;
2828
onConfirmAdd: (t: Test) => void;
2929
onConfirmEdit: (t: Test) => void;
30-
testToEdit: Test | null;
30+
initialTest: Test | null;
3131
};
3232

3333
export const TestDetailsModal = ({
@@ -37,48 +37,25 @@ export const TestDetailsModal = ({
3737
onClose,
3838
onConfirmAdd,
3939
onConfirmEdit,
40-
testToEdit,
40+
initialTest,
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: initialTest?.id || '',
44+
date: initialTest?.date || new Date(),
45+
type: initialTest?.type || undefined,
46+
score: initialTest?.score || undefined,
47+
result: initialTest?.result || undefined,
48+
comments: initialTest?.comments || '',
4949
});
5050

5151
const [typeError, setTypeError] = useState(false);
5252
const [resultError, setResultError] = useState(false);
5353
const [scoreError, setScoreError] = useState(false);
5454

55-
const isEditMode = Boolean(testToEdit);
56-
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-
};
55+
const isEditMode = Boolean(initialTest);
7856

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const TestsComponent = () => {
1414
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
1515

1616
const [modalError, setModalError] = useState<string>('');
17-
const [testToEdit, setTestToEdit] = useState<Test | null>(null);
17+
const [initialTest, setInitialTest] = useState<Test | null>(null);
1818
const { traineeId } = useTraineeProfileContext();
1919
const { mutate: addTest, isPending: addTestLoading } = useAddTest(traineeId);
2020
const { mutate: deleteTest, isPending: deleteTestLoading, error: deleteTestError } = useDeleteTest(traineeId);
@@ -27,7 +27,7 @@ export const TestsComponent = () => {
2727
const handleSuccess = () => {
2828
queryClient.invalidateQueries({ queryKey: ['tests', traineeId] });
2929
setIsModalOpen(false);
30-
setTestToEdit(null);
30+
setInitialTest(null);
3131
};
3232

3333
const getErrorMessage = (error: Error | unknown) => {
@@ -37,11 +37,13 @@ export const TestsComponent = () => {
3737
const onClickEdit = (id: string) => {
3838
const test = tests?.find((test) => test.id === id) || null;
3939

40-
setTestToEdit(test);
40+
setInitialTest(test);
4141
setIsModalOpen(true);
4242
};
4343

4444
const onConfirmAdd = async (test: Test) => {
45+
if (modalError) setModalError('');
46+
4547
addTest(test, {
4648
onSuccess: handleSuccess,
4749
onError: (e) => {
@@ -51,6 +53,7 @@ export const TestsComponent = () => {
5153
};
5254

5355
const onConfirmEdit = (test: Test) => {
56+
if (modalError) setModalError('');
5457
editTest(test, {
5558
onSuccess: handleSuccess,
5659
onError: (e) => {
@@ -76,7 +79,7 @@ export const TestsComponent = () => {
7679
*/
7780
const closeModal = () => {
7881
setIsModalOpen(false);
79-
setTestToEdit(null);
82+
setInitialTest(null);
8083
setModalError('');
8184
};
8285

@@ -127,13 +130,14 @@ export const TestsComponent = () => {
127130
)}
128131

129132
<TestDetailsModal
133+
key={initialTest?.id || `add-test-${isModalOpen}`} // Force remount to reset internal state when opening for a new test
130134
isLoading={addTestLoading || editTestLoading}
131135
error={modalError}
132136
isOpen={isModalOpen}
133137
onClose={closeModal}
134138
onConfirmAdd={onConfirmAdd}
135139
onConfirmEdit={onConfirmEdit}
136-
testToEdit={testToEdit}
140+
initialTest={initialTest}
137141
/>
138142
</div>
139143
</>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const InteractionsInfo = () => {
3838
};
3939

4040
const onConfirmAdd = async (interaction: Interaction) => {
41+
if (modalError) setModalError('');
4142
addInteraction(interaction, {
4243
onSuccess: handleSuccess,
4344
onError: (e) => {
@@ -47,6 +48,7 @@ const InteractionsInfo = () => {
4748
};
4849

4950
const onConfirmEdit = (interaction: Interaction) => {
51+
if (modalError) setModalError('');
5052
editInteraction(interaction, {
5153
onSuccess: handleSuccess,
5254
onError: (e) => {
@@ -90,13 +92,14 @@ const InteractionsInfo = () => {
9092
)}
9193

9294
<InteractionDetailsModal
95+
key={interactionToEdit?.id || `add-interaction-${isModalOpen}`} // Use interaction ID for edit mode, and a unique key for add mode to force remounting
9396
isLoading={addInteractionLoading || editInteractionLoading}
9497
error={modalError}
9598
isOpen={isModalOpen}
9699
onClose={closeModal}
97100
onConfirmAdd={onConfirmAdd}
98101
onConfirmEdit={onConfirmEdit}
99-
interactionToEdit={interactionToEdit}
102+
initialInteraction={interactionToEdit}
100103
/>
101104
</Box>
102105
</>

0 commit comments

Comments
 (0)