Skip to content

Commit

Permalink
chore: merge & toast example
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 23, 2024
1 parent 5c2fe8a commit 11c7d69
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 0 additions & 8 deletions frontend/src/composables/services/course.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Course } from '@/types/Course.ts';
import { type Ref, ref } from 'vue';
import { endpoints } from '@/config/endpoints.ts';
import { i18n } from '@/config/i18n.ts';
import { get, getList, create, patch, deleteId, getPaginatedList } from '@/composables/services/helpers.ts';
import { type Response } from '@/types/Response.ts';
import { type CoursePaginatorResponse } from '@/types/filter/Paginator.ts';
import { type Filter } from '@/types/filter/Filter.ts';
import { type User } from '@/types/users/User.ts';
import { useMessagesStore } from '@/store/messages.store.ts';

interface CoursesState {
pagination: Ref<CoursePaginatorResponse | null>;
Expand Down Expand Up @@ -95,8 +93,6 @@ export function useCourses(): CoursesState {
}

async function createCourse(courseData: Course, selfProcessError: boolean = true): Promise<void> {
const { t } = i18n.global;
const { addSuccessMessage } = useMessagesStore();
const endpoint = endpoints.courses.index;
await create<Course>(
endpoint,
Expand All @@ -114,10 +110,6 @@ export function useCourses(): CoursesState {
undefined,
selfProcessError,
);
addSuccessMessage(
t('toasts.messages.success'),
t('toasts.messages.courses.create.success', [course.value?.name]),
);
}

async function updateCourse(courseData: Course, selfProcessError: boolean = true): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function useGroup(): GroupState {
score: groupData.score,
},
response,
selfProcessError
selfProcessError,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/composables/services/project.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Project, type ProjectJSON } from '@/types/Project';
import { Project } from '@/types/Project';
import { type Ref, ref } from 'vue';
import { endpoints } from '@/config/endpoints.ts';
import { i18n } from '@/config/i18n.ts';
Expand Down Expand Up @@ -52,7 +52,7 @@ export function useProject(): ProjectState {

async function getProjectsByTeacher(teacherId: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.projects.byTeacher.replace('{teacherId}', teacherId);
await getList<Project>(endpoint, projects, Project.fromJSON);
await getList<Project>(endpoint, projects, Project.fromJSON, selfProcessError);
}

async function getProjectsByCourseAndDeadline(
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/views/courses/CreateCourseView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { useFaculty } from '@/composables/services/faculty.service.ts';
import { type Course } from '@/types/Course.ts';
import { useCourses } from '@/composables/services/course.service.ts';
import { useRouter } from 'vue-router';
import { useMessagesStore } from '@/store/messages.store.ts';
/* Composable injections */
const { t } = useI18n();
const { addSuccessMessage } = useMessagesStore();
const { push } = useRouter();
const { faculties, getFaculties } = useFaculty();
const { createCourse } = useCourses();
Expand All @@ -25,8 +27,13 @@ const loading = ref(true);
* @param course
*/
async function saveCourse(course: Course): Promise<void> {
await createCourse(course);
await push({ name: 'dashboard' });
try {
await createCourse(course);
addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.courses.create.success', [course.name]));
await push({ name: 'dashboard' });
} catch (error: any) {
// TODO error message
}
}
/** Load the data */
Expand Down

0 comments on commit 11c7d69

Please sign in to comment.