decentraland-ui
Version:
Decentraland's UI components and styles
129 lines (128 loc) • 7.4 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeedbackModal = exports.TransactionStatus = void 0;
var React = __importStar(require("react"));
var ModalContent_1 = __importDefault(require("semantic-ui-react/dist/commonjs/modules/Modal/ModalContent"));
var Icon_1 = __importDefault(require("semantic-ui-react/dist/commonjs/elements/Icon"));
var classnames_1 = __importDefault(require("classnames"));
var Modal_1 = require("../Modal/Modal");
var ModalNavigation_1 = require("../ModalNavigation/ModalNavigation");
var Loader_1 = require("../Loader/Loader");
var Button_1 = require("../Button/Button");
require("./FeedbackModal.css");
var TransactionStatus;
(function (TransactionStatus) {
TransactionStatus["PENDING"] = "pending";
TransactionStatus["SUCCESS"] = "success";
TransactionStatus["FAILURE"] = "failure";
})(TransactionStatus = exports.TransactionStatus || (exports.TransactionStatus = {}));
var iconNames = (_a = {},
_a[TransactionStatus.PENDING] = 'clock outline',
_a[TransactionStatus.FAILURE] = 'warning circle',
_a);
var FeedbackModal = /** @class */ (function (_super) {
__extends(FeedbackModal, _super);
function FeedbackModal() {
return _super !== null && _super.apply(this, arguments) || this;
}
FeedbackModal.prototype.renderActions = function () {
var _a = this.props, i18n = _a.i18n, status = _a.status, goToUrl = _a.goToUrl, transactionUrl = _a.transactionUrl, onClickCta = _a.onClickCta, onClickSecondaryCta = _a.onClickSecondaryCta, onClose = _a.onClose;
switch (status) {
case TransactionStatus.SUCCESS:
return (React.createElement(React.Fragment, null,
React.createElement(Button_1.Button, { primary: true, onClick: onClickCta || onClose }, i18n.cta),
transactionUrl ? (React.createElement("a", { className: "view-transaction", href: transactionUrl, target: "_blank", rel: "noopener noreferrer" },
i18n.viewTransaction,
React.createElement(Icon_1.default, { name: "external alternate" }))) : null));
case TransactionStatus.PENDING:
return (React.createElement(React.Fragment, null,
React.createElement(Loader_1.Loader, { size: "medium", active: true }, goToUrl ? (React.createElement("a", { href: goToUrl, className: "go-to", target: "_blank", rel: "external" }, i18n === null || i18n === void 0 ? void 0 : i18n.goToText)) : null)));
case TransactionStatus.FAILURE:
return (React.createElement(React.Fragment, null,
React.createElement(Button_1.Button, { primary: true, onClick: onClickCta }, i18n.cta),
React.createElement(Button_1.Button, { secondary: true, onClick: onClickSecondaryCta }, i18n.secondaryCta)));
default:
break;
}
};
FeedbackModal.prototype.renderStatusTitle = function () {
var _a = this.props, i18n = _a.i18n, status = _a.status;
var iconName = iconNames[status];
if (status === TransactionStatus.SUCCESS)
return null;
return i18n.statusTitle ? (React.createElement("p", { className: "status-description" },
iconName ? React.createElement(Icon_1.default, { name: iconName, className: "status-icon" }) : null,
i18n.statusTitle)) : null;
};
FeedbackModal.prototype.render = function () {
var _a = this.props, open = _a.open, className = _a.className, message = _a.message, i18n = _a.i18n, hasError = _a.hasError, loading = _a.loading, status = _a.status, selectedGateway = _a.selectedGateway, onClose = _a.onClose, onInfo = _a.onInfo;
return (React.createElement(Modal_1.Modal, { open: open, className: (0, classnames_1.default)('dcl', 'feedback-modal', className, status) },
React.createElement(ModalNavigation_1.ModalNavigation, { title: i18n.title, onInfo: onInfo, onClose: onClose }),
React.createElement(ModalContent_1.default, null,
React.createElement("img", { className: (0, classnames_1.default)('gateway-image', status === TransactionStatus.SUCCESS ? 'stars' : selectedGateway) }),
React.createElement("div", { className: "text-content" },
this.renderStatusTitle(),
React.createElement("p", { className: "description" }, i18n.description),
message ? React.createElement("small", { className: "message" }, message) : null)),
hasError ? React.createElement("p", { className: "error visible" }, i18n.error) : null,
loading ? (React.createElement(React.Fragment, null,
React.createElement(Loader_1.Loader, { size: "big", active: true }),
React.createElement("div", { className: "loader-background" }))) : null,
React.createElement(Modal_1.Modal.Actions, null, this.renderActions())));
};
FeedbackModal.defaultProps = {
className: '',
hasError: false,
loading: false,
i18n: {
title: 'Awesome',
description: 'The MANA has been added to your account. If you still don’t see it in your balance, refresh this page.',
cta: 'Done',
viewTransaction: 'View Transaction in Exporer'
}
};
return FeedbackModal;
}(React.Component));
exports.FeedbackModal = FeedbackModal;