diff --git a/packages/components/src/components/Actions/Actions.jsx b/packages/components/src/components/Actions/Actions.jsx index d1e447096..70b169e8e 100644 --- a/packages/components/src/components/Actions/Actions.jsx +++ b/packages/components/src/components/Actions/Actions.jsx @@ -11,8 +11,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Component } from 'react'; -import { injectIntl } from 'react-intl'; +import { useState } from 'react'; +import { useIntl } from 'react-intl'; import { Button, MenuButton, @@ -24,38 +24,53 @@ import { import Modal from '../Modal'; -class Actions extends Component { - state = { showDialog: false }; +export default function Actions({ items, kind, resource }) { + const intl = useIntl(); - handleModalAction = () => { - const { action } = this.state; - action(); - this.handleClose(); - }; + const [state, setState] = useState({ + action: undefined, + modal: {}, + showDialog: false + }); - handleClose = () => { - this.setState({ showDialog: false }); - }; + function handleClose() { + setState(prevState => ({ ...prevState, showDialog: false })); + } + + function handleModalAction() { + state.action(); + handleClose(); + } - handleClick = (action, modalProperties) => { + function handleClick(itemAction, modalProperties) { if (modalProperties) { - this.setState({ action, modal: modalProperties, showDialog: true }); + setState(prevState => ({ + ...prevState, + action: itemAction, + modal: modalProperties, + showDialog: true + })); } else { - action(); + itemAction(); } - }; + } - getButton() { - const { intl, items, kind, resource } = this.props; + function getButton() { const isButton = kind === 'button'; if (isButton && items.length === 1) { - const { action, actionText, icon, modalProperties } = items[0]; + const { + action: itemAction, + actionText, + danger, + icon, + modalProperties + } = items[0]; return ( - - + +