Skip to content

Commit c5f5250

Browse files
committed
2 parents 34127b4 + 2b84914 commit c5f5250

File tree

5 files changed

+71
-77
lines changed

5 files changed

+71
-77
lines changed

frontend/src/components/AdminUsersTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const ITEMS_PER_PAGE_OPTIONS = [5, 10]; // Number of items to display per page
3232

3333
const AdminUsersTable: React.FC = () => {
3434
const [adminUsersData, setAdminUsersData] = useState<AdminUser[]>([]);
35-
const [currentPage, setCurrentPage] = useState<number>(1);
35+
const [currentPage, setCurrentPage] = useState<number>(0);
3636
const [itemsPerPage, setItemsPerPage] = useState<number>(
3737
ITEMS_PER_PAGE_OPTIONS[0]
3838
);
@@ -57,7 +57,7 @@ const AdminUsersTable: React.FC = () => {
5757

5858
const handleChangeItemsPerPage = (event: SelectChangeEvent<unknown>) => {
5959
setItemsPerPage(event.target.value as number);
60-
setCurrentPage(1);
60+
setCurrentPage(0);
6161
};
6262

6363
const removeAdmin = async (admin: AdminUser, index: number) => {
@@ -73,7 +73,7 @@ const AdminUsersTable: React.FC = () => {
7373
setAdminUsersData(adminUsersData.filter((e, i) => i !== index));
7474
};
7575

76-
const indexOfLastAdmin = currentPage * itemsPerPage;
76+
const indexOfLastAdmin = (currentPage + 1) * itemsPerPage;
7777
const indexOfFirstAdmin = indexOfLastAdmin - itemsPerPage;
7878
const currentAdmins = adminUsersData.slice(
7979
indexOfFirstAdmin,
@@ -143,7 +143,7 @@ const AdminUsersTable: React.FC = () => {
143143
component="div"
144144
count={adminUsersData.length}
145145
rowsPerPage={itemsPerPage}
146-
page={currentPage - 1}
146+
page={currentPage}
147147
onPageChange={handlePageChange}
148148
/>
149149
</div>
Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,54 @@
11
import React from "react";
22
import QuestionForm from "./QuestionForm";
3-
import {Box, Button} from "@mui/material";
3+
import { Box, Button } from "@mui/material";
44
import Question from "./Question";
55
import Typography from "@mui/material/Typography";
6-
import {addQuestion} from "../../api/questions/data";
7-
import {AxiosError} from "axios";
8-
6+
import { addQuestion } from "../../api/questions/data";
7+
import { AxiosError } from "axios";
98

109
const AddQuestionTab: React.FC = () => {
11-
const [addQuestions, setAddQuestions] = React.useState(false);
12-
13-
const handleAddQuestionClick = () => {
14-
setAddQuestions(true);
15-
}
16-
const onSubmit = async (question: Question) => {
17-
console.log(question);
18-
let questionToAdd = new Question(question);
19-
20-
try {
21-
const questionAdded = await addQuestion(questionToAdd);
22-
console.log(questionAdded);
23-
setAddQuestions(false);
24-
} catch (e) {
25-
if (e instanceof AxiosError && e.response) {
26-
console.log(e.response.data.code);
27-
} else if (e instanceof Error) {
28-
console.log(e.message);
29-
}
30-
}
31-
};
32-
33-
const onCancel = () => {
34-
setAddQuestions(false);
10+
const [addQuestions, setAddQuestions] = React.useState(false);
11+
12+
const handleAddQuestionClick = () => {
13+
setAddQuestions(true);
14+
};
15+
const onSubmit = async (question: Question) => {
16+
console.log(question);
17+
let questionToAdd = new Question(question);
18+
19+
try {
20+
const questionAdded = await addQuestion(questionToAdd);
21+
console.log(questionAdded);
22+
setAddQuestions(false);
23+
} catch (e) {
24+
if (e instanceof AxiosError && e.response) {
25+
console.log(e.response.data.code);
26+
} else if (e instanceof Error) {
27+
console.log(e.message);
28+
}
3529
}
30+
};
3631

32+
const onCancel = () => {
33+
setAddQuestions(false);
34+
};
3735

38-
return (
36+
return (
37+
<Box component="span" padding={2} width="80%">
38+
{addQuestions ? (
3939
<React.Fragment>
40-
<Box component="span" padding={2} width='80%'>
41-
{addQuestions ?
42-
<React.Fragment>
43-
<Typography variant="h5" gutterBottom>
44-
Add Question
45-
</Typography>
46-
<QuestionForm onSubmit={onSubmit} onCancel={onCancel} />
47-
</React.Fragment>
48-
:
49-
<Button variant="contained" onClick={handleAddQuestionClick}>
50-
Add Question
51-
</Button>
52-
}
53-
</Box>
40+
<Typography variant="h5" gutterBottom>
41+
Add Question
42+
</Typography>
43+
<QuestionForm onSubmit={onSubmit} onCancel={onCancel} />
5444
</React.Fragment>
55-
);
56-
}
57-
58-
export default AddQuestionTab;
45+
) : (
46+
<Button variant="contained" onClick={handleAddQuestionClick}>
47+
Add Question
48+
</Button>
49+
)}
50+
</Box>
51+
);
52+
};
53+
54+
export default AddQuestionTab;

frontend/src/components/Questions/EditQuestionsTab.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,29 @@ const EditQuestionsTab: React.FC = () => {
5454
};
5555

5656
return (
57-
<React.Fragment>
58-
<Box component="span" padding={2} width="80%">
59-
{editQuestions ? (
60-
<React.Fragment>
61-
<Typography variant="h5" gutterBottom>
62-
Edit Questions
63-
</Typography>
64-
<Grid container spacing={3}>
65-
<Grid item sm={12}>
66-
<EditQuestionsTable onEdit={onEdit} onDelete={onDelete} />
67-
</Grid>
68-
<Grid item sm={12}>
69-
<Button variant="contained" onClick={handleStopEdit}>
70-
Finish Editing
71-
</Button>
72-
</Grid>
73-
</Grid>
74-
</React.Fragment>
75-
) : (
76-
<Button variant="contained" onClick={handleStartEdit}>
57+
<Box component="span" padding={2} width="80%">
58+
{editQuestions ? (
59+
<React.Fragment>
60+
<Typography variant="h5" gutterBottom>
7761
Edit Questions
78-
</Button>
79-
)}
80-
</Box>
81-
</React.Fragment>
62+
</Typography>
63+
<Grid container spacing={3}>
64+
<Grid item sm={12}>
65+
<EditQuestionsTable onEdit={onEdit} onDelete={onDelete} />
66+
</Grid>
67+
<Grid item sm={12}>
68+
<Button variant="contained" onClick={handleStopEdit}>
69+
Finish Editing
70+
</Button>
71+
</Grid>
72+
</Grid>
73+
</React.Fragment>
74+
) : (
75+
<Button variant="contained" onClick={handleStartEdit}>
76+
Edit Questions
77+
</Button>
78+
)}
79+
</Box>
8280
);
8381
};
8482

frontend/src/components/Questions/EditQuestionsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const EditQuestionsTable: React.FC<EditQuestionsTableProps> = ({onEdit, onDelete
5454
event: SelectChangeEvent<unknown>,
5555
) => {
5656
setItemsPerPage(event.target.value as number);
57-
setCurrentPage(1);
57+
setCurrentPage(0);
5858
};
5959

6060
const handleExpandClick = (id: string) => {

frontend/src/components/Questions/QuestionsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const filteredQuestions = questionsData.filter(question =>
7070

7171
const handleChangeItemsPerPage = (event: SelectChangeEvent<unknown>) => {
7272
setItemsPerPage(event.target.value as number);
73-
setCurrentPage(1);
73+
setCurrentPage(0);
7474
};
7575

7676
const indexOfLastQuestion = (currentPage + 1) * itemsPerPage;

0 commit comments

Comments
 (0)