diff --git a/addon/components/work-item-button.js b/addon/components/work-item-button.js index 234eef4cf..c9c2bcc8c 100644 --- a/addon/components/work-item-button.js +++ b/addon/components/work-item-button.js @@ -29,6 +29,7 @@ export default class WorkItemButtonComponent extends Component { @queryManager apollo; + @service notification; @service intl; cancelWorkItemMutation = cancelWorkItem; @@ -37,9 +38,27 @@ export default class WorkItemButtonComponent extends Component { @dropTask *mutate() { - yield this.apollo.mutate({ - mutation: this[`${this.args.mutation}WorkItemMutation`], - variables: { id: this.args.workItemId }, - }); + try { + yield this.apollo.mutate({ + mutation: this[`${this.args.mutation}WorkItemMutation`], + variables: { id: this.args.workItemId }, + }); + + if (this.args.onSuccess) { + this.args.onSuccess(); + } else { + this.notification.success( + this.intl.t("caluma.mutate-work-item.success") + ); + } + } catch (e) { + if (this.args.onError) { + this.args.onError(e); + } else { + // eslint-disable-next-line no-console + console.error(e); + this.notification.danger(this.intl.t("caluma.mutate-work-item.error")); + } + } } } diff --git a/tests/dummy/app/templates/docs/buttons.md b/tests/dummy/app/templates/docs/buttons.md index c846ef382..b77366e80 100644 --- a/tests/dummy/app/templates/docs/buttons.md +++ b/tests/dummy/app/templates/docs/buttons.md @@ -28,17 +28,19 @@ The text of the button is per default the mutation name, it can be overwritten w ``` - The WorkItemButton component has 3 parameters: - - - `mutation` The state mutation to be used either `complete`, `skip` or `cancel`. - - `workItemId` Id of the work item which should be mutated. - - `label` (Optional) Overwrites the button text. - - Additionally there are many optional parameters for the underlying [UkButton](https://adfinis-sygroup.github.io/ember-uikit/#/docs/components/button) component, refer to the UkButton component documentation to see what exactly they do: - - - `type` - - `disabled` - - `loading` - - `color` - - `size` - - `title` +The WorkItemButton component has 5 parameters: + +- `mutation` The state mutation to be used either `complete`, `skip` or `cancel`. +- `workItemId` Id of the work item which should be mutated. +- `label` (Optional) Overwrites the button text. +- `onSuccess`(Optional) Function to be called when the mutation succeeds. +- `onError`(Optional) Function to be called when the mutation fails. + +Additionally there are many optional parameters for the underlying [UkButton](https://adfinis-sygroup.github.io/ember-uikit/#/docs/components/button) component, refer to the UkButton component documentation to see what exactly they do: + +- `type` +- `disabled` +- `loading` +- `color` +- `size` +- `title` diff --git a/translations/de.yaml b/translations/de.yaml index e07ee8624..ea77b0f04 100644 --- a/translations/de.yaml +++ b/translations/de.yaml @@ -215,3 +215,5 @@ caluma: complete: "Abschliessen" skip: "Überspringen" cancel: "Abbrechen" + success: "Der Status der Aufgabens wurde erfolgreich angepasst!" + error: "Hoppla, beim Speichern des Aufgabenstatus ist etwas schief gelaufen..." diff --git a/translations/en.yaml b/translations/en.yaml index 7c25404da..858ab2175 100644 --- a/translations/en.yaml +++ b/translations/en.yaml @@ -215,3 +215,5 @@ caluma: complete: "Complete" skip: "Skip" cancel: "Cancel" + success: "Work item state was successfully changed!" + error: "Ooops, something went wrong while changing the work item state..." diff --git a/translations/fr.yaml b/translations/fr.yaml index 9e98fe2c5..3df553e65 100644 --- a/translations/fr.yaml +++ b/translations/fr.yaml @@ -78,3 +78,5 @@ caluma: complete: "Terminer" skip: "Sauter" cancel: "Annuler" + success: "Succès!" + error: "Oups, quelque chose a mal ..."