passbolt-styleguide
Version:
Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.
106 lines (95 loc) • 2.88 kB
JavaScript
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) 2023 Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2023 Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.1.0
*/
import React from "react";
import PropTypes from "prop-types";
import { Trans, withTranslation } from "react-i18next";
import { withActionFeedback } from "../../../../contexts/ActionFeedbackContext";
import { withAdminRbac } from "../../../../contexts/Administration/AdministrationRbacContext/AdministrationRbacContext";
class DisplayAdministrationRbacActions extends React.Component {
/**
* Constructor
* @param {Object} props
*/
constructor(props) {
super(props);
this.bindCallbacks();
}
/**
* Bind callbacks methods
*/
bindCallbacks() {
this.handleSaveClick = this.handleSaveClick.bind(this);
}
/**
* Handle save settings
*/
async handleSaveClick() {
try {
await this.props.adminRbacContext.save();
this.handleSaveSuccess();
} catch (error) {
this.handleSaveError(error);
}
}
/**
* Is save button enable
* @returns {boolean}
*/
isSaveEnabled() {
return !this.props.adminRbacContext.isProcessing();
}
/**
* Handle save operation success.
*/
async handleSaveSuccess() {
await this.props.actionFeedbackContext.displaySuccess(
this.props.t("The role-based access control settings were updated."),
);
}
/**
* Handle save operation error.
* @param {object} error The returned error
*/
async handleSaveError(error) {
console.error(error);
await this.props.actionFeedbackContext.displayError(error.message);
}
/**
* Render the component
* @returns {JSX}
*/
render() {
return (
<div className="actions-wrapper">
<button
className="button primary form"
type="button"
disabled={!this.isSaveEnabled()}
onClick={this.handleSaveClick}
>
<span>
<Trans>Save</Trans>
</span>
</button>
</div>
);
}
}
DisplayAdministrationRbacActions.propTypes = {
context: PropTypes.object, // The application context
adminRbacContext: PropTypes.object, // The administration rbac context
actionFeedbackContext: PropTypes.object, // The action feedback context
t: PropTypes.func, // The translation function
};
export default withAdminRbac(withActionFeedback(withTranslation("common")(DisplayAdministrationRbacActions)));