Skip to content

Commit

Permalink
chore: helper function that also shows a toast message upon successfu…
Browse files Browse the repository at this point in the history
…l creation #407
  • Loading branch information
bsilkyn committed May 18, 2024
1 parent fc58576 commit 4cc1467
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/src/assets/lang/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"success": "Success",
"error": "Error",
"unknown": "An unknown error has occurred.",
"create": "The {type} has successfully been created",
"courses": {
"enrollment": {
"success": "You have been successfully enrolled for the course '{0}'.",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/lang/app/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
"success": "Succes",
"error": "Fout",
"unknown": "Er is een onbekende fout opgetreden.",
"create": "De {type} werd succesvol aangemaakt",
"courses": {
"enrollment": {
"success": "Je bent succesvol ingeschreven voor het vak '{0}'.",
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/composables/services/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ export async function create<T>(
}
}

export async function createToast<T>(
type: string,
endpoint: string,
data: any,
ref: Ref<T | null>,
fromJson: (data: any) => T,
contentType: string = 'application/json'
): Promise<void> {
const { t } = i18n.global;
const { addSuccessMessage } = useMessagesStore();

try {
await create<T>(endpoint, data, ref, fromJson, contentType)
addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.create', { type: type }));
} catch (e) {
throw e
}
}


/**
* Patch an item given its ID.
*
Expand Down

0 comments on commit 4cc1467

Please sign in to comment.