Skip to content

Commit 6b7b907

Browse files
refactor: Update fetching and create mutations with tanstack/query (#233)
1 parent 9804975 commit 6b7b907

File tree

92 files changed

+1737
-1885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1737
-1885
lines changed

e2e/courses/EnrollStudent.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ test.describe.serial("Enroll student workflow", () => {
9393
await studentButton.click();
9494

9595
// Assert an alert is shown
96-
await expect(
97-
page.getByText("Student was enrolled successfully")
98-
).toBeVisible();
96+
await expect(page.getByText("Student enrolled successfully")).toBeVisible();
9997

10098
// Close the dialog
10199
await page.keyboard.press("Escape");

e2e/courses/JoinCourse.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test.describe.serial("Join courses workflow", () => {
8989

9090
// Assert an alert is shown
9191
await expect(
92-
page.getByText("Course was created successfully")
92+
page.getByText("The course was created successfully")
9393
).toBeVisible();
9494

9595
// Assert the modal is closed

e2e/courses/ToggleCourseVisibility.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ test.describe.serial("User can toggle the course visibility", () => {
7474
await expect(dropdownMenu).not.toBeVisible();
7575

7676
// Assert an alert is shown
77-
await expect(
78-
page.getByText("Course visibility was updated successfully")
79-
).toBeVisible();
77+
await expect(page.getByText("Course hidden successfully")).toBeVisible();
8078

8179
// Assert the course is not listed in the "Your courses" list
8280
await expect(page.getByText(courseName)).not.toBeVisible();
@@ -117,9 +115,7 @@ test.describe.serial("User can toggle the course visibility", () => {
117115
await expect(dropdownMenu).not.toBeVisible();
118116

119117
// Assert an alert is shown
120-
await expect(
121-
page.getByText("Course visibility was updated successfully")
122-
).toBeVisible();
118+
await expect(page.getByText("Course shown successfully")).toBeVisible();
123119

124120
// Close the "Hidden courses" list
125121
await page.getByText("Hidden courses", { exact: true }).click();

e2e/rubrics/EditRubric.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test.describe.serial("Rubrics edition workflow", () => {
7575

7676
// Assert an alert is shown
7777
await expect(
78-
page.getByText("Rubric name has been updated successfully")
78+
page.getByText("Rubric renamed successfully")
7979
).toBeVisible();
8080

8181
// Reload the page and assert the rubric name was updated
@@ -180,7 +180,7 @@ test.describe.serial("Rubrics edition workflow", () => {
180180

181181
// Assert the changes were saved
182182
await expect(
183-
page.getByText("The objective has been updated successfully")
183+
page.getByText("Objective updated successfully")
184184
).toBeVisible();
185185

186186
// Reload the page and assert the changes were saved
@@ -232,7 +232,7 @@ test.describe.serial("Rubrics edition workflow", () => {
232232

233233
// Assert the changes were saved
234234
await expect(
235-
page.getByText("The criteria has been updated successfully")
235+
page.getByText("Criteria updated successfully")
236236
).toBeVisible();
237237

238238
// Reload the page and assert the changes were saved
@@ -290,7 +290,7 @@ test.describe.serial("Rubrics edition workflow", () => {
290290

291291
// Assert an alert is shown
292292
await expect(
293-
page.getByText("The criteria has been deleted successfully")
293+
page.getByText("Criteria deleted successfully")
294294
).toBeVisible();
295295
});
296296

@@ -331,7 +331,7 @@ test.describe.serial("Rubrics edition workflow", () => {
331331

332332
// Assert an alert is shown
333333
await expect(
334-
page.getByText("The objective has been deleted successfully")
334+
page.getByText("Objective deleted successfully")
335335
).toBeVisible();
336336

337337
// Assert the objective was deleted

src/components/FoundStudentCard/FoundStudentCard.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/components/GridContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactNode } from "react";
22

3-
export const GridContainer = ({ children }: { children: ReactNode[] }) => {
3+
export const GridContainer = ({ children }: { children?: ReactNode[] }) => {
44
return (
55
<section className="grid w-full grid-cols-[repeat(auto-fill,minmax(250px,1fr))] items-center gap-8">
66
{children}

src/components/ui/form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const useFormField = () => {
4343
const itemContext = React.useContext(FormItemContext);
4444
const { getFieldState, formState } = useFormContext();
4545

46-
const fieldState = getFieldState(fieldContext.name, formState);
46+
const fieldstate = getFieldState(fieldContext.name, formState);
4747

4848
if (!fieldContext) {
4949
throw new Error("useFormField should be used within <FormField>");
@@ -57,7 +57,7 @@ const useFormField = () => {
5757
formItemId: `${id}-form-item`,
5858
formDescriptionId: `${id}-form-item-description`,
5959
formMessageId: `${id}-form-item-message`,
60-
...fieldState
60+
...fieldstate
6161
};
6262
};
6363

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
import { CoursesActions } from "@/hooks/courses/coursesReducer";
2-
import { CoursesState, useCourses } from "@/hooks/courses/useCourses";
31
import { Course } from "@/types/entities/general-entities";
42
import { ReactNode, createContext, useState } from "react";
53

6-
interface UserCoursesContext {
7-
isLoading: boolean;
8-
userCourses: CoursesState;
9-
userCoursesDispatcher: React.Dispatch<CoursesActions>;
10-
4+
interface UserCoursesDialogsContext {
115
renameCourseDialogState: RenameCourseDialogState;
126
openRenameCourseDialog: (course: Course) => void;
137
closeRenameCourseDialog: () => void;
148
}
159

16-
const defaultValues: UserCoursesContext = {
17-
// Courses state
18-
isLoading: false,
19-
userCourses: {
20-
courses: [],
21-
hiddenCourses: []
22-
},
23-
userCoursesDispatcher: () => {},
24-
10+
const defaultValues: UserCoursesDialogsContext = {
2511
// Dialogs state
2612
openRenameCourseDialog: () => {},
2713
closeRenameCourseDialog: () => {},
@@ -36,12 +22,14 @@ type RenameCourseDialogState = {
3622
selectedCourse: Course | null;
3723
};
3824

39-
export const UserCoursesContext =
40-
createContext<UserCoursesContext>(defaultValues);
41-
42-
export const UserCoursesProvider = ({ children }: { children: ReactNode }) => {
43-
const { loading, courses, coursesDispatcher } = useCourses();
25+
export const UserCoursesDialogsContext =
26+
createContext<UserCoursesDialogsContext>(defaultValues);
4427

28+
export const UserCoursesDialogsProvider = ({
29+
children
30+
}: {
31+
children: ReactNode;
32+
}) => {
4533
// Dialogs state
4634
const [renameCourseDialogState, setRenameCourseDialogState] =
4735
useState<RenameCourseDialogState>({
@@ -63,17 +51,14 @@ export const UserCoursesProvider = ({ children }: { children: ReactNode }) => {
6351
};
6452

6553
return (
66-
<UserCoursesContext.Provider
54+
<UserCoursesDialogsContext.Provider
6755
value={{
68-
isLoading: loading,
69-
userCourses: courses,
70-
userCoursesDispatcher: coursesDispatcher,
7156
renameCourseDialogState,
7257
openRenameCourseDialog,
7358
closeRenameCourseDialog
7459
}}
7560
>
7661
{children}
77-
</UserCoursesContext.Provider>
62+
</UserCoursesDialogsContext.Provider>
7863
);
7964
};

src/context/laboratories/CourseLaboratoriesContext.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/hooks/courses/coursesReducer.ts

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)