@esvndev/es-data-sharing 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var jsxRuntime = require('react/jsx-runtime');
4
6
  var react = require('react');
5
- var reactstrap = require('reactstrap');
6
7
  var reactI18next = require('react-i18next');
8
+ var reactstrap = require('reactstrap');
7
9
  var esGridTemplate = require('es-grid-template');
8
10
  var becoxyIcons = require('becoxy-icons');
9
11
 
@@ -86,28 +88,44 @@ var classnames$1 = {exports: {}};
86
88
 
87
89
  var classnames = classnames$1.exports;
88
90
 
89
- const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared }) => {
90
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center mb-3", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: title })] }), jsxRuntime.jsx("div", { className: "master-fields-list", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "mb-2 row align-items-center", children: [jsxRuntime.jsxs("label", { className: "col-5 text-muted small mb-0", children: [f.label, ":"] }), jsxRuntime.jsx("div", { className: "col-7 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: "Danh m\u1EE5c d\u00F9ng chung to\u00E0n t\u1EADp \u0111o\u00E0n" }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: "T\u1EF1 \u0111\u1ED9ng c\u1EA5p quy\u1EC1n s\u1EED d\u1EE5ng cho t\u1EA5t c\u1EA3 \u0111\u01A1n v\u1ECB th\u00E0nh vi\u00EAn" })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
91
+ const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
92
+ const { t } = reactI18next.useTranslation();
93
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) })] }), jsxRuntime.jsx("div", { className: "master-fields-list flex-grow-1", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "row mx-0 align-items-center es-master-field-row", children: [jsxRuntime.jsxs("label", { className: "col-5 ps-0 text-muted small mb-0", children: [t(f.label), ":"] }), jsxRuntime.jsx("div", { className: "col-7 pe-0 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) }), showGlobalSharedSwitch && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
91
94
  };
92
95
 
93
- const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared }) => {
96
+ const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
94
97
  const { t } = reactI18next.useTranslation();
95
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between mb-2", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "border rounded bg-white p-2", style: { maxHeight: '215px', overflowY: 'auto' }, children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
98
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between es-master-header", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "p-2 flex-grow-1 es-batch-items-list", children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), showGlobalSharedSwitch && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
96
99
  };
97
100
 
98
- const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
99
- const { t } = reactI18next.useTranslation();
101
+ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
102
+ const { t, i18n } = reactI18next.useTranslation();
100
103
  const [search, setSearch] = react.useState('');
101
104
  const [filterType, setFilterType] = react.useState('ALL');
102
- const filtered = orgList.filter(o => {
105
+ const filtered = react.useMemo(() => orgList.filter(o => {
103
106
  const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
104
107
  o.orgCode.toLowerCase().includes(search.toLowerCase());
105
108
  const matchType = filterType === 'ALL' || o.orgType === filterType;
106
109
  return matchSearch && matchType;
107
- });
110
+ }), [orgList, search, filterType]);
111
+ const gridDataSource = react.useMemo(() => filtered.map(o => ({
112
+ ...o,
113
+ rowId: o.targetOrgId,
114
+ statusText: o.isSelected
115
+ ? t('DataSharing_Sharing', 'Đang chia sẻ')
116
+ : t('DataSharing_NotShared', 'Chưa chia sẻ')
117
+ })), [filtered, t]);
108
118
  const selectedCount = orgList.filter(o => o.isSelected).length;
109
119
  const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
110
120
  const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
121
+ const resolvedParentOrg = react.useMemo(() => {
122
+ if (parentOrgName)
123
+ return parentOrgName;
124
+ const rootOrg = orgList.find(o => !o.parentId);
125
+ if (!rootOrg)
126
+ return '';
127
+ return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
128
+ }, [parentOrgName, orgList]);
111
129
  const handleToggleSelectAll = (checked) => {
112
130
  const filteredIds = new Set(filtered.map(f => f.targetOrgId));
113
131
  const next = orgList.map(item => {
@@ -144,9 +162,115 @@ const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
144
162
  const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
145
163
  onChangeOrg(next);
146
164
  };
147
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), selectedCount > 0 && (jsxRuntime.jsxs("div", { className: "d-flex justify-content-end gap-2 mb-2", children: [jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(true), children: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng') }), jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "secondary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(false), children: t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc') })] })), jsxRuntime.jsx("div", { className: "table-responsive border rounded", style: { maxHeight: '235px' }, children: jsxRuntime.jsxs(reactstrap.Table, { size: "sm", hover: true, className: "align-middle mb-0", children: [jsxRuntime.jsx("thead", { className: "table-light sticky-top", children: jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("th", { style: { width: 42 }, className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", title: t('DataSharing_SelectAll', 'Chọn tất cả'), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) }), jsxRuntime.jsx("th", { children: t('DataSharing_Organization', 'Đơn vị') }), jsxRuntime.jsx("th", { style: { width: 90 }, children: t('DataSharing_OrgType', 'Loại') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 105 }, children: t('DataSharing_InheritMaster', 'Kế thừa gốc') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 120 }, children: t('DataSharing_CanOverride', 'Cấu hình riêng') }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveFrom', 'Hiệu lực từ') }), jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveTo', 'Hiệu lực đến') })] })), jsxRuntime.jsx("th", { style: { width: 110 }, children: t('DataSharing_Status', 'Trạng thái') })] }) }), jsxRuntime.jsx("tbody", { children: filtered.length === 0 ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: showEffectiveDate ? 8 : 6, className: "text-center text-muted py-3", children: t('DataSharing_NoOrgFound', 'Không tìm thấy đơn vị phù hợp') }) })) : (filtered.map(row => (jsxRuntime.jsxs("tr", { className: row.isSelected ? 'table-primary bg-opacity-10' : '', children: [jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: row.isSelected, onChange: e => handleSelectRow(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsxs("td", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: row.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", row.orgCode, ")"] })] }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Badge, { color: row.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: row.orgType === 'Công ty'
148
- ? t('DataSharing_Company', 'Công ty')
149
- : t('DataSharing_Branch', 'Chi nhánh') }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: row.isInheritMaster, onChange: e => handleFieldChange(row.targetOrgId, 'isInheritMaster', e.target.checked) }) }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !row.isSelected, checked: row.canOverrideConfig, onChange: e => handleFieldChange(row.targetOrgId, 'canOverrideConfig', e.target.checked) }) }) }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveFrom ? String(row.effectiveFrom).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveFrom', e.target.value || null) }) }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveTo ? String(row.effectiveTo).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveTo', e.target.value || null) }) })] })), jsxRuntime.jsx("td", { children: row.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') })) })] }, row.targetOrgId)))) })] }) })] }) }));
165
+ const handleCellChange = (args, handleCallback) => {
166
+ const item = args.rowData;
167
+ const field = args.field;
168
+ if (field === 'effectiveFrom' || field === 'effectiveTo') {
169
+ const rawVal = item?.[field];
170
+ const normalized = rawVal ? String(rawVal).substring(0, 10) : null;
171
+ handleFieldChange(item.targetOrgId, field, normalized);
172
+ }
173
+ handleCallback(item, args.indexRow);
174
+ };
175
+ const headerColumns = react.useMemo(() => [
176
+ {
177
+ field: 'isSelected',
178
+ headerText: '',
179
+ width: 50,
180
+ minWidth: 50,
181
+ maxWidth: 50,
182
+ textAlign: 'center',
183
+ fixedType: 'left',
184
+ allowFiltering: false,
185
+ allowSortering: false,
186
+ allowResizing: false,
187
+ editEnable: false,
188
+ headerTemplate: () => (jsxRuntime.jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", title: String(t('DataSharing_SelectAll', 'Chọn tất cả')), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) })),
189
+ template: (props) => (jsxRuntime.jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: Boolean(props.rowData?.isSelected), onChange: e => handleSelectRow(props.rowData?.targetOrgId, e.target.checked) }) }))
190
+ },
191
+ {
192
+ field: 'orgName',
193
+ headerText: String(t('DataSharing_Organization', 'Đơn vị')),
194
+ headerTooltip: String(t('DataSharing_Organization', 'Đơn vị')),
195
+ width: 260,
196
+ minWidth: 160,
197
+ fixedType: 'left',
198
+ editEnable: false,
199
+ template: (props) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", props.rowData?.orgCode, ")"] })] }))
200
+ },
201
+ {
202
+ field: 'orgType',
203
+ headerText: String(t('DataSharing_OrgType', 'Loại')),
204
+ headerTooltip: String(t('DataSharing_OrgType', 'Loại')),
205
+ width: 110,
206
+ minWidth: 95,
207
+ textAlign: 'center',
208
+ visible: false,
209
+ editEnable: false,
210
+ template: (props) => (jsxRuntime.jsx(reactstrap.Badge, { color: props.rowData?.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: props.rowData?.orgType === 'Công ty'
211
+ ? t('DataSharing_Company', 'Công ty')
212
+ : t('DataSharing_Branch', 'Chi nhánh') }))
213
+ },
214
+ {
215
+ field: 'isInheritMaster',
216
+ headerText: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
217
+ headerTooltip: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
218
+ width: 115,
219
+ minWidth: 100,
220
+ textAlign: 'center',
221
+ visible: false,
222
+ allowFiltering: false,
223
+ editEnable: false,
224
+ template: (props) => (jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: Boolean(props.rowData?.isInheritMaster), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'isInheritMaster', e.target.checked) }) }))
225
+ },
226
+ {
227
+ field: 'canOverrideConfig',
228
+ headerText: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
229
+ headerTooltip: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
230
+ width: 125,
231
+ minWidth: 110,
232
+ textAlign: 'center',
233
+ allowFiltering: false,
234
+ editEnable: false,
235
+ template: (props) => (jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !props.rowData?.isSelected, checked: Boolean(props.rowData?.canOverrideConfig), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'canOverrideConfig', e.target.checked) }) }))
236
+ },
237
+ {
238
+ field: 'effectiveFrom',
239
+ headerText: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
240
+ headerTooltip: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
241
+ type: 'date',
242
+ editType: 'date',
243
+ textAlign: 'center',
244
+ visible: false,
245
+ width: 145,
246
+ minWidth: 120,
247
+ editEnable: (rowData) => Boolean(rowData?.isSelected)
248
+ },
249
+ {
250
+ field: 'effectiveTo',
251
+ headerText: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
252
+ headerTooltip: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
253
+ type: 'date',
254
+ editType: 'date',
255
+ textAlign: 'center',
256
+ visible: false,
257
+ width: 145,
258
+ minWidth: 120,
259
+ editEnable: (rowData) => Boolean(rowData?.isSelected)
260
+ },
261
+ {
262
+ field: 'statusText',
263
+ headerText: String(t('DataSharing_Status', 'Trạng thái')),
264
+ headerTooltip: String(t('DataSharing_Status', 'Trạng thái')),
265
+ width: 125,
266
+ minWidth: 105,
267
+ textAlign: 'center',
268
+ visible: false,
269
+ editEnable: false,
270
+ template: (props) => props.rowData?.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') }))
271
+ }
272
+ ], [allFilteredSelected, orgList, filtered, t]);
273
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), (resolvedParentOrg || selectedCount > 0) && (jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center gap-2 mb-2", children: [jsxRuntime.jsx("div", { children: resolvedParentOrg && (jsxRuntime.jsxs("div", { className: "es-parent-org-pill", children: [jsxRuntime.jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxRuntime.jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] })) }), selectedCount > 0 && (jsxRuntime.jsxs("div", { className: "d-flex gap-2 ms-auto", children: [jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(true), children: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng') }), jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "secondary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(false), children: t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc') })] }))] })), jsxRuntime.jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(115, 103, 240, 0.06)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
150
274
  };
151
275
 
152
276
  function resolveFieldDisplayValue(field, rowData, rawVal) {
@@ -309,11 +433,11 @@ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride,
309
433
  }
310
434
  handleCallback(item, args.indexRow);
311
435
  };
312
- return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: onApplyFirstToAll, children: ["\uD83D\uDCCB ", t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác')] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, allowResizing: true, t: t, format: {
313
- decimalSeparator: '.',
314
- thousandSeparator: ',',
315
- decimalScale: 0
316
- }, showEmptyText: false }, "DataSharingOverrideGrid")), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 text-muted small p-1 bg-light rounded", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
436
+ return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: onApplyFirstToAll, children: ["\uD83D\uDCCB ", t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác')] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx("div", { className: "es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
437
+ decimalSeparator: '.',
438
+ thousandSeparator: ',',
439
+ decimalScale: 0
440
+ }, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 es-override-note", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
317
441
  };
318
442
 
319
443
  const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
@@ -469,83 +593,149 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
469
593
  emitUpdatedRows(item?.rows ?? []);
470
594
  }
471
595
  };
472
- return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, allowResizing: true, t: t, format: {
596
+ return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, height: 280, allowResizing: true, t: t, format: {
473
597
  decimalSeparator: '.',
474
598
  thousandSeparator: ',',
475
599
  decimalScale: 2
476
600
  }, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
477
601
  };
478
602
 
479
- const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false }) => {
603
+ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, setOrgList, detailData, setDetailData, isGlobalShared, onToggleGlobalShared, onChangeOverride, onApplyFirstToAll, showMasterCard: propShowMasterCard, showOrgScope: propShowOrgScope, showConfigTabs: propShowConfigTabs, showOverrideTab: propShowOverrideTab, showSummaryTab: propShowSummaryTab, showGlobalSharedSwitch: propShowGlobalSharedSwitch }) => {
480
604
  const { t } = reactI18next.useTranslation();
481
- const [activeTab, setActiveTab] = react.useState('override');
482
- const [saving, setSaving] = react.useState(false);
605
+ const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
606
+ const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
607
+ const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
608
+ const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
609
+ const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
610
+ const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
611
+ const detailTabs = config.detailTabs ?? [];
612
+ const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
613
+ const getFirstVisibleTab = () => {
614
+ if (showOverrideTab)
615
+ return 'override';
616
+ if (detailTabs.length > 0)
617
+ return `detail:${detailTabs[0].key}`;
618
+ return 'summary';
619
+ };
620
+ const [activeTab, setActiveTab] = react.useState(getFirstVisibleTab);
621
+ react.useEffect(() => {
622
+ const validTabs = [];
623
+ if (showOverrideTab)
624
+ validTabs.push('override');
625
+ detailTabs.forEach(tab => validTabs.push(`detail:${tab.key}`));
626
+ if (showSummaryTab)
627
+ validTabs.push('summary');
628
+ if (validTabs.length > 0 && !validTabs.includes(activeTab)) {
629
+ setActiveTab(validTabs[0]);
630
+ }
631
+ }, [showOverrideTab, showSummaryTab, detailTabs, activeTab]);
632
+ const selectedOrgs = orgList.filter(o => o.isSelected);
633
+ const showTopRow = showMasterCard || showOrgScope;
634
+ const masterColMd = showOrgScope ? 5 : 12;
635
+ const orgColMd = showMasterCard ? 7 : 12;
636
+ return (jsxRuntime.jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxRuntime.jsxs(reactstrap.Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsxRuntime.jsx(reactstrap.Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsxRuntime.jsx(reactstrap.Col, { md: orgColMd, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), hasVisibleTabs && (jsxRuntime.jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
637
+ const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
638
+ return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
639
+ }), showSummaryTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) }))] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns ?? [], masterData: isBatchMode ? undefined : masterData, onChangeOverride: onChangeOverride, onApplyFirstToAll: onApplyFirstToAll }) })), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
640
+ ...prev,
641
+ [tab.key]: updatedRows
642
+ })) }) }, tab.key))), showSummaryTab && (jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "es-data-sharing-summary-box", children: [jsxRuntime.jsx("div", { className: "fw-bold mb-2 small text-dark", children: t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng') }), jsxRuntime.jsxs("div", { className: "es-summary-grid", children: [jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryScope', 'Phạm vi') }), jsxRuntime.jsx("div", { className: "es-summary-value", children: isGlobalShared
643
+ ? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
644
+ : `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng') }), jsxRuntime.jsx("div", { className: "es-summary-value", children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t(tab.title) }), jsxRuntime.jsx("div", { className: "es-summary-value", children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) }))] })] }))] }));
645
+ };
646
+
647
+ function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
648
+ if (!checked)
649
+ return orgList;
650
+ return orgList.map(o => ({
651
+ ...o,
652
+ isSelected: true,
653
+ status: 1,
654
+ statusText: sharingLabel
655
+ }));
656
+ }
657
+ function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
658
+ return orgList.map(item => {
659
+ if (item.targetOrgId !== targetOrgId)
660
+ return item;
661
+ return {
662
+ ...item,
663
+ overrideData: {
664
+ ...item.overrideData,
665
+ [fieldKey]: value
666
+ }
667
+ };
668
+ });
669
+ }
670
+ function applyFirstOverrideToAll(orgList) {
671
+ const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
672
+ if (editableOrgs.length < 2)
673
+ return orgList;
674
+ const firstData = editableOrgs[0].overrideData ?? {};
675
+ return orgList.map(item => {
676
+ if (!item.isSelected || !item.canOverrideConfig)
677
+ return item;
678
+ return {
679
+ ...item,
680
+ overrideData: {
681
+ ...firstData
682
+ }
683
+ };
684
+ });
685
+ }
686
+ function buildDataSharingPayload(params) {
687
+ const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
483
688
  const isBatchMode = (entityIds?.length ?? 0) > 1;
484
689
  const detailTabs = config.detailTabs ?? [];
690
+ return {
691
+ entityType: config.entityType,
692
+ entityId,
693
+ ...(isBatchMode ? { entityIds } : {}),
694
+ isGlobalShared,
695
+ sharingList: orgList.map(o => ({
696
+ TargetOrgId: o.targetOrgId,
697
+ IsInheritMaster: o.isInheritMaster,
698
+ CanOverrideConfig: o.canOverrideConfig,
699
+ EffectiveFrom: o.effectiveFrom || null,
700
+ EffectiveTo: o.effectiveTo || null,
701
+ Status: o.isSelected ? 1 : 0
702
+ })),
703
+ orgConfigList: orgList
704
+ .filter(o => o.isSelected && o.canOverrideConfig)
705
+ .map(o => ({
706
+ OrganizationId: o.targetOrgId,
707
+ ...o.overrideData
708
+ })),
709
+ ...(detailTabs.length > 0 ? { detailData } : {})
710
+ };
711
+ }
712
+
713
+ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
714
+ const { t } = reactI18next.useTranslation();
715
+ const [saving, setSaving] = react.useState(false);
716
+ const isBatchMode = (entityIds?.length ?? 0) > 1;
485
717
  const handleToggleGlobalShared = (checked) => {
486
718
  setIsGlobalShared(checked);
487
- if (checked) {
488
- setOrgList(prev => prev.map(o => ({
489
- ...o,
490
- isSelected: true,
491
- status: 1,
492
- statusText: t('DataSharing_Sharing', 'Đang chia sẻ')
493
- })));
494
- }
719
+ const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
720
+ setOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
495
721
  };
496
722
  const handleChangeOverride = (targetOrgId, fieldKey, value) => {
497
- setOrgList(prev => prev.map(item => {
498
- if (item.targetOrgId !== targetOrgId)
499
- return item;
500
- return {
501
- ...item,
502
- overrideData: {
503
- ...item.overrideData,
504
- [fieldKey]: value
505
- }
506
- };
507
- }));
723
+ setOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
508
724
  };
509
725
  const handleApplyFirstToAll = () => {
510
- const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
511
- if (editableOrgs.length < 2)
512
- return;
513
- const firstData = editableOrgs[0].overrideData ?? {};
514
- setOrgList(prev => prev.map(item => {
515
- if (!item.isSelected || !item.canOverrideConfig)
516
- return item;
517
- return {
518
- ...item,
519
- overrideData: {
520
- ...firstData
521
- }
522
- };
523
- }));
726
+ setOrgList(prev => applyFirstOverrideToAll(prev));
524
727
  };
525
728
  const handleSubmit = async () => {
526
729
  setSaving(true);
527
730
  try {
528
- const payload = {
529
- entityType: config.entityType,
731
+ const payload = buildDataSharingPayload({
732
+ config,
530
733
  entityId,
531
- ...(isBatchMode ? { entityIds } : {}),
734
+ entityIds,
532
735
  isGlobalShared,
533
- sharingList: orgList.map(o => ({
534
- TargetOrgId: o.targetOrgId,
535
- IsInheritMaster: o.isInheritMaster,
536
- CanOverrideConfig: o.canOverrideConfig,
537
- EffectiveFrom: o.effectiveFrom || null,
538
- EffectiveTo: o.effectiveTo || null,
539
- Status: o.isSelected ? 1 : 0
540
- })),
541
- orgConfigList: orgList
542
- .filter(o => o.isSelected && o.canOverrideConfig)
543
- .map(o => ({
544
- OrganizationId: o.targetOrgId,
545
- ...o.overrideData
546
- })),
547
- ...(detailTabs.length > 0 ? { detailData } : {})
548
- };
736
+ orgList,
737
+ detailData
738
+ });
549
739
  await onSave(payload);
550
740
  toggle();
551
741
  }
@@ -553,30 +743,41 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
553
743
  setSaving(false);
554
744
  }
555
745
  };
556
- const selectedOrgs = orgList.filter(o => o.isSelected);
557
- return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, className: "border-bottom pb-2", children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 fs-4", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { className: "p-3", children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(reactstrap.Row, { className: "mb-3", children: [jsxRuntime.jsx(reactstrap.Col, { md: 5, className: "mb-2 mb-md-0", children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle, fields: config.masterFields, data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) }), jsxRuntime.jsx(reactstrap.Col, { md: 7, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, showEffectiveDate: config.showEffectiveDate }) })] }), jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) }), detailTabs.map(tab => {
558
- const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
559
- return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
560
- }), jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) })] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns, masterData: isBatchMode ? undefined : masterData, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll }) }), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
561
- ...prev,
562
- [tab.key]: updatedRows
563
- })) }) }, tab.key))), jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "border rounded p-3 small", children: [jsxRuntime.jsxs("div", { className: "fw-bold mb-2", children: [t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng'), ":"] }), jsxRuntime.jsxs("ul", { className: "mb-0 ps-3", children: [jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryScope', 'Phạm vi'), ":", ' ', jsxRuntime.jsx("strong", { children: isGlobalShared
564
- ? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
565
- : `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng'), ":", ' ', jsxRuntime.jsx("strong", { children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("li", { children: [t(tab.title), ":", ' ', jsxRuntime.jsx("strong", { children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) })] })] })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { className: "border-top pt-2", children: [jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') }), jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') })] })] }));
746
+ return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { children: [jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
566
747
  };
567
748
 
568
- const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onSave, onSuccess }, ref) => {
749
+ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
750
+ const { t } = reactI18next.useTranslation();
751
+ const [internalDetailData, setInternalDetailData] = react.useState({});
752
+ const detailData = controlledDetailData ?? internalDetailData;
753
+ const setDetailData = onChangeDetailData ?? setInternalDetailData;
754
+ const handleToggleGlobalShared = (checked) => {
755
+ onChangeGlobalShared?.(checked);
756
+ const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
757
+ onChangeOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
758
+ };
759
+ const handleChangeOverride = (targetOrgId, fieldKey, value) => {
760
+ onChangeOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
761
+ };
762
+ const handleApplyFirstToAll = () => {
763
+ onChangeOrgList(prev => applyFirstOverrideToAll(prev));
764
+ };
765
+ return (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch }));
766
+ };
767
+ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }, ref) => {
569
768
  const [isOpen, setIsOpen] = react.useState(false);
570
769
  const [loading, setLoading] = react.useState(false);
571
770
  const [config, setConfig] = react.useState(null);
572
771
  const [masterData, setMasterData] = react.useState({});
573
772
  const [masterDataList, setMasterDataList] = react.useState([]);
773
+ const [activeParentOrgName, setActiveParentOrgName] = react.useState(parentOrgName);
574
774
  const [entityId, setEntityId] = react.useState('');
575
775
  const [entityIds, setEntityIds] = react.useState(undefined);
576
776
  const [activeDatabase, setActiveDatabase] = react.useState(database);
577
777
  const [isGlobalShared, setIsGlobalShared] = react.useState(false);
578
778
  const [orgList, setOrgList] = react.useState([]);
579
779
  const [detailData, setDetailData] = react.useState({});
780
+ const [openVisibility, setOpenVisibility] = react.useState({});
580
781
  react.useImperativeHandle(ref, () => ({
581
782
  open: async (params) => {
582
783
  const targetDb = params.database ?? database;
@@ -587,15 +788,27 @@ const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onS
587
788
  setConfig(params.config);
588
789
  setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
589
790
  setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
791
+ setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
590
792
  setEntityId(primaryEntityId);
591
793
  setEntityIds(isBatch ? ids : undefined);
592
794
  setActiveDatabase(targetDb);
593
795
  setIsGlobalShared(params.initialGlobalShared || false);
594
796
  setDetailData(params.initialDetailData ?? {});
797
+ setOpenVisibility({
798
+ showMasterCard: params.showMasterCard,
799
+ showOrgScope: params.showOrgScope,
800
+ showConfigTabs: params.showConfigTabs,
801
+ showOverrideTab: params.showOverrideTab,
802
+ showSummaryTab: params.showSummaryTab,
803
+ showGlobalSharedSwitch: params.showGlobalSharedSwitch
804
+ });
595
805
  if (fetchSharingData && primaryEntityId) {
596
806
  setLoading(true);
597
807
  try {
598
808
  const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
809
+ if (res.parentOrgName) {
810
+ setActiveParentOrgName(res.parentOrgName);
811
+ }
599
812
  if (isBatch) {
600
813
  // In batch mode, load org tree cleanly without inheriting single-item selections
601
814
  setIsGlobalShared(false);
@@ -637,8 +850,15 @@ const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onS
637
850
  onSuccess();
638
851
  }
639
852
  };
640
- return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading }));
853
+ return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab, showGlobalSharedSwitch: openVisibility.showGlobalSharedSwitch ?? showGlobalSharedSwitch }));
641
854
  });
642
855
 
643
- module.exports = DataSharingComponent;
856
+ exports.BatchMasterCard = BatchMasterCard;
857
+ exports.DataSharingPanel = DataSharingPanel;
858
+ exports.DetailTabTable = DetailTabTable;
859
+ exports.MasterCard = MasterCard;
860
+ exports.OrgTable = OrgTable;
861
+ exports.OverrideTable = OverrideTable;
862
+ exports.buildDataSharingPayload = buildDataSharingPayload;
863
+ exports["default"] = DataSharingComponent;
644
864
  //# sourceMappingURL=index.js.map