diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js index b487daa..618ef17 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js @@ -6,6 +6,7 @@ * under the terms of the MIT License; see LICENSE file for more details. */ +import { NotificationContext } from "@js/invenio_administration"; import { BoolFormatter } from "@js/invenio_administration"; import { i18next } from "@translations/invenio_app_rdm/i18next"; import PropTypes from "prop-types"; @@ -18,6 +19,18 @@ import { http } from "react-invenio-forms"; import { StatusFormatter } from "./StatusFormatter"; class SearchResultItemComponent extends Component { + static contextType = NotificationContext; + + onError = (e) => { + const { addNotification } = this.context; + addNotification({ + title: i18next.t("Error"), + content: e.message, + type: "error", + }); + console.error(e); + }; + render() { const { result } = this.props; @@ -105,7 +118,7 @@ class SearchResultItemComponent extends Component { Run now - {/* */} + {/* */} ); diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js index 1fd4ea6..587e49b 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js @@ -6,7 +6,8 @@ import { i18next } from "@translations/invenio_app_rdm/i18next"; import PropTypes from "prop-types"; -import React from "react"; +import React, { useState } from "react"; +import { http } from "react-invenio-forms"; import { Button, Dropdown, @@ -14,12 +15,24 @@ import { Form, FormInput, } from "semantic-ui-react"; -import { http } from "react-invenio-forms"; -export const RunButton = ({ jobId, config }) => { +export const RunButton = ({ jobId, config, onError }) => { + const [loading, setLoading] = useState(false); + + const handleClick = async () => { + setLoading(true); + try { + await http.post("/api/jobs/" + jobId + "/runs"); + setLoading(false); + } catch (error) { + setLoading(false); + onError(error); + } + }; + return ( {