9s-fe-core
Version:
Core functionalities for authentication, configuration, and repository management.
61 lines (60 loc) • 3.77 kB
JavaScript
;
'use client';
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DetailModal = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const antd_1 = require("antd");
const template_utils_1 = require("../../utils/template_utils");
const react_1 = require("react");
const repository_1 = require("../../../repository");
const DetailModal = ({ isOpen, onClose, record, onActionClick, actionSchema, }) => {
const [detailData, setDetailData] = (0, react_1.useState)();
(0, react_1.useEffect)(() => {
if (!isOpen || !actionSchema || !record)
return;
const fetchData = () => __awaiter(void 0, void 0, void 0, function* () {
const requestFields = (0, template_utils_1.integrateFieldsWithData)(actionSchema.api.request_fields, record);
let payload = {};
requestFields.forEach(fieldItem => {
(0, template_utils_1.convertFieldToPayload)(fieldItem, payload);
});
const request = {
apiUrl: (0, template_utils_1.buildApiUrl)(actionSchema.api.path, record),
httpMethod: actionSchema.api.method,
type: actionSchema.api.type,
payload: payload
};
const result = yield repository_1.baseRepository.submitRequest(request);
if (result.status == 200) {
setDetailData(result.dataResponse);
}
else {
antd_1.message.error(result.message);
}
});
fetchData();
}, [isOpen]);
return ((0, jsx_runtime_1.jsxs)(antd_1.Modal, { visible: isOpen, title: "Chi ti\u1EBFt d\u1EEF li\u1EC7u", onCancel: onClose, footer: null, width: 1000, children: [detailData && ((0, jsx_runtime_1.jsx)(antd_1.Descriptions, { column: 1, bordered: true, size: "small", children: actionSchema === null || actionSchema === void 0 ? void 0 : actionSchema.response_fields.map(fieldItem => {
fieldItem.value = detailData === null || detailData === void 0 ? void 0 : detailData[fieldItem.key];
return ((0, jsx_runtime_1.jsx)(antd_1.Descriptions.Item, { label: fieldItem.label, children: (0, template_utils_1.renderFieldDisplayUI)(fieldItem, { showAllImage: true }) }, fieldItem.key));
}) })), detailData && ((0, jsx_runtime_1.jsx)("div", { style: { marginTop: '15px' }, children: actionSchema === null || actionSchema === void 0 ? void 0 : actionSchema.actions.map(action => {
return ((0, jsx_runtime_1.jsx)(antd_1.Button, { type: "primary", style: {
backgroundColor: 'green',
color: '#fff',
border: 'green',
padding: '4px 12px',
borderRadius: '4px',
cursor: 'pointer',
}, onClick: () => onActionClick(action, detailData), children: action.name }, action.action));
}) }, "actions"))] }));
};
exports.DetailModal = DetailModal;