forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathevent-form.js
More file actions
2477 lines (2324 loc) · 84 KB
/
Copy pathevent-form.js
File metadata and controls
2477 lines (2324 loc) · 84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2017 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* */
import React from "react";
import T from "i18n-react/dist/i18n-react";
import "awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css";
import Swal from "sweetalert2";
import moment from "moment-timezone";
import { Tooltip } from "react-tooltip";
import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods";
import Dropdown from "openstack-uicore-foundation/lib/components/inputs/dropdown";
import GroupedDropdown from "openstack-uicore-foundation/lib/components/inputs/grouped-dropdown";
import DateTimePicker from "openstack-uicore-foundation/lib/components/inputs/datetimepicker";
import TagInput from "openstack-uicore-foundation/lib/components/inputs/tag-input";
import SpeakerInput from "openstack-uicore-foundation/lib/components/inputs/speaker-input";
import CompanyInput from "openstack-uicore-foundation/lib/components/inputs/company-input";
import GroupInput from "openstack-uicore-foundation/lib/components/inputs/group-input";
import UploadInput from "openstack-uicore-foundation/lib/components/inputs/upload-input";
import Input from "openstack-uicore-foundation/lib/components/inputs/text-input";
import Panel from "openstack-uicore-foundation/lib/components/sections/panel";
import Table from "openstack-uicore-foundation/lib/components/table";
import MemberInput from "openstack-uicore-foundation/lib/components/inputs/member-input";
import FreeTextSearch from "openstack-uicore-foundation/lib/components/free-text-search";
import TicketTypesInput from "openstack-uicore-foundation/lib/components/inputs/ticket-types-input";
import SortableTable from "openstack-uicore-foundation/lib/components/table-sortable";
import TextEditorV3 from "openstack-uicore-foundation/lib/components/inputs/editor-input-v3";
import { Pagination } from "react-bootstrap";
import ExtraQuestionsForm from "openstack-uicore-foundation/lib/components/extra-questions";
import QuestionsSet from "openstack-uicore-foundation/lib/utils/questions-set";
import {
isEmpty,
scrollToError,
shallowEqual,
hasErrors,
adjustEventDuration,
isValidUrl
} from "../../utils/methods";
import ProgressFlags from "../inputs/ProgressFlags";
import {
ATTENDEES_EXPECTED_LEARNT,
ATTENDING_MEDIA,
LEVEL,
SOCIAL_DESCRIPTION
} from "../../actions/event-actions";
import AuditLogs from "../audit-logs";
import {
DECIMAL_DIGITS,
DELTA_SECS,
DEFAULT_REOPEN_HOURS,
EVENT_TYPE_FISHBOWL,
EVENT_TYPE_GROUP_EVENTS,
EVENT_TYPE_PRESENTATION,
MILLISECONDS_TO_SECONDS,
ONE_MINUTE,
REOPEN_PRESET_HOURS_48,
REOPEN_PRESET_HOURS_72,
RSVP_TYPE_NONE,
RSVP_TYPE_PRIVATE,
RSVP_TYPE_PUBLIC
} from "../../utils/constants";
import CopyClipboard from "../buttons/copy-clipboard";
import EventRsvpList from "../rsvp/event-rsvp-list";
import EventRsvpInvitationList from "../rsvp/event-rsvp-invitation-list";
import showConfirmDialog from "../mui/showConfirmDialog";
const REOPEN_DEADLINE_FORMAT = "MMMM DD, YYYY h:mm a";
class EventForm extends React.Component {
constructor(props) {
super(props);
this.state = {
speakerToAdd: null,
entity: { ...props.entity },
showSection: "main",
errors: props.errors,
publish: false,
commentFilters: { ...props.commentState.filters },
reopenHours: DEFAULT_REOPEN_HOURS,
reopenCustomHours: ""
};
this.formRef = React.createRef();
this.handleChange = this.handleChange.bind(this);
this.handleQAuserChange = this.handleQAuserChange.bind(this);
this.handleTimeChange = this.handleTimeChange.bind(this);
this.handleUploadFile = this.handleUploadFile.bind(this);
this.handleRemoveFile = this.handleRemoveFile.bind(this);
this.handleMaterialEdit = this.handleMaterialEdit.bind(this);
this.handleNewMaterial = this.handleNewMaterial.bind(this);
this.handleUploadPic = this.handleUploadPic.bind(this);
this.handleMaterialDownload = this.handleMaterialDownload.bind(this);
this.handleMaterialDelete = this.handleMaterialDelete.bind(this);
this.getQAUsersOptionLabel = this.getQAUsersOptionLabel.bind(this);
this.handleFeedbackExport = this.handleFeedbackExport.bind(this);
this.handleFeedbackPageChange = this.handleFeedbackPageChange.bind(this);
this.handleFeedbackSort = this.handleFeedbackSort.bind(this);
this.handleFeedbackSearch = this.handleFeedbackSearch.bind(this);
this.handleDeleteEventFeedback = this.handleDeleteEventFeedback.bind(this);
this.handleChangeSelectionPlan = this.handleChangeSelectionPlan.bind(this);
this.handleChangeExtraQuestion = this.handleChangeExtraQuestion.bind(this);
this.triggerFormSubmit = this.triggerFormSubmit.bind(this);
this.handleUnpublish = this.handleUnpublish.bind(this);
this.isQuestionAllowed = this.isQuestionAllowed.bind(this);
this.getPopupScores = this.getPopupScores.bind(this);
this.handleTrackChairCommentEdit =
this.handleTrackChairCommentEdit.bind(this);
this.handleTrackChairCommentDelete =
this.handleTrackChairCommentDelete.bind(this);
this.handleTrackChairCommentSearch =
this.handleTrackChairCommentSearch.bind(this);
this.handleTrackChairCommentPageChange =
this.handleTrackChairCommentPageChange.bind(this);
this.handleTrackChairCommentSort =
this.handleTrackChairCommentSort.bind(this);
this.handleTrackChairFilterChange =
this.handleTrackChairFilterChange.bind(this);
this.handleSelectSpeakerToAdd = this.handleSelectSpeakerToAdd.bind(this);
this.handleSpeakerUnassign = this.handleSpeakerUnassign.bind(this);
this.handleSpeakerAssign = this.handleSpeakerAssign.bind(this);
this.handleSpeakerEdit = this.handleSpeakerEdit.bind(this);
this.handleSpeakersReordering = this.handleSpeakersReordering.bind(this);
this.handleCloneEvent = this.handleCloneEvent.bind(this);
this.handleEventTypeChange = this.handleEventTypeChange.bind(this);
this.handleRSVPTypeChange = this.handleRSVPTypeChange.bind(this);
this.handleSaveIncomplete = this.handleSaveIncomplete.bind(this);
this.handleReopenSubmission = this.handleReopenSubmission.bind(this);
this.handleCloseSubmission = this.handleCloseSubmission.bind(this);
}
componentDidMount() {
const { entity } = this.state;
const { feedbackState, commentState, getEventFeedback, getEventComments } =
this.props;
if (entity.id > 0) {
if (entity.allow_feedback) {
getEventFeedback(
entity.id,
feedbackState.term,
feedbackState.page,
feedbackState.perPage,
feedbackState.order,
feedbackState.orderDir
);
}
getEventComments(
entity.id,
commentState.term,
commentState.page,
commentState.perPage,
commentState.order,
commentState.orderDir
);
}
}
componentDidUpdate(prevProps) {
const { errors, entity } = this.props;
const newState = {};
scrollToError(errors);
if (!shallowEqual(prevProps.entity, entity)) {
newState.entity = { ...entity };
newState.errors = {};
}
if (!shallowEqual(prevProps.errors, errors)) {
newState.errors = { ...errors };
}
if (!isEmpty(newState)) {
this.setState((prevState) => ({ ...prevState, ...newState }));
}
}
handleChange(ev) {
const { entity, errors } = this.state;
const newEntity = { ...entity };
const newErrors = { ...errors };
let { value, id } = ev.target;
if (ev.target.type === "radio") {
id = ev.target.name;
value = ev.target.value === 1;
}
if (ev.target.type === "checkbox") {
value = ev.target.checked;
}
if (ev.target.type === "datetime") {
value = value.valueOf() / MILLISECONDS_TO_SECONDS;
}
newErrors[id] = "";
newEntity[id] = value;
this.setState({ entity: newEntity }, () => {
if (id === "type_id" && entity.id)
this.handleEventTypeChange(entity, newEntity);
});
}
handleRSVPTypeChange(ev) {
const { entity } = this.state;
const { onUpdate } = this.props;
const newEntity = { ...entity };
const { value, id } = ev.target;
newEntity[id] = value;
this.setState({ entity: newEntity }, () => {
if (newEntity.id) onUpdate({ [id]: value });
});
}
handleQAuserChange(ev) {
const { errors, entity } = this.state;
const newEntity = { ...entity };
const newErrors = { ...errors };
const { onAddQAMember, onDeleteQAMember, currentSummit } = this.props;
let { value, id } = ev.target;
let currentError = "";
const oldHelpUsers = newEntity[id];
const currentOldOnes = [];
try {
// remap to chat api payload format
const newHelpUsers = value.map((member) => {
if (member.hasOwnProperty("email")) {
// if has email property then its cames from main api
// we need to remap but first only users with idp id set
// are valid
if (!member.user_external_id) {
throw new Error("Invalid user");
}
const newMember = {
member_id: member.id,
idp_user_id: member.user_external_id,
full_name: `${member.first_name} ${member.last_name}`,
summit_event_id: newEntity.id,
summit_id: currentSummit.id
};
onAddQAMember(newMember, newEntity.id);
return newMember;
}
currentOldOnes.push(member);
return member;
});
// check if we delete something
if (oldHelpUsers.length !== currentOldOnes.length) {
// get missing one
const missingOne = oldHelpUsers.filter((oldOne) => {
const matches = currentOldOnes.filter(
(newOne) => newOne.member_id === oldOne.member_id
);
return matches.length === 0;
});
if (missingOne.length > 0) {
// remove it
onDeleteQAMember(missingOne[0], newEntity.id);
}
}
value = newHelpUsers;
} catch (e) {
console.log(e);
value = oldHelpUsers;
currentError = e;
}
newErrors[id] = currentError;
newEntity[id] = value;
this.setState({ entity: newEntity, errors: newErrors });
}
handleTimeChange(ev) {
const { errors, entity } = this.state;
const { id } = ev.target;
let newEntity = { ...entity };
const newErrors = { ...errors };
newErrors[id] = "";
newEntity = adjustEventDuration(ev, entity);
this.setState({ entity: newEntity, errors: newErrors });
}
handleUploadFile(file) {
const { onAttach } = this.props;
const { entity } = this.state;
const newEntity = { ...entity };
newEntity.attachment = file.preview;
this.setState({ entity: newEntity });
const formData = new FormData();
formData.append("file", file);
onAttach(newEntity, formData, "file");
}
handleRemoveFile(attr) {
const { onRemoveImage } = this.props;
const { entity } = this.state;
const newEntity = { ...entity };
newEntity[attr] = "";
if (attr === "image") {
onRemoveImage(newEntity.id);
}
this.setState({ entity: newEntity });
}
handleCloneEvent(ev) {
ev.preventDefault();
const { entity } = this.state;
const { onClone } = this.props;
Swal.fire({
title: T.translate("general.are_you_sure"),
text: `${T.translate("edit_event.clone_event")} "${entity.title}"`,
type: "warning",
showCancelButton: true,
confirmButtonText: T.translate("general.yes")
}).then((result) => {
if (result.value) {
onClone(entity);
}
});
}
async handleChangeSelectionPlan(ev) {
const {
currentSummit,
selectionPlansOpts,
fetchExtraQuestions,
fetchExtraQuestionsAnswers
} = this.props;
const { errors, entity } = this.state;
const newEntity = { ...entity };
const { value, id } = ev.target;
let extraQuestions = [];
let extraQuestionsAnswers = [];
let newSelectionPlan = null;
if (value) {
extraQuestions = await fetchExtraQuestions(currentSummit.id, value);
newSelectionPlan = selectionPlansOpts.find((sp) => sp.id === value);
newSelectionPlan.extra_questions = extraQuestions;
if (newEntity?.id) {
extraQuestionsAnswers = await fetchExtraQuestionsAnswers(
currentSummit.id,
value,
newEntity.id
);
}
}
errors[id] = "";
newEntity.selection_plan_id = value;
newEntity.selection_plan = newSelectionPlan;
newEntity.extra_questions = extraQuestionsAnswers;
this.setState({ entity: newEntity });
}
handleChangeExtraQuestion(formValues) {
const { entity } = this.state;
const { onSubmit } = this.props;
const qs = new QuestionsSet(entity?.selection_plan?.extra_questions || {});
const formattedAnswers = [];
Object.keys(formValues).map((name) => {
const question = qs.getQuestionByName(name);
const newQuestion = {
question_id: question.id,
value: `${formValues[name]}`
};
formattedAnswers.push(newQuestion);
});
const { publish } = this.state;
this.setState(
(prevState) => ({
...prevState,
entity: { ...prevState.entity, extra_questions: formattedAnswers },
publish: false
}),
() => {
onSubmit(entity, publish);
}
);
}
handleUnpublish(ev) {
const { onUnpublish } = this.props;
const { entity } = this.state;
ev.preventDefault();
onUnpublish(entity);
}
handleScheduleLink(ev) {
const { entity } = this.state;
const { currentSummit, history } = this.props;
ev.preventDefault();
const start_date = epochToMomentTimeZone(
entity.start_date,
currentSummit.time_zone_id
).format("YYYY-MM-DD");
const { location_id } = entity;
const event_id = entity.id;
history.push(
`/app/summits/${currentSummit.id}/events/schedule#location_id=${location_id}&day=${start_date}&event=${event_id}`
);
}
handleEventLink(ev) {
const { entity } = this.state;
const { currentSummit } = this.props;
ev.preventDefault();
const eventStart = epochToMomentTimeZone(
entity.start_date + DELTA_SECS,
currentSummit.time_zone_id
).format("YYYY-MM-DD,HH:mm:ss");
const event_detail_url = `${currentSummit.virtual_site_url}event/${entity.id}#now=${eventStart}`;
window.open(event_detail_url, "_blank");
}
handleMaterialEdit(materialId) {
const { currentSummit, entity, history } = this.props;
history.push(
`/app/summits/${currentSummit.id}/events/${entity.id}/materials/${materialId}`
);
}
handleNewMaterial(ev) {
ev.preventDefault();
const { currentSummit, entity, history } = this.props;
history.push(
`/app/summits/${currentSummit.id}/events/${entity.id}/materials/new`
);
}
handleUploadPic(file) {
const { entity } = this.state;
const { onAttach } = this.props;
const newEntity = { ...entity };
newEntity.image = file.preview;
this.setState({ entity: newEntity });
const formData = new FormData();
formData.append("file", file);
onAttach(newEntity, formData, "profile");
}
getMaterialUrl(material) {
let url = null;
if (isValidUrl(material.private_url)) url = material.private_url;
if (isValidUrl(material.public_url)) url = material.public_url;
if (isValidUrl(material.link)) url = material.link;
if (material.youtube_id)
url = `https://www.youtube.com/watch?v=${material.youtube_id}`;
if (material.external_url) url = material.external_url;
return url;
}
handleMaterialDownload(materialId) {
const { entity } = this.props;
const material = entity.materials.find((m) => m.id === materialId);
const url = this.getMaterialUrl(material);
if (!url) {
Swal.fire(
"Not Found",
T.translate("edit_event.invalid_material_url"),
"warning"
);
return;
}
window.open(url, "_blank");
}
handleMaterialDelete(materialId) {
const { entity, onMaterialDelete } = this.props;
const material = entity.materials.find((m) => m.id === materialId);
Swal.fire({
title: T.translate("general.are_you_sure"),
text: `${T.translate("edit_event.delete_material")} ${material.filename}`,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: T.translate("general.yes_delete")
}).then((result) => {
if (result.value) {
onMaterialDelete(materialId);
}
});
}
handleFeedbackExport(ev) {
ev.preventDefault();
const { entity } = this.state;
const { feedbackState, getEventFeedbackCSV } = this.props;
getEventFeedbackCSV(
entity.id,
feedbackState.term,
feedbackState.order,
feedbackState.orderDir
);
}
handleFeedbackSearch(term) {
const { entity } = this.state;
const { feedbackState, getEventFeedback } = this.props;
getEventFeedback(
entity.id,
term,
feedbackState.page,
feedbackState.perPage,
feedbackState.order,
feedbackState.orderDir
);
}
handleFeedbackPageChange(page) {
const { entity } = this.state;
const { feedbackState, getEventFeedback } = this.props;
getEventFeedback(
entity.id,
feedbackState.term,
page,
feedbackState.perPage,
feedbackState.order,
feedbackState.orderDir
);
}
handleFeedbackSort(index, key, dir) {
const { feedbackState, getEventFeedback } = this.props;
const { entity } = this.state;
getEventFeedback(
entity.id,
feedbackState.term,
feedbackState.page,
feedbackState.perPage,
key,
dir
);
}
handleDeleteEventFeedback(id) {
const { entity } = this.state;
const { deleteEventFeedback } = this.props;
Swal.fire({
title: T.translate("general.are_you_sure"),
text: T.translate("edit_event.delete_feedback_warning"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: T.translate("general.yes_delete")
}).then((result) => {
if (result.value) {
deleteEventFeedback(entity.id, id);
}
});
}
handleTrackChairCommentEdit(commentId) {
const { currentSummit, entity, history } = this.props;
history.push(
`/app/summits/${currentSummit.id}/events/${entity.id}/comments/${commentId}`
);
}
handleTrackChairCommentDelete(commentId) {
const { commentState, onCommentDelete } = this.props;
const comment = commentState.comments.find((c) => c.id === commentId);
Swal.fire({
title: T.translate("general.are_you_sure"),
text:
`${T.translate("edit_event.delete_comment")} ` + `"${comment.body}"`,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: T.translate("general.yes_delete")
}).then((result) => {
if (result.value) {
onCommentDelete(commentId);
}
});
}
handleSelectSpeakerToAdd(ev) {
const { value } = ev.target;
this.setState((prevState) => ({ ...prevState, speakerToAdd: value }));
}
handleSpeakerAssign() {
const { entity, speakerToAdd } = this.state;
if (speakerToAdd) {
if (entity.speakers.some((s) => s.id === speakerToAdd.id)) return;
const speakers = [...entity.speakers, speakerToAdd];
this.setState((prevState) => ({
...prevState,
speakerToAdd: null,
entity: { ...entity, speakers }
}));
}
}
handleSpeakerUnassign(speakerId) {
const { entity } = this.state;
const speaker = entity.speakers.find((c) => c.id === speakerId);
if (!speaker) return;
Swal.fire({
title: T.translate("general.are_you_sure"),
text:
`${T.translate("edit_event.unassign_speaker")} ` +
`${speaker.first_name} ${speaker.last_name}?`,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: T.translate("general.yes_delete")
}).then((result) => {
if (result.value) {
this.setState((prevState) => ({
...prevState,
entity: {
...entity,
speakers: entity.speakers.filter((e) => e.id !== speaker.id)
}
}));
}
});
}
handleSpeakersReordering(speakers) {
const { entity } = this.state;
this.setState((prevState) => ({
...prevState,
entity: { ...entity, speakers }
}));
}
handleSpeakerEdit(speakerId) {
const { history } = this.props;
history.push(`/app/speakers/${speakerId}`);
}
handleTrackChairCommentSearch(term) {
const { entity } = this.state;
const { commentState, getEventComments } = this.props;
getEventComments(
entity.id,
term,
commentState.page,
commentState.perPage,
commentState.order,
commentState.orderDir
);
}
handleTrackChairCommentPageChange(page) {
const { entity } = this.state;
const { commentState, getEventComments } = this.props;
getEventComments(
entity.id,
commentState.term,
page,
commentState.perPage,
commentState.order,
commentState.orderDir
);
}
handleTrackChairCommentSort(index, key, dir) {
const { commentState, getEventComments } = this.props;
const { entity } = this.state;
getEventComments(
entity.id,
commentState.term,
commentState.page,
commentState.perPage,
key,
dir
);
}
handleTrackChairFilterChange(ev) {
const { entity, commentFilters } = this.state;
const { commentState, getEventComments } = this.props;
this.setState(
(prevState) => ({
...prevState,
commentFilters: {
...commentFilters,
[ev.target.id]: ev.target.checked
}
}),
() => {
getEventComments(
entity.id,
commentState.term,
commentState.page,
commentState.perPage,
commentState.order,
commentState.orderDir,
commentFilters
);
}
);
}
handleSaveIncomplete(ev) {
ev.preventDefault();
const { onSaveIncomplete } = this.props;
const { entity } = this.state;
onSaveIncomplete({ ...entity });
}
isPresentation() {
const { entity } = this.state;
return entity.class_name === "Presentation";
}
// The API's isSubmissionReopened() requires three things: the plan enabled, its
// submission window actually ended, and a live grant. Keying the UI on the grant
// alone lets it announce a deadline the server no longer treats as operative --
// e.g. an admin grants a reopen, then extends the plan's submission_end_date past
// it, and the speaker is editing under normal open-window rules again.
// entity comes from state, not props, because that is what the render gate reads.
// handleChangeSelectionPlan writes selection_plan_id into state without saving, and
// componentDidUpdate only syncs the other way, so reading props here would judge
// eligibility against the persisted plan while the form displays a different one.
isReopenApplicable() {
const { selectionPlansOpts } = this.props;
const { entity } = this.state;
const plan = selectionPlansOpts?.find(
(sp) => sp.id === entity.selection_plan_id
);
if (!plan || plan.is_enabled === false || !plan.submission_end_date) {
return false;
}
return moment().unix() > plan.submission_end_date;
}
// The panel title and the section body MUST share one gate. Keying the title on
// isSubmissionReopened() alone would announce a deadline in exactly the case the
// comment on isReopenApplicable describes: a live grant whose plan window was
// since extended, which the server no longer treats as operative.
isReopenSectionVisible() {
const { entity } = this.state;
return (
this.isPresentation() &&
!this.isNew() &&
entity.selection_plan_id > 0 &&
this.isReopenApplicable()
);
}
isSubmissionReopened() {
const deadline = this.getReopenDeadline();
return !!deadline?.isAfter(moment());
}
getReopenDeadline() {
const { currentSummit } = this.props;
const { entity } = this.state;
// normalizeEventResponse coerces server nulls to "", so "" means no grant.
if (!entity.submission_reopened_until) return null;
return epochToMomentTimeZone(
entity.submission_reopened_until,
currentSummit.time_zone_id
);
}
// Mirrors the server's CFP_MAX_REOPEN_HOURS so an over-ceiling value is caught
// before the confirm dialog rather than by the 412 after it. dotenv values are
// strings, hence the coercion. Unset means uncapped: the server's 412 stays the
// authoritative ceiling, so a deployment that never sets this behaves as before.
getMaxReopenHours() {
return Number(window.CFP_MAX_REOPEN_HOURS) || 0;
}
getSelectedReopenHours() {
const { reopenHours, reopenCustomHours } = this.state;
const raw = String(
reopenHours === "custom" ? reopenCustomHours : reopenHours
).trim();
// Not parseInt: it reads "-1" as a truthy negative, and "1.5"/"1e3" as 1, which
// would silently grant an hour instead of what the admin typed. Only a plain
// positive integer is a valid window.
if (!/^\d+$/.test(raw) || Number(raw) <= 0) return 0;
const hours = Number(raw);
// Uncapped, a digit-only value can still overflow moment: the deadline comes back NaN,
// which epochToMomentTimeZone passes through unwrapped, so the confirm dialog throws.
if (!moment().add(hours, "hours").isValid()) return 0;
const max = this.getMaxReopenHours();
// Applied to the presets too, not just the custom entry, so a ceiling
// configured below 72 can't offer a preset the server would refuse.
return max && hours > max ? 0 : hours;
}
async handleReopenSubmission() {
const { currentSummit, onReopenSubmission } = this.props;
const { entity } = this.state;
const hours = this.getSelectedReopenHours();
if (!hours) return;
// Deliberately optimistic: the deadline shown here is computed client-side for the
// confirm copy only. The server derives the real one. They agree to within the
// round trip, and naming it is what stops an admin pasting a link that will
// quietly go read-only (the CFP route hard-gates on the live grant).
const deadline = epochToMomentTimeZone(
moment().add(hours, "hours").unix(),
currentSummit.time_zone_id
).format(REOPEN_DEADLINE_FORMAT);
const confirmed = await showConfirmDialog({
title: T.translate("edit_event.reopen_confirm_title"),
text: T.translate("edit_event.reopen_confirm_text", { deadline }),
iconType: "warning",
confirmButtonText: T.translate("edit_event.reopen_submission")
});
// snackbarErrorHandler has already put the API message in front of the admin, and an
// over-ceiling hours value is an expected 412 rather than a fault. Swallow the
// rejection so it doesn't reach Sentry as an unhandled one.
if (confirmed) onReopenSubmission(entity.id, hours)?.catch(() => {});
}
async handleCloseSubmission() {
const { onCloseSubmission } = this.props;
const { entity } = this.state;
const confirmed = await showConfirmDialog({
title: T.translate("edit_event.close_submission_confirm_title"),
text: T.translate("edit_event.close_submission_confirm_text"),
iconType: "warning",
confirmButtonText: T.translate("edit_event.close_submission"),
confirmButtonColor: "error"
});
// See handleReopenSubmission: the error is already surfaced, so don't let the
// rejection escape as an unhandled one.
if (confirmed) onCloseSubmission(entity.id)?.catch(() => {});
}
isNew() {
const { entity } = this.state;
return !entity.id;
}
isComplete() {
const { entity } = this.state;
return (
["Accepted", "Received"].includes(entity?.status) &&
entity?.progress === "COMPLETE"
);
}
getMissingDraftFields() {
const { entity } = this.state;
const missing = [];
if (!entity.title) missing.push("Title");
if (!entity.type_id) missing.push("Activity Type");
if (!entity.track_id) missing.push("Activity Category");
if (!entity.type_id || this.shouldShowField("allows_publishing_dates")) {
if (!entity.start_date) missing.push("Start Date");
if (!entity.end_date) missing.push("End Date");
if (!entity.duration) missing.push("Duration");
}
if (!entity.type_id || this.isEventType(EVENT_TYPE_PRESENTATION)) {
if (!entity.disclaimer_accepted) missing.push("Disclaimer Accepted");
}
return missing;
}
handleEventTypeChange(oldEntity, newEntity) {
const isEventUpgrade =
!this.isEventType(EVENT_TYPE_PRESENTATION, oldEntity) &&
this.isEventType(EVENT_TYPE_PRESENTATION, newEntity);
const isEventDowngrade =
this.isEventType(EVENT_TYPE_PRESENTATION, oldEntity) &&
!this.isEventType(EVENT_TYPE_PRESENTATION, newEntity);
if (isEventUpgrade) {
Swal.fire({
title: T.translate("general.attention"),
html: `${T.translate("edit_event.upgrade_message")}<br>${T.translate(
"edit_event.upgrade_message_2"
)}`,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: T.translate("general.save")
}).then((result) => {
if (result.value) {
const { onEventUpgrade } = this.props;
onEventUpgrade(newEntity);
}
if (result.dismiss) {
this.setState((prevState) => ({
...prevState,
entity: oldEntity
}));
}
});
}
if (isEventDowngrade) {
Swal.fire({
title: T.translate("general.attention"),
text: T.translate("edit_event.downgrade_message"),
type: "warning",
showCancelButton: false,
confirmButtonColor: "#DD6B55"
// confirmButtonText: T.translate("general.yes_delete")
}).then((result) => {
if (result.value) {
this.setState((prevState) => ({
...prevState,
entity: oldEntity
}));
}
});
}
}
getPopupScores(score_id) {
const { entity } = this.state;
let res = "";
const rating_type = entity?.selection_plan?.track_chair_rating_types.find(
(st) => st.id === parseInt(score_id)
);
if (rating_type) {
rating_type.score_types.forEach((st) => {
if (res !== "") res += "<br>";
res += `${
st.score
}. <b>${st.name.trim()}</b> <p>${st.description?.trim()}</p>`;
});
}
return res;
}
getQAUsersOptionLabel(member) {
if (member.hasOwnProperty("full_name")) {
return member.full_name;
}
// default
return `${member.first_name} ${member.last_name} (${member.id})`;
}
triggerFormSubmit(ev, publish = false) {
ev.preventDefault();
const { onSubmit } = this.props;
const { entity } = this.state;
// do regular submit
const newEntity = { ...entity };
// check current ( could not be rendered)
if (this.formRef.current) {
this.setState(
(prevState) => ({ ...prevState, publish }),
() => {
this.formRef.current.doSubmit();
}
);
return;
}
// if we did not changed the extra questions , then dont send them
if (newEntity.extra_questions) {
delete newEntity.extra_questions;