diff --git a/frontend/src/assets/lang/app/en.json b/frontend/src/assets/lang/app/en.json index 28db6a9f..858ccd2e 100644 --- a/frontend/src/assets/lang/app/en.json +++ b/frontend/src/assets/lang/app/en.json @@ -212,6 +212,21 @@ "student": "Student", "assistant": "Assistant", "teacher": "Teacher" + }, + "article": { + "admin": "The admin", + "assistant": "The assistant", + "course": "The course", + "docker": "The docker image", + "extraCheck": "The extra check", + "faculty": "The faculty", + "group": "The group", + "project": "The project", + "structureCheck": "The structure check", + "student": "The student", + "submission": "The submission", + "teacher": "The teacher", + "user": "The user" } }, "helpers": { @@ -222,7 +237,7 @@ "success": "Success", "error": "Error", "unknown": "An unknown error has occurred.", - "create": "The object has successfully been created", + "create": "{type} has successfully been created", "courses": { "enrollment": { "success": "You have been successfully enrolled for the course '{0}'.", diff --git a/frontend/src/assets/lang/app/nl.json b/frontend/src/assets/lang/app/nl.json index 0a11c5a7..dcc844f3 100644 --- a/frontend/src/assets/lang/app/nl.json +++ b/frontend/src/assets/lang/app/nl.json @@ -209,6 +209,21 @@ "student": "Student", "assistant": "Assistent", "teacher": "Professor" + }, + "article": { + "admin": "De admin", + "assistant": "De assistent", + "course": "Het vak", + "docker": "De docker image", + "extraCheck": "De extra check", + "faculty": "De faculteit", + "group": "De groep", + "project": "Het project", + "structureCheck": "The structuurcheck", + "student": "De student", + "submission": "De indiening", + "teacher": "De professor", + "user": "De gebruiker" } }, "helpers": { @@ -219,7 +234,7 @@ "success": "Succes", "error": "Fout", "unknown": "Er is een onbekende fout opgetreden.", - "create": "Het object werd succesvol aangemaakt", + "create": "{type} werd succesvol aangemaakt", "courses": { "enrollment": { "success": "Je bent succesvol ingeschreven voor het vak '{0}'.", diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index 58db0007..b5e09ee7 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -1,6 +1,6 @@ import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId } from '@/composables/services/helpers.ts'; +import { get, getList, deleteId, createToast } from '@/composables/services/helpers.ts'; import { User } from '@/types/users/User.ts'; interface AdminState { @@ -28,7 +28,8 @@ export function useAdmin(): AdminState { async function createAdmin(user: User): Promise { const endpoint = endpoints.admins.index; - await create( + await createToast( + 'admin', endpoint, { id: user.id, diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 70690cf6..98841db4 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -3,7 +3,15 @@ import { type User } from '@/types/users/User.ts'; import { Response } from '@/types/Response'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId, deleteIdWithData, getPaginatedList } from '@/composables/services/helpers.ts'; +import { + get, + getList, + create, + deleteId, + deleteIdWithData, + getPaginatedList, + createToast, +} from '@/composables/services/helpers.ts'; import { type PaginatorResponse } from '@/types/filter/Paginator.ts'; import { type Filter } from '@/types/filter/Filter.ts'; @@ -61,7 +69,8 @@ export function useAssistant(): AssistantState { async function createAssistant(user: User): Promise { const endpoint = endpoints.assistants.index; - await create( + await createToast( + 'assistant', endpoint, { user: user.id, diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index 69b25946..c08a5d1a 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -3,7 +3,7 @@ import { Response } from '@/types/Response.ts'; import { endpoints } from '@/config/endpoints.ts'; import { type Ref, ref } from 'vue'; import { type Filter } from '@/types/filter/Filter.ts'; -import { create, getList, getPaginatedList, patch } from '@/composables/services/helpers.ts'; +import { createToast, getList, getPaginatedList, patch } from '@/composables/services/helpers.ts'; import { type PaginatorResponse } from '@/types/filter/Paginator.ts'; interface DockerImagesState { @@ -38,7 +38,8 @@ export function useDockerImages(): DockerImagesState { async function createDockerImage(dockerData: DockerImage, file: File): Promise { const endpoint = endpoints.dockerImages.index; - await create( + await createToast( + 'docker', endpoint, { file, diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 00e01f37..8d9dfce4 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -1,7 +1,7 @@ import { Faculty } from '@/types/Faculty.ts'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId } from '@/composables/services/helpers.ts'; +import { get, getList, deleteId, createToast } from '@/composables/services/helpers.ts'; interface FacultyState { faculties: Ref; @@ -28,7 +28,13 @@ export function useFaculty(): FacultyState { async function createFaculty(facultyData: Faculty): Promise { const endpoint = endpoints.faculties.index; - await create(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON); + await createToast( + 'faculty', + endpoint, + { id: facultyData.id, name: facultyData.name }, + faculty, + Faculty.fromJSON, + ); } async function deleteFaculty(id: string): Promise { diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index e8946269..f02830cf 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -57,6 +57,7 @@ export async function create( /** * Create an item and display toast message when successful stating the creation has been successful. * + * @param type type of the object that gets created * @param endpoint * @param data * @param ref @@ -64,24 +65,20 @@ export async function create( * @param contentType */ export async function createToast( + type: string, endpoint: string, data: any, ref: Ref, fromJson: (data: any) => T, - contentType: string = 'application/json' + contentType: string = 'application/json', ): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); - try { - await create(endpoint, data, ref, fromJson, contentType) - addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.create')); - } catch (e) { - throw e - } + await create(endpoint, data, ref, fromJson, contentType); + addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.create', { type: t('types.article.' + type) })); } - /** * Patch an item given its ID. * diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index cfc89d90..c75947d2 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -1,7 +1,7 @@ import { StructureCheck } from '@/types/StructureCheck.ts'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId } from '@/composables/services/helpers.ts'; +import { get, getList, deleteId, createToast } from '@/composables/services/helpers.ts'; interface StructureCheckState { structureChecks: Ref; @@ -28,7 +28,8 @@ export function useStructureCheck(): StructureCheckState { async function createStructureCheck(structureCheckData: StructureCheck, projectId: string): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await create( + await createToast( + 'structureCheck', endpoint, { name: structureCheckData.name, diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index c70c67bd..713ac8d3 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -2,7 +2,7 @@ import { Student } from '@/types/users/Student.ts'; import { Response } from '@/types/Response'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId, deleteIdWithData } from '@/composables/services/helpers.ts'; +import { get, getList, create, deleteId, deleteIdWithData, createToast } from '@/composables/services/helpers.ts'; interface StudentsState { students: Ref; @@ -69,7 +69,8 @@ export function useStudents(): StudentsState { async function createStudent(studentData: Student): Promise { const endpoint = endpoints.students.index; - await create( + await createToast( + 'student', endpoint, { user: studentData.id, diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 11cf66bc..708ca51c 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -4,7 +4,15 @@ import { Teacher } from '@/types/users/Teacher.ts'; import { Response } from '@/types/Response'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { get, getList, create, deleteId, deleteIdWithData, getPaginatedList } from '@/composables/services/helpers.ts'; +import { + get, + getList, + create, + deleteId, + deleteIdWithData, + getPaginatedList, + createToast, +} from '@/composables/services/helpers.ts'; import { type PaginatorResponse } from '@/types/filter/Paginator.ts'; import { type Filter } from '@/types/filter/Filter.ts'; @@ -62,7 +70,8 @@ export function useTeacher(): TeacherState { async function createTeacher(user: User): Promise { const endpoint = endpoints.teachers.index; - await create( + await createToast( + 'teacher', endpoint, { user: user.id, diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 50a3279a..565e5967 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -3,7 +3,7 @@ import { User } from '@/types/users/User.ts'; import { type Response } from '@/types/Response.ts'; import { type PaginatorResponse } from '@/types/filter/Paginator.ts'; import { endpoints } from '@/config/endpoints.ts'; -import { create, get, patch, getList, getPaginatedList } from '@/composables/services/helpers.ts'; +import { get, patch, getList, getPaginatedList, createToast } from '@/composables/services/helpers.ts'; import { type Filter } from '@/types/filter/Filter.ts'; interface userState { @@ -40,7 +40,8 @@ export function useUser(): userState { async function createUser(userData: User): Promise { const endpoint = endpoints.users.index; - await create( + await createToast( + 'user', endpoint, { username: userData.username,