@manuscripts/body-editor 2.7.7 → 2.7.8-LEAN-4213.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/cjs/components/affiliations/AffiliationForm.js +106 -0
- package/dist/cjs/components/affiliations/AffiliationItem.js +112 -0
- package/dist/cjs/components/affiliations/AffiliationList.js +47 -0
- package/dist/cjs/components/affiliations/AffiliationsModal.js +418 -0
- package/dist/cjs/components/authors/AuthorDetailsForm.js +10 -2
- package/dist/cjs/components/authors/AuthorList.js +1 -1
- package/dist/cjs/components/authors/AuthorsModal.js +184 -80
- package/dist/cjs/components/authors/DraggableAuthor.js +0 -3
- package/dist/cjs/components/dialog/ConfirmationDialog.js +86 -0
- package/dist/cjs/components/form/FormFooter.js +32 -0
- package/dist/cjs/components/form/FormPlaceholder.js +43 -0
- package/dist/cjs/components/{authors/AuthorActions.js → form/ModalFormActions.js} +12 -11
- package/dist/cjs/plugins/affiliations.js +5 -38
- package/dist/cjs/useEditor.js +0 -1
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/affiliations.js +82 -14
- package/dist/cjs/views/contributors.js +1 -9
- package/dist/es/components/affiliations/AffiliationForm.js +76 -0
- package/dist/es/components/affiliations/AffiliationItem.js +82 -0
- package/dist/es/components/affiliations/AffiliationList.js +40 -0
- package/dist/es/components/affiliations/AffiliationsModal.js +388 -0
- package/dist/es/components/authors/AuthorDetailsForm.js +11 -3
- package/dist/es/components/authors/AuthorList.js +1 -1
- package/dist/es/components/authors/AuthorsModal.js +183 -79
- package/dist/es/components/authors/DraggableAuthor.js +0 -3
- package/dist/es/components/dialog/ConfirmationDialog.js +79 -0
- package/dist/es/components/form/FormFooter.js +27 -0
- package/dist/es/components/form/FormPlaceholder.js +36 -0
- package/dist/es/components/{authors/AuthorActions.js → form/ModalFormActions.js} +10 -9
- package/dist/es/plugins/affiliations.js +6 -39
- package/dist/es/useEditor.js +0 -1
- package/dist/es/versions.js +1 -1
- package/dist/es/views/affiliations.js +85 -17
- package/dist/es/views/contributors.js +1 -9
- package/dist/types/components/{authors → affiliations}/AffiliationForm.d.ts +5 -0
- package/dist/types/components/affiliations/AffiliationItem.d.ts +10 -0
- package/dist/types/components/affiliations/AffiliationList.d.ts +26 -0
- package/dist/types/components/affiliations/AffiliationsModal.d.ts +11 -0
- package/dist/types/components/authors/AuthorDetailsForm.d.ts +1 -0
- package/dist/types/components/authors/AuthorsModal.d.ts +2 -1
- package/dist/types/components/dialog/ConfirmationDialog.d.ts +15 -0
- package/dist/types/components/form/FormFooter.d.ts +5 -0
- package/dist/types/components/form/FormPlaceholder.d.ts +9 -0
- package/dist/types/components/{authors/AuthorActions.d.ts → form/ModalFormActions.d.ts} +4 -3
- package/dist/types/lib/dnd.d.ts +1 -1
- package/dist/types/selection.d.ts +7 -1
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/affiliations.d.ts +11 -0
- package/dist/types/views/contributors.d.ts +0 -1
- package/package.json +2 -2
- package/styles/AdvancedEditor.css +8 -4
- package/styles/Editor.css +7 -0
- package/dist/cjs/components/authors/AffiliationButton.js +0 -104
- package/dist/cjs/components/authors/AffiliationForm.js +0 -50
- package/dist/cjs/components/authors/AuthorAffiliations.js +0 -120
- package/dist/cjs/components/authors/AuthorFormPlaceholder.js +0 -71
- package/dist/cjs/components/authors/DeleteAuthorConfirmationDialog.js +0 -36
- package/dist/cjs/components/authors/RequiredFieldConfirmationDialog.js +0 -39
- package/dist/cjs/components/authors/SaveAuthorConfirmationDialog.js +0 -39
- package/dist/es/components/authors/AffiliationButton.js +0 -74
- package/dist/es/components/authors/AffiliationForm.js +0 -43
- package/dist/es/components/authors/AuthorAffiliations.js +0 -89
- package/dist/es/components/authors/AuthorFormPlaceholder.js +0 -64
- package/dist/es/components/authors/DeleteAuthorConfirmationDialog.js +0 -29
- package/dist/es/components/authors/RequiredFieldConfirmationDialog.js +0 -32
- package/dist/es/components/authors/SaveAuthorConfirmationDialog.js +0 -32
- package/dist/types/components/authors/AffiliationButton.d.ts +0 -8
- package/dist/types/components/authors/AuthorAffiliations.d.ts +0 -11
- package/dist/types/components/authors/AuthorFormPlaceholder.d.ts +0 -2
- package/dist/types/components/authors/DeleteAuthorConfirmationDialog.d.ts +0 -7
- package/dist/types/components/authors/RequiredFieldConfirmationDialog.d.ts +0 -7
- package/dist/types/components/authors/SaveAuthorConfirmationDialog.d.ts +0 -7
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.AffiliationsModal = void 0;
|
|
30
|
+
const json_schema_1 = require("@manuscripts/json-schema");
|
|
31
|
+
const style_guide_1 = require("@manuscripts/style-guide");
|
|
32
|
+
const lodash_1 = require("lodash");
|
|
33
|
+
const react_1 = __importStar(require("react"));
|
|
34
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
35
|
+
const authors_1 = require("../../lib/authors");
|
|
36
|
+
const AuthorsModal_1 = require("../authors/AuthorsModal");
|
|
37
|
+
const ConfirmationDialog_1 = require("../dialog/ConfirmationDialog");
|
|
38
|
+
const FormFooter_1 = __importDefault(require("../form/FormFooter"));
|
|
39
|
+
const FormPlaceholder_1 = require("../form/FormPlaceholder");
|
|
40
|
+
const ModalFormActions_1 = require("../form/ModalFormActions");
|
|
41
|
+
const AffiliationForm_1 = require("./AffiliationForm");
|
|
42
|
+
const AffiliationList_1 = require("./AffiliationList");
|
|
43
|
+
const StyledSidebarContent = (0, styled_components_1.default)(style_guide_1.SidebarContent) `
|
|
44
|
+
padding: 0;
|
|
45
|
+
`;
|
|
46
|
+
const AddAffiliationButton = styled_components_1.default.div `
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
padding: 12px 8px 12px 12px;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
&[data-active='true'] {
|
|
52
|
+
background: ${(props) => props.theme.colors.background.fifth};
|
|
53
|
+
border: 1px solid ${(props) => props.theme.colors.border.primary};
|
|
54
|
+
border-left: 0;
|
|
55
|
+
border-right: 0;
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
const ActionTitle = styled_components_1.default.div `
|
|
59
|
+
padding-left: ${(props) => props.theme.grid.unit * 2}px;
|
|
60
|
+
`;
|
|
61
|
+
const AffiliationForms = styled_components_1.default.div `
|
|
62
|
+
padding-left: ${(props) => props.theme.grid.unit * 3}px;
|
|
63
|
+
padding-right: ${(props) => props.theme.grid.unit * 3}px;
|
|
64
|
+
position: relative;
|
|
65
|
+
margin-top: 20px;
|
|
66
|
+
`;
|
|
67
|
+
const AuthorsSection = styled_components_1.default.div `
|
|
68
|
+
margin-top: ${(props) => props.theme.grid.unit * 4}px;
|
|
69
|
+
padding-top: ${(props) => props.theme.grid.unit * 4}px;
|
|
70
|
+
border-top: 1px solid ${(props) => props.theme.colors.border.tertiary};
|
|
71
|
+
`;
|
|
72
|
+
const AuthorsHeader = styled_components_1.default.div `
|
|
73
|
+
display: flex;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
align-items: flex-start;
|
|
76
|
+
flex-direction: column;
|
|
77
|
+
margin-bottom: ${(props) => props.theme.grid.unit * 2}px;
|
|
78
|
+
`;
|
|
79
|
+
const AuthorsTitle = styled_components_1.default.h3 `
|
|
80
|
+
margin: 0;
|
|
81
|
+
font-weight: ${(props) => props.theme.font.weight.normal};
|
|
82
|
+
font-size: ${(props) => props.theme.font.size.large};
|
|
83
|
+
font-family: ${(props) => props.theme.font.family.sans};
|
|
84
|
+
color: ${(props) => props.theme.colors.text.secondary};
|
|
85
|
+
`;
|
|
86
|
+
const AffiliateButton = styled_components_1.default.button `
|
|
87
|
+
color: ${(props) => props.theme.colors.brand.default};
|
|
88
|
+
background: none;
|
|
89
|
+
border: none;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
padding: 0;
|
|
92
|
+
font: ${(props) => props.theme.font.weight.normal}
|
|
93
|
+
${(props) => props.theme.font.size.normal}
|
|
94
|
+
${(props) => props.theme.font.family.sans};
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: 4px;
|
|
98
|
+
margin-top: ${(props) => props.theme.grid.unit * 2}px;
|
|
99
|
+
&:hover {
|
|
100
|
+
opacity: 0.8;
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
const StyledModalBody = (0, styled_components_1.default)(style_guide_1.ModalBody) `
|
|
104
|
+
position: relative;
|
|
105
|
+
height: calc(90vh - 40px);
|
|
106
|
+
`;
|
|
107
|
+
const StyledModalSidebarHeader = (0, styled_components_1.default)(style_guide_1.ModalSidebarHeader) `
|
|
108
|
+
margin-top: 8px;
|
|
109
|
+
margin-bottom: 16px;
|
|
110
|
+
`;
|
|
111
|
+
const normalize = (affiliation) => ({
|
|
112
|
+
id: affiliation.id,
|
|
113
|
+
institution: affiliation.institution,
|
|
114
|
+
department: affiliation.department,
|
|
115
|
+
addressLine1: affiliation.addressLine1,
|
|
116
|
+
addressLine2: affiliation.addressLine2,
|
|
117
|
+
addressLine3: affiliation.addressLine3,
|
|
118
|
+
postCode: affiliation.postCode,
|
|
119
|
+
country: affiliation.country,
|
|
120
|
+
county: affiliation.county,
|
|
121
|
+
city: affiliation.city,
|
|
122
|
+
email: affiliation.email,
|
|
123
|
+
priority: affiliation.priority,
|
|
124
|
+
});
|
|
125
|
+
const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, onSaveAffiliation, onDeleteAffiliation, onUpdateAuthors, addNewAffiliation = false, }) => {
|
|
126
|
+
const [isOpen, setIsOpen] = (0, react_1.useState)(true);
|
|
127
|
+
const [selection, setSelection] = (0, react_1.useState)(undefined);
|
|
128
|
+
const [showDeleteDialog, setShowDeleteDialog] = (0, react_1.useState)(false);
|
|
129
|
+
const valuesRef = (0, react_1.useRef)();
|
|
130
|
+
const actionsRef = (0, react_1.useRef)();
|
|
131
|
+
const [authors, dispatchAuthors] = (0, react_1.useReducer)(AuthorsModal_1.authorsReducer, $authors.sort(authors_1.authorComparator));
|
|
132
|
+
const [affiliations, dispatchAffiliations] = (0, react_1.useReducer)(AuthorsModal_1.affiliationsReducer, $affiliations);
|
|
133
|
+
const [isDisableSave, setIsDisableSave] = (0, react_1.useState)(true);
|
|
134
|
+
const [newAffiliation, setNewAffiliation] = (0, react_1.useState)(false);
|
|
135
|
+
const [showRequiredFieldConfirmationDialog, setShowRequiredFieldConfirmationDialog,] = (0, react_1.useState)(false);
|
|
136
|
+
const [showConfirmationDialog, setShowConfirmationDialog] = (0, react_1.useState)(false);
|
|
137
|
+
const affiliation = {
|
|
138
|
+
id: (0, json_schema_1.generateID)(json_schema_1.ObjectTypes.Affiliation),
|
|
139
|
+
institution: '',
|
|
140
|
+
department: '',
|
|
141
|
+
addressLine1: '',
|
|
142
|
+
addressLine2: '',
|
|
143
|
+
addressLine3: '',
|
|
144
|
+
postCode: '',
|
|
145
|
+
country: '',
|
|
146
|
+
county: '',
|
|
147
|
+
city: '',
|
|
148
|
+
email: {
|
|
149
|
+
href: '',
|
|
150
|
+
text: '',
|
|
151
|
+
},
|
|
152
|
+
priority: affiliations.length,
|
|
153
|
+
};
|
|
154
|
+
const [showAuthorDrawer, setShowAuthorDrawer] = (0, react_1.useState)(false);
|
|
155
|
+
const [selectedIds, setSelectedIds] = (0, react_1.useState)([]);
|
|
156
|
+
const [pendingSelection, setPendingSelection] = (0, react_1.useState)(null);
|
|
157
|
+
const [pendingAction, setPendingAction] = (0, react_1.useState)(null);
|
|
158
|
+
const [savedAffiliationId, setSavedAffiliationId] = (0, react_1.useState)(undefined);
|
|
159
|
+
const [affiliationAuthorMap, setAffiliationAuthorMap] = (0, react_1.useState)({});
|
|
160
|
+
const handleClose = () => {
|
|
161
|
+
var _a;
|
|
162
|
+
const values = valuesRef.current;
|
|
163
|
+
const hasAffiliationChanges = selection && !(0, lodash_1.isEqual)(values, normalize(selection));
|
|
164
|
+
const originalAuthors = affiliationAuthorMap[(selection === null || selection === void 0 ? void 0 : selection.id) || ''] || [];
|
|
165
|
+
const hasAuthorChanges = !(0, lodash_1.isEqual)(originalAuthors.sort(), selectedIds.sort());
|
|
166
|
+
const hasChanges = hasAffiliationChanges || (selection && hasAuthorChanges);
|
|
167
|
+
const isInstitutionEmpty = ((_a = values === null || values === void 0 ? void 0 : values.institution) === null || _a === void 0 ? void 0 : _a.trim()) === '';
|
|
168
|
+
if (hasChanges) {
|
|
169
|
+
if (isInstitutionEmpty && hasAffiliationChanges) {
|
|
170
|
+
setShowRequiredFieldConfirmationDialog(true);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
setShowConfirmationDialog(true);
|
|
174
|
+
}
|
|
175
|
+
setPendingAction('close');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
setIsOpen(false);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const handleSelect = (affiliation) => {
|
|
182
|
+
var _a;
|
|
183
|
+
const values = valuesRef.current;
|
|
184
|
+
const hasAffiliationChanges = selection && !(0, lodash_1.isEqual)(values, normalize(selection));
|
|
185
|
+
const originalAuthors = affiliationAuthorMap[(selection === null || selection === void 0 ? void 0 : selection.id) || ''] || [];
|
|
186
|
+
const hasAuthorChanges = !(0, lodash_1.isEqual)(originalAuthors.sort(), selectedIds.sort());
|
|
187
|
+
const hasChanges = hasAffiliationChanges || hasAuthorChanges;
|
|
188
|
+
const isInstitutionEmpty = ((_a = values === null || values === void 0 ? void 0 : values.institution) === null || _a === void 0 ? void 0 : _a.trim()) === '';
|
|
189
|
+
if (hasChanges) {
|
|
190
|
+
setPendingSelection(affiliation);
|
|
191
|
+
setPendingAction('select');
|
|
192
|
+
if (isInstitutionEmpty && hasAffiliationChanges) {
|
|
193
|
+
setShowRequiredFieldConfirmationDialog(true);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
setShowConfirmationDialog(true);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const affiliatedAuthorIds = authors
|
|
201
|
+
.filter((author) => { var _a; return (_a = author.affiliations) === null || _a === void 0 ? void 0 : _a.includes(affiliation.id); })
|
|
202
|
+
.map((author) => author.id);
|
|
203
|
+
setNewAffiliation(false);
|
|
204
|
+
setSelection(affiliation);
|
|
205
|
+
setSelectedIds(affiliatedAuthorIds);
|
|
206
|
+
setShowAuthorDrawer(false);
|
|
207
|
+
setAffiliationAuthorMap((prevMap) => (Object.assign(Object.assign({}, prevMap), { [affiliation.id]: affiliatedAuthorIds })));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const handleSaveAffiliation = (values) => {
|
|
211
|
+
if (!values || !selection) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
setIsDisableSave(true);
|
|
215
|
+
const affiliation = Object.assign(Object.assign({}, normalize(selection)), values);
|
|
216
|
+
onSaveAffiliation(affiliation);
|
|
217
|
+
dispatchAffiliations({
|
|
218
|
+
type: 'update',
|
|
219
|
+
items: [affiliation],
|
|
220
|
+
});
|
|
221
|
+
setSelection(affiliation);
|
|
222
|
+
const updatedAuthors = authors.map((author) => (Object.assign(Object.assign({}, author), { affiliations: selectedIds.includes(author.id)
|
|
223
|
+
? [...new Set([...(author.affiliations || []), affiliation.id])]
|
|
224
|
+
: (author.affiliations || []).filter((id) => id !== affiliation.id) })));
|
|
225
|
+
dispatchAuthors({
|
|
226
|
+
type: 'update',
|
|
227
|
+
items: updatedAuthors,
|
|
228
|
+
});
|
|
229
|
+
onUpdateAuthors(updatedAuthors);
|
|
230
|
+
setNewAffiliation(false);
|
|
231
|
+
setAffiliationAuthorMap((prevMap) => (Object.assign(Object.assign({}, prevMap), { [affiliation.id]: selectedIds })));
|
|
232
|
+
setShowAuthorDrawer(false);
|
|
233
|
+
setSavedAffiliationId(affiliation.id);
|
|
234
|
+
setTimeout(() => {
|
|
235
|
+
setSavedAffiliationId(undefined);
|
|
236
|
+
}, 3200);
|
|
237
|
+
};
|
|
238
|
+
const handleAffiliationChange = (values) => {
|
|
239
|
+
var _a;
|
|
240
|
+
valuesRef.current = values;
|
|
241
|
+
if (!selection || selection.id !== values.id) {
|
|
242
|
+
setIsDisableSave(true);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const isInstitutionEmpty = !((_a = values.institution) === null || _a === void 0 ? void 0 : _a.trim());
|
|
246
|
+
const hasAffiliationChanges = selection && !(0, lodash_1.isEqual)(normalize(values), normalize(selection));
|
|
247
|
+
const originalAuthors = affiliationAuthorMap[(selection === null || selection === void 0 ? void 0 : selection.id) || ''] || [];
|
|
248
|
+
const hasAuthorChanges = selection && !(0, lodash_1.isEqual)(originalAuthors.sort(), selectedIds.sort());
|
|
249
|
+
const shouldEnableSave = !isInstitutionEmpty && (hasAffiliationChanges || hasAuthorChanges);
|
|
250
|
+
setIsDisableSave(!shouldEnableSave);
|
|
251
|
+
};
|
|
252
|
+
const handleShowDeleteDialog = () => {
|
|
253
|
+
setShowDeleteDialog((prev) => !prev);
|
|
254
|
+
};
|
|
255
|
+
const handleDeleteAffiliation = () => {
|
|
256
|
+
if (!selection) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const updatedAuthors = authors.map((author) => (Object.assign(Object.assign({}, author), { affiliations: (author.affiliations || []).filter((id) => id !== selection.id) })));
|
|
260
|
+
dispatchAuthors({
|
|
261
|
+
type: 'update',
|
|
262
|
+
items: updatedAuthors,
|
|
263
|
+
});
|
|
264
|
+
onUpdateAuthors(updatedAuthors);
|
|
265
|
+
onDeleteAffiliation(selection);
|
|
266
|
+
dispatchAffiliations({
|
|
267
|
+
type: 'delete',
|
|
268
|
+
item: selection,
|
|
269
|
+
});
|
|
270
|
+
setSelectedIds([]);
|
|
271
|
+
setSelection(undefined);
|
|
272
|
+
};
|
|
273
|
+
const handleAuthorSelect = (authorId) => {
|
|
274
|
+
var _a, _b;
|
|
275
|
+
if (!selection) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const newSelectedAuthorIds = selectedIds.includes(authorId)
|
|
279
|
+
? selectedIds.filter((id) => id !== authorId)
|
|
280
|
+
: [...selectedIds, authorId];
|
|
281
|
+
setSelectedIds(newSelectedAuthorIds);
|
|
282
|
+
const hasAffiliationChanges = !(0, lodash_1.isEqual)(valuesRef.current, normalize(selection));
|
|
283
|
+
const originalAuthors = affiliationAuthorMap[selection.id] || [];
|
|
284
|
+
const hasAuthorChanges = !(0, lodash_1.isEqual)(originalAuthors.sort(), newSelectedAuthorIds.sort());
|
|
285
|
+
const isInstitutionEmpty = !((_b = (_a = valuesRef.current) === null || _a === void 0 ? void 0 : _a.institution) === null || _b === void 0 ? void 0 : _b.trim());
|
|
286
|
+
const shouldEnableSave = !isInstitutionEmpty && (hasAffiliationChanges || hasAuthorChanges);
|
|
287
|
+
setIsDisableSave(!shouldEnableSave);
|
|
288
|
+
};
|
|
289
|
+
const authorItems = authors.map((author) => ({
|
|
290
|
+
id: author.id,
|
|
291
|
+
label: `${author.bibliographicName.given} ${author.bibliographicName.family}`,
|
|
292
|
+
}));
|
|
293
|
+
const selectedAuthors = selectedIds
|
|
294
|
+
.map((authorId) => {
|
|
295
|
+
const author = authors.find((a) => a.id === authorId);
|
|
296
|
+
return {
|
|
297
|
+
id: authorId,
|
|
298
|
+
label: author
|
|
299
|
+
? `${author.bibliographicName.given} ${author.bibliographicName.family}`
|
|
300
|
+
: '',
|
|
301
|
+
};
|
|
302
|
+
})
|
|
303
|
+
.filter((author) => author.label);
|
|
304
|
+
const handleAddAffiliation = () => {
|
|
305
|
+
var _a;
|
|
306
|
+
const values = valuesRef.current;
|
|
307
|
+
const hasChanges = !isDisableSave;
|
|
308
|
+
const isInstitutionEmpty = ((_a = values === null || values === void 0 ? void 0 : values.institution) === null || _a === void 0 ? void 0 : _a.trim()) === '';
|
|
309
|
+
if (hasChanges) {
|
|
310
|
+
setPendingAction('new');
|
|
311
|
+
if (isInstitutionEmpty) {
|
|
312
|
+
setShowRequiredFieldConfirmationDialog(true);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
setShowConfirmationDialog(true);
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
setNewAffiliation(true);
|
|
320
|
+
setSelection(affiliation);
|
|
321
|
+
setSelectedIds([]);
|
|
322
|
+
setShowAuthorDrawer(false);
|
|
323
|
+
};
|
|
324
|
+
(0, react_1.useEffect)(() => {
|
|
325
|
+
if (addNewAffiliation) {
|
|
326
|
+
handleAddAffiliation();
|
|
327
|
+
setNewAffiliation(true);
|
|
328
|
+
}
|
|
329
|
+
}, [addNewAffiliation]);
|
|
330
|
+
const handleConfirmationSave = () => {
|
|
331
|
+
handleSaveAffiliation(valuesRef.current);
|
|
332
|
+
setShowConfirmationDialog(false);
|
|
333
|
+
setShowRequiredFieldConfirmationDialog(false);
|
|
334
|
+
if (pendingAction === 'new') {
|
|
335
|
+
setNewAffiliation(true);
|
|
336
|
+
setSelection(affiliation);
|
|
337
|
+
setSelectedIds([]);
|
|
338
|
+
setIsDisableSave(true);
|
|
339
|
+
}
|
|
340
|
+
else if (pendingAction === 'select' && pendingSelection) {
|
|
341
|
+
setSelection(pendingSelection);
|
|
342
|
+
setNewAffiliation(false);
|
|
343
|
+
const affiliatedAuthorIds = authors
|
|
344
|
+
.filter((author) => { var _a; return (_a = author.affiliations) === null || _a === void 0 ? void 0 : _a.some((aff) => aff === pendingSelection.id); })
|
|
345
|
+
.map((author) => author.id);
|
|
346
|
+
setSelectedIds(affiliatedAuthorIds);
|
|
347
|
+
valuesRef.current = normalize(pendingSelection);
|
|
348
|
+
setIsDisableSave(true);
|
|
349
|
+
setAffiliationAuthorMap((prevMap) => (Object.assign(Object.assign({}, prevMap), { [pendingSelection.id]: affiliatedAuthorIds })));
|
|
350
|
+
}
|
|
351
|
+
setPendingSelection(null);
|
|
352
|
+
setPendingAction(null);
|
|
353
|
+
if (pendingAction === 'close') {
|
|
354
|
+
setIsOpen(false);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const handleConfirmationCancel = () => {
|
|
358
|
+
setShowConfirmationDialog(false);
|
|
359
|
+
setShowRequiredFieldConfirmationDialog(false);
|
|
360
|
+
setShowAuthorDrawer(false);
|
|
361
|
+
if (pendingAction === 'select' && pendingSelection) {
|
|
362
|
+
setSelection(pendingSelection);
|
|
363
|
+
setNewAffiliation(false);
|
|
364
|
+
const affiliatedAuthorIds = authors
|
|
365
|
+
.filter((author) => { var _a; return (_a = author.affiliations) === null || _a === void 0 ? void 0 : _a.some((aff) => aff === pendingSelection.id); })
|
|
366
|
+
.map((author) => author.id);
|
|
367
|
+
setSelectedIds(affiliatedAuthorIds);
|
|
368
|
+
}
|
|
369
|
+
else if (pendingAction === 'new') {
|
|
370
|
+
setNewAffiliation(true);
|
|
371
|
+
setSelection(affiliation);
|
|
372
|
+
setSelectedIds([]);
|
|
373
|
+
}
|
|
374
|
+
if (pendingSelection) {
|
|
375
|
+
valuesRef.current = normalize(pendingSelection);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
valuesRef.current = undefined;
|
|
379
|
+
}
|
|
380
|
+
setPendingSelection(null);
|
|
381
|
+
setPendingAction(null);
|
|
382
|
+
if (pendingAction === 'close') {
|
|
383
|
+
setIsOpen(false);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
return (react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: () => handleClose(), shouldCloseOnOverlayClick: true },
|
|
387
|
+
react_1.default.createElement(style_guide_1.ModalContainer, null,
|
|
388
|
+
react_1.default.createElement(style_guide_1.ModalHeader, null,
|
|
389
|
+
react_1.default.createElement(style_guide_1.CloseButton, { onClick: () => handleClose(), "data-cy": "modal-close-button" })),
|
|
390
|
+
react_1.default.createElement(StyledModalBody, null,
|
|
391
|
+
react_1.default.createElement(style_guide_1.ModalSidebar, null,
|
|
392
|
+
react_1.default.createElement(StyledModalSidebarHeader, null,
|
|
393
|
+
react_1.default.createElement(style_guide_1.ModalSidebarTitle, null, "Affiliations")),
|
|
394
|
+
react_1.default.createElement(StyledSidebarContent, null,
|
|
395
|
+
react_1.default.createElement(AddAffiliationButton, { "data-cy": "add-affiliation-button", onClick: handleAddAffiliation, "data-active": newAffiliation },
|
|
396
|
+
react_1.default.createElement(style_guide_1.AddIcon, { width: 18, height: 18 }),
|
|
397
|
+
react_1.default.createElement(ActionTitle, null, "New Affiliation")),
|
|
398
|
+
react_1.default.createElement(AffiliationList_1.AffiliationList, { affiliation: selection, affiliations: affiliations, onSelect: handleSelect, onDelete: handleShowDeleteDialog, lastSavedAffiliationId: savedAffiliationId }))),
|
|
399
|
+
react_1.default.createElement(style_guide_1.ScrollableModalContent, { "data-cy": "affiliations-modal-content" },
|
|
400
|
+
react_1.default.createElement(AffiliationForms, null,
|
|
401
|
+
selection ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
402
|
+
react_1.default.createElement(ModalFormActions_1.ModalFormActions, { type: 'affiliation', onSave: () => handleSaveAffiliation(valuesRef.current), onDelete: handleDeleteAffiliation, showDeleteDialog: showDeleteDialog, handleShowDeleteDialog: handleShowDeleteDialog, newEntity: newAffiliation, isDisableSave: isDisableSave }),
|
|
403
|
+
react_1.default.createElement(AffiliationForm_1.AffiliationForm, { values: normalize(selection), onSave: handleSaveAffiliation, onChange: handleAffiliationChange, actionsRef: actionsRef }),
|
|
404
|
+
react_1.default.createElement(ConfirmationDialog_1.ConfirmationDialog, { isOpen: showRequiredFieldConfirmationDialog, onPrimary: () => setShowRequiredFieldConfirmationDialog(false), onSecondary: handleConfirmationCancel, type: ConfirmationDialog_1.DialogType.REQUIRED, entityType: "affiliation" }),
|
|
405
|
+
react_1.default.createElement(ConfirmationDialog_1.ConfirmationDialog, { isOpen: showConfirmationDialog, onPrimary: handleConfirmationSave, onSecondary: handleConfirmationCancel, type: ConfirmationDialog_1.DialogType.SAVE, entityType: "affiliation" }),
|
|
406
|
+
react_1.default.createElement(AuthorsSection, null,
|
|
407
|
+
react_1.default.createElement(AuthorsHeader, null,
|
|
408
|
+
react_1.default.createElement(AuthorsTitle, null, "Authors"),
|
|
409
|
+
react_1.default.createElement(AffiliateButton, { onClick: () => setShowAuthorDrawer(true), "data-cy": "affiliate-authors-button" },
|
|
410
|
+
react_1.default.createElement(style_guide_1.AddUserIcon, { width: 16, height: 16 }),
|
|
411
|
+
"Affiliate Authors")),
|
|
412
|
+
react_1.default.createElement(style_guide_1.SelectedItemsBox, { items: selectedAuthors, onRemove: (id) => {
|
|
413
|
+
setSelectedIds((prev) => prev.filter((authorId) => authorId !== id));
|
|
414
|
+
}, placeholder: "No authors assigned" })))) : (react_1.default.createElement(FormPlaceholder_1.FormPlaceholder, { type: "affiliation", title: 'Affiliation Details', message: "Select an affiliation from the list to display it's details here.", placeholderIcon: react_1.default.createElement(style_guide_1.AffiliationPlaceholderIcon, null) })),
|
|
415
|
+
showAuthorDrawer && (react_1.default.createElement(style_guide_1.Drawer, { items: authorItems, selectedIds: selectedIds, title: "Authors", onSelect: handleAuthorSelect, onBack: () => setShowAuthorDrawer(false), width: "100%" }))))),
|
|
416
|
+
react_1.default.createElement(FormFooter_1.default, { onCancel: handleClose }))));
|
|
417
|
+
};
|
|
418
|
+
exports.AffiliationsModal = AffiliationsModal;
|
|
@@ -75,8 +75,13 @@ const CheckboxContainer = styled_components_1.default.div `
|
|
|
75
75
|
align-items: center;
|
|
76
76
|
gap: 32px;
|
|
77
77
|
`;
|
|
78
|
-
const AuthorDetailsForm = ({ values, onChange, onSave, actionsRef, isEmailRequired, }) => {
|
|
78
|
+
const AuthorDetailsForm = ({ values, onChange, onSave, actionsRef, isEmailRequired, selectedAffiliations, }) => {
|
|
79
79
|
const formRef = (0, react_1.useRef)(null);
|
|
80
|
+
(0, react_1.useEffect)(() => {
|
|
81
|
+
if (selectedAffiliations && formRef.current) {
|
|
82
|
+
formRef.current.setFieldValue('affiliations', selectedAffiliations);
|
|
83
|
+
}
|
|
84
|
+
}, [selectedAffiliations]);
|
|
80
85
|
if (actionsRef && !actionsRef.current) {
|
|
81
86
|
actionsRef.current = {
|
|
82
87
|
reset: () => {
|
|
@@ -110,7 +115,10 @@ const AuthorDetailsForm = ({ values, onChange, onSave, actionsRef, isEmailRequir
|
|
|
110
115
|
react_1.default.createElement(OrcidContainer, null,
|
|
111
116
|
react_1.default.createElement(style_guide_1.TextFieldLabel, null,
|
|
112
117
|
react_1.default.createElement(exports.LabelText, null, "ORCID"),
|
|
113
|
-
react_1.default.createElement(formik_1.Field, { name: 'ORCIDIdentifier', type: 'text' }, (props) => (react_1.default.createElement(style_guide_1.TextField, Object.assign({ id: 'orcid', placeholder: 'https://orcid.org/...' }, props.field))))))
|
|
118
|
+
react_1.default.createElement(formik_1.Field, { name: 'ORCIDIdentifier', type: 'text' }, (props) => (react_1.default.createElement(style_guide_1.TextField, Object.assign({ id: 'orcid', placeholder: 'https://orcid.org/...' }, props.field)))))),
|
|
119
|
+
react_1.default.createElement(formik_1.Field, { name: "affiliations", type: "hidden" }, (props) => {
|
|
120
|
+
return (react_1.default.createElement(style_guide_1.TextField, Object.assign({ type: "hidden" }, props.field, { value: selectedAffiliations || [] })));
|
|
121
|
+
}))));
|
|
114
122
|
}));
|
|
115
123
|
};
|
|
116
124
|
exports.AuthorDetailsForm = AuthorDetailsForm;
|
|
@@ -34,7 +34,7 @@ const AuthorListTitle = styled_components_1.default.h2 `
|
|
|
34
34
|
font-weight: 400;
|
|
35
35
|
line-height: 24px;
|
|
36
36
|
margin-left: 14px;
|
|
37
|
-
margin-top:
|
|
37
|
+
margin-top: 20px;
|
|
38
38
|
`;
|
|
39
39
|
const AuthorList = ({ author, authors, onSelect, onDelete, moveAuthor, lastSavedAuthor, }) => {
|
|
40
40
|
return (react_1.default.createElement(react_dnd_1.DndProvider, { backend: react_dnd_html5_backend_1.HTML5Backend },
|