/
AddAppointment.jsx
591 lines (552 loc) · 32.2 KB
/
AddAppointment.jsx
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
import React, {Fragment, useEffect, useState} from "react";
import classNames from 'classnames';
import {
appointmentEditor,
appointmentPlanContainer,
dateHeading,
isRecurring,
recurringContainer,
recurringContainerLeft,
recurringContainerRight,
searchFieldsContainer,
timeSelector,
weekDaysContainer
} from './AddAppointment.module.scss';
import {conflictsPopup, customPopup} from "../CustomPopup/CustomPopup.module.scss";
import ErrorMessage from "../ErrorMessage/ErrorMessage.jsx";
import AppointmentEditorFooter from "../AppointmentEditorFooter/AppointmentEditorFooter.jsx";
import {injectIntl} from "react-intl";
import PropTypes from "prop-types";
import {
getAppointmentConflicts,
getRecurringAppointmentsConflicts,
saveAppointment,
saveRecurring
} from "../../services/AppointmentsService/AppointmentsService";
import Label from '../Label/Label.jsx';
import {getDateTime, isStartTimeBeforeEndTime} from '../../utils/DateUtil.js'
import TimeSelector from "../TimeSelector/TimeSelector.jsx";
import AppointmentNotes from "../AppointmentNotes/AppointmentNotes.jsx";
import AppointmentPlan from "../AppointmentPlan/AppointmentPlan.jsx";
import CustomPopup from "../CustomPopup/CustomPopup.jsx";
import SuccessConfirmation from "../SuccessModal/SuccessModal.jsx";
import {AppContext} from "../AppContext/AppContext";
import AppointmentDatePicker from "../DatePicker/DatePicker.jsx";
import StartDateRadioGroup from "../RadioGroup/StartDateRadioGroup.jsx";
import EndDateRadioGroup from "../RadioGroup/EndDateRadioGroup.jsx";
import RecurrenceTypeRadioGroup from "../RadioGroup/RecurrenceTypeRadioGroup.jsx";
import {
appointmentEndTimeProps,
appointmentStartTimeProps,
CANCEL_CONFIRMATION_MESSAGE_ADD,
dayRecurrenceType,
FROM,
MINUTES,
RECURRING_APPOINTMENT_TYPE,
SERVICE_ERROR_MESSAGE_TIME_OUT_INTERVAL,
TODAY,
WALK_IN_APPOINTMENT_TYPE
} from "../../constants";
import moment from "moment";
import {getDefaultOccurrences, getDuration} from "../../helper.js";
import {getSelectedWeekDays, getWeekDays} from "../../services/WeekDaysService/WeekDaysService";
import ButtonGroup from "../ButtonGroup/ButtonGroup.jsx";
import {getErrorTranslations} from "../../utils/ErrorTranslationsUtil";
import {isEmpty, isNil} from 'lodash';
import AppointmentEditorCommonFieldsWrapper
from "../AppointmentEditorCommonFieldsWrapper/AppointmentEditorCommonFieldsWrapper.jsx";
import Conflicts from "../Conflicts/Conflicts.jsx";
import updateAppointmentStatusAndProviderResponse from "../../appointment-request/AppointmentRequest";
import * as patientApi from "../../api/patientApi";
import {mapOpenMRSPatient} from "../../mapper/patientMapper";
const AddAppointment = props => {
const {appConfig, intl, appointmentParams, currentProvider, urlParams } = props;
const {setViewDate} = React.useContext(AppContext);
const errorTranslations = getErrorTranslations(intl);
const initialAppointmentState = {
patient: null,
providers: [],
service: null,
serviceType: null,
location: null,
speciality: null,
appointmentDate: appointmentParams && moment(new Date(appointmentParams.startDateTime)),
recurringStartDate: appointmentParams && moment(new Date(appointmentParams.startDateTime)),
recurringEndDate: undefined,
startTime: appointmentParams && moment(appointmentParams.startDateTime),
endTime: appointmentParams && moment(appointmentParams.endDateTime),
appointmentType: undefined,
notes: undefined,
startDateType: appointmentParams && moment(new Date(appointmentParams.startDateTime)) ? FROM : undefined,
endDateType: undefined,
recurrenceType: dayRecurrenceType,
occurrences: undefined,
period: undefined,
weekDays: undefined,
selectedRecurringStartDate: appointmentParams && moment(new Date(appointmentParams.startDateTime))
};
const initialErrorsState = {
patientError: false,
serviceError: false,
appointmentDateError: false,
startDateError: false,
endDateError: false,
endDateTypeError: false,
occurrencesError: false,
startTimeError: false,
endTimeError: false,
recurrencePeriodError: false,
startTimeBeforeEndTimeError: false,
weekDaysError: false,
providerError: false
};
const [appointmentDetails, setAppointmentDetails] = useState(initialAppointmentState);
const [conflicts, setConflicts] = useState();
const [errors, setErrors] = useState(initialErrorsState);
const [showSuccessPopup, setShowSuccessPopup] = useState(false);
const [serviceErrorMessage, setServiceErrorMessage] = useState('');
const [disableSaveButton, setDisableSaveButton] = useState(false);
useEffect(() => {
if (appointmentDetails.occurrences === undefined)
updateAppointmentDetails({occurrences: getDefaultOccurrences(appConfig)});
updateAppointmentDetails({weekDays: getWeekDays(appConfig && appConfig.startOfWeek)});
if(urlParams && urlParams.patient) {
populatePatientDetails(urlParams.patient).then();
}
}, [appConfig]);
async function populatePatientDetails(patientUuid) {
const patient = await patientApi.getPatient(patientUuid);
const patientForDropdown = mapOpenMRSPatient(patient);
return updateAppointmentDetails({patient: patientForDropdown});
}
const reInitialiseComponent = () => {
updateAppointmentDetails({
...initialAppointmentState,
weekDays: getWeekDays(appConfig && appConfig.startOfWeek)
});
updateErrorIndicators(initialErrorsState);
setConflicts(undefined);
setShowSuccessPopup(false);
};
const getRecurringPattern = () => {
const recurringPattern = {
type: appointmentDetails.recurrenceType,
period: appointmentDetails.period
};
appointmentDetails.endDateType === "After" ? recurringPattern.frequency = appointmentDetails.occurrences : recurringPattern.endDate = appointmentDetails.recurringEndDate;
if (appointmentDetails.recurrenceType === 'WEEK') {
recurringPattern.daysOfWeek = getSelectedWeekDays(appointmentDetails.weekDays);
}
return recurringPattern;
};
const isRecurringAppointment = () => appointmentDetails.appointmentType === RECURRING_APPOINTMENT_TYPE;
const isWalkInAppointment = () => appointmentDetails.appointmentType === WALK_IN_APPOINTMENT_TYPE;
const getAppointmentRequest = () => {
let appointment = {
patientUuid: appointmentDetails.patient && appointmentDetails.patient.value.uuid,
serviceUuid: appointmentDetails.service && appointmentDetails.service.value.uuid,
serviceTypeUuid: appointmentDetails.serviceType && appointmentDetails.serviceType.value &&
appointmentDetails.serviceType.value.uuid,
startDateTime: isRecurringAppointment()
? getDateTime(appointmentDetails.recurringStartDate, appointmentDetails.startTime)
: getDateTime(appointmentDetails.appointmentDate, appointmentDetails.startTime),
endDateTime: isRecurringAppointment()
? getDateTime(appointmentDetails.recurringStartDate, appointmentDetails.endTime)
: getDateTime(appointmentDetails.appointmentDate, appointmentDetails.endTime),
providers: appointmentDetails.providers,
locationUuid: appointmentDetails.location && appointmentDetails.location.value.uuid,
appointmentKind: isWalkInAppointment() ? WALK_IN_APPOINTMENT_TYPE : "Scheduled",
comments: appointmentDetails.notes
};
if (!appointment.serviceTypeUuid || appointment.serviceTypeUuid.length < 1)
delete appointment.serviceTypeUuid;
return appointment;
};
const getRecurringAppointmentRequest = () => {
return {
appointmentRequest: getAppointmentRequest(),
recurringPattern: getRecurringPattern()
};
};
const updateErrorIndicators = errorIndicators => setErrors(prevErrors => {return {...prevErrors, ...errorIndicators}});
const updateAppointmentDetails = modifiedAppointmentDetails => setAppointmentDetails(prevAppointmentDetails => {
return {...prevAppointmentDetails, ...modifiedAppointmentDetails}
});
const isValidAppointment = () => {
const isValidPatient = appointmentDetails.patient && appointmentDetails.patient.value.uuid;
const startTimeBeforeEndTime = isStartTimeBeforeEndTime(appointmentDetails.startTime, appointmentDetails.endTime);
updateCommonErrorIndicators(isValidPatient, startTimeBeforeEndTime);
updateErrorIndicators({appointmentDateError: !appointmentDetails.appointmentDate});
return isValidPatient && appointmentDetails.service && appointmentDetails.appointmentDate && appointmentDetails.startTime && appointmentDetails.endTime && startTimeBeforeEndTime;
};
const isValidRecurringAppointment = () => {
const isValidPatient = appointmentDetails.patient && appointmentDetails.patient.value.uuid;
const startTimeBeforeEndTime = isStartTimeBeforeEndTime(appointmentDetails.startTime, appointmentDetails.endTime);
const selectedWeekDays = getSelectedWeekDays(appointmentDetails.weekDays);
updateCommonErrorIndicators(isValidPatient, startTimeBeforeEndTime);
updateErrorIndicators({
recurrencePeriodError: !appointmentDetails.period || appointmentDetails.period < 1,
endDateTypeError: !appointmentDetails.endDateType,
weekDaysError: appointmentDetails.recurrenceType === 'WEEK' && isEmpty(selectedWeekDays),
startDateError: !appointmentDetails.startDateType || !appointmentDetails.recurringStartDate
});
if (appointmentDetails.endDateType) {
updateErrorIndicators({
endDateError: appointmentDetails.endDateType === "On" && !appointmentDetails.recurringEndDate,
occurrencesError: appointmentDetails.endDateType === "After" && (!appointmentDetails.occurrences || appointmentDetails.occurrences < 1)
})
}
return isValidPatient && appointmentDetails.service && appointmentDetails.startTime
&& appointmentDetails.endTime && startTimeBeforeEndTime && appointmentDetails.recurrenceType
&& appointmentDetails.period && appointmentDetails.period > 0 && appointmentDetails.recurringStartDate
&& isValidEndDate() && (appointmentDetails.recurrenceType === dayRecurrenceType || !isEmpty(selectedWeekDays));
};
const updateCommonErrorIndicators = (isValidPatient, startTimeBeforeEndTime) => updateErrorIndicators({
patientError: !isValidPatient,
serviceError: !appointmentDetails.service,
startTimeError: !appointmentDetails.startTime,
endTimeError: !appointmentDetails.endTime,
startTimeBeforeEndTimeError: !startTimeBeforeEndTime
});
const isValidEndDate = () => (appointmentDetails.endDateType === "On" && appointmentDetails.recurringEndDate) ||
(appointmentDetails.endDateType === "After" && appointmentDetails.occurrences && appointmentDetails.occurrences > 0);
const setViewDateAndShowSuccessPopup = startDate => {
setViewDate(moment(startDate).startOf('day').toDate());
setShowSuccessPopup(true);
};
const setServiceErrorMessageFromResponse = response => {
response.error && response.error.message ? setServiceErrorMessage(response.error.message)
: setServiceErrorMessage(errorTranslations.unexpectedServiceErrorMessage);
};
const resetServiceErrorMessage = () => {
setTimeout(function () {
setServiceErrorMessage('');
}, SERVICE_ERROR_MESSAGE_TIME_OUT_INTERVAL);
};
const save = async appointmentRequest => {
setDisableSaveButton(true);
if (appConfig.enableAppointmentRequests) {
await checkAndUpdateAppointmentStatus(appointmentRequest, false);
}
const response = await saveAppointment(appointmentRequest);
const status = response.status;
if (status === 200) {
setConflicts(undefined);
setViewDateAndShowSuccessPopup(response.data.startDateTime);
} else if (response.data && response.data.error) {
setConflicts(undefined);
setServiceErrorMessageFromResponse(response.data);
resetServiceErrorMessage();
}
setDisableSaveButton(false);
};
const checkAndSave = async () => {
if (isValidAppointment()) {
setDisableSaveButton(true);
const appointment = getAppointmentRequest();
const response = await getAppointmentConflicts(appointment);
const status = response.status;
if (status === 204) {
await save(appointment);
} else if (status === 200) {
setConflicts(response.data);
} else if (response.data && response.data.error) {
setConflicts(undefined);
setServiceErrorMessageFromResponse(response.data);
resetServiceErrorMessage();
}
setDisableSaveButton(false);
}
};
const checkAndUpdateAppointmentStatus = async function (appointmentRequest, isRecurring) {
const appointmentRequestData = isRecurring ? appointmentRequest.appointmentRequest : appointmentRequest;
await updateAppointmentStatusAndProviderResponse(appointmentDetails, appointmentRequestData, currentProvider.uuid, [], false);
};
const saveRecurringAppointments = async recurringAppointmentRequest => {
setDisableSaveButton(true);
if (appConfig.enableAppointmentRequests) {
await checkAndUpdateAppointmentStatus(recurringAppointmentRequest, true);
}
const response = await saveRecurring(recurringAppointmentRequest);
const status = response.status;
if (status === 200) {
setConflicts(undefined);
setServiceErrorMessage('');
const immediateAppointment = response.data[0];
setViewDateAndShowSuccessPopup(immediateAppointment.appointmentDefaultResponse.startDateTime);
} else if (status === 204) {
setServiceErrorMessage(errorTranslations.noContentErrorMessage);
resetServiceErrorMessage();
} else if (response.data && response.data.error) {
setConflicts(undefined);
setServiceErrorMessageFromResponse(response.data);
resetServiceErrorMessage();
}
setDisableSaveButton(false);
};
const checkAndSaveRecurringAppointments = async () => {
if (isValidRecurringAppointment()) {
setDisableSaveButton(true);
const recurringRequest = getRecurringAppointmentRequest();
const response = await getRecurringAppointmentsConflicts(recurringRequest);
const status = response.status;
if (status === 204) {
await saveRecurringAppointments(recurringRequest);
} else if (status === 200) {
setConflicts(response.data);
} else if (response.data && response.data.error) {
setConflicts(undefined);
setServiceErrorMessageFromResponse(response.data);
resetServiceErrorMessage();
}
setDisableSaveButton(false);
}
};
const saveAppointments = () => {
isRecurringAppointment()
? saveRecurringAppointments(getRecurringAppointmentRequest()) : save(getAppointmentRequest());
};
const savePopup = <CustomPopup style={customPopup} popupContent={<SuccessConfirmation
resetAppointmentModal={reInitialiseComponent}
patientDetails={appointmentDetails.patient && `${appointmentDetails.patient.value.name} (${appointmentDetails.patient.value.identifier})`}/>}/>;
const endTimeBasedOnService = (time, service, serviceType) => {
const currentTime = moment(time);
const duration = getDuration(service, serviceType);
currentTime.add(duration, MINUTES);
if (time) {
updateAppointmentDetails({endTime: currentTime});
updateErrorIndicators({endTimeError: false});
}
};
const getEndDateTypeErrorMessage = () => {
if (errors.endDateTypeError) return errorTranslations.endDateTypeErrorMessage;
if (errors.endDateError) return errorTranslations.dateErrorMessage;
if (errors.occurrencesError) return errorTranslations.occurrencesErrorMessage;
};
const startDateOnChange = value => {
updateAppointmentDetails({startDateType: value});
if (value === TODAY) {
updateAppointmentDetails({recurringStartDate: moment()});
updateErrorIndicators({startDateError: false});
} else {
updateAppointmentDetails({
recurringEndDate: undefined,
recurringStartDate: appointmentDetails.selectedRecurringStartDate
});
updateErrorIndicators({startDateError: !appointmentDetails.recurringStartDate});
}
};
const endDateOnChange = value => {
updateAppointmentDetails({endDateType: value});
updateErrorIndicators({endDateTypeError: false});
value === "After" && updateErrorIndicators({endDateError: false});
if (value === "On") {
updateErrorIndicators({endDateError: appointmentDetails.recurringStartDate && !appointmentDetails.recurringEndDate, occurrencesError: false});
}
};
const on = "On";
return (<Fragment>
<div data-testid="appointment-editor" className={classNames(appointmentEditor, appointmentDetails.appointmentType === RECURRING_APPOINTMENT_TYPE ? isRecurring: '')}>
<AppointmentEditorCommonFieldsWrapper appointmentDetails={appointmentDetails}
updateAppointmentDetails={updateAppointmentDetails}
updateErrorIndicators={updateErrorIndicators}
endTimeBasedOnService={endTimeBasedOnService}
appConfig={appConfig} errors={errors} autoFocus={true}/>
<div className={classNames(searchFieldsContainer)} data-testid="recurring-plan-checkbox">
<div className={classNames(appointmentPlanContainer)}>
<AppointmentPlan appointmentType={appointmentDetails.appointmentType}
onChange={(e) => {
if (appointmentDetails.appointmentType === e.target.name)
updateAppointmentDetails({appointmentType: undefined});
else
updateAppointmentDetails({appointmentType: e.target.name})
}}/>
</div>
</div>
<div className={classNames(recurringContainer)}>
{isRecurringAppointment() ?
<div className={classNames(recurringContainerLeft)}>
<div data-testid="start-date-group">
<div className={classNames(dateHeading)}>
<Label translationKey="STARTS_LABEL" defaultValue="Starts"/>
</div>
<StartDateRadioGroup
onChange={event => startDateOnChange(event.target.value)}
startDateType={appointmentDetails.startDateType}/>
<AppointmentDatePicker
onChange={date => {
updateAppointmentDetails({
recurringStartDate: date,
selectedRecurringStartDate: date
});
!date.isBefore(appointmentDetails.recurringEndDate) && updateAppointmentDetails({recurringEndDate: undefined});
updateErrorIndicators({startDateError: !date});
}}
isDisabled={ appointmentDetails.startDateType !==FROM }
value={appointmentDetails.startDateType === FROM ? appointmentDetails.selectedRecurringStartDate : appointmentDetails.recurringStartDate}
minDate={moment()}/>
<ErrorMessage message={errors.startDateError ? errorTranslations.dateErrorMessage : undefined}/>
</div>
<div data-testid="end-date-group">
<div className={classNames(dateHeading)}>
<Label translationKey="ENDS_LABEL" defaultValue="Ends"/>
</div>
<EndDateRadioGroup
onChange={event => endDateOnChange(event.target.value)}
onOccurrencesChange={value => updateAppointmentDetails({occurrences: value})}
occurrences={appointmentDetails.occurrences}
endDateType={appointmentDetails.endDateType}/>
<AppointmentDatePicker
onChange={date => {
updateAppointmentDetails({recurringEndDate: date!=='' && !isNil(date)
? moment(date).endOf('day') : undefined});
updateErrorIndicators({endDateError: !date});
}}
isDisabled={appointmentDetails.endDateType !== on || (appointmentDetails.endDateType === on && isNil(appointmentDetails.recurringStartDate))}
value={appointmentDetails.recurringEndDate}
minDate={appointmentDetails.recurringStartDate}/>
<ErrorMessage message={getEndDateTypeErrorMessage()}/>
</div>
<div data-testid="recurrence-type-group">
<div>
<div className={classNames(dateHeading)}>
<Label translationKey="REPEATS_EVERY_LABEL" defaultValue="Repeats Every"/>
</div>
<div>
<div>
<RecurrenceTypeRadioGroup
onChange={event => {
updateAppointmentDetails({recurrenceType: event.currentTarget.value});
updateErrorIndicators({weekDaysError: errors.weekDaysError && event.currentTarget.value === 'WEEK'});
}}
onPeriodChange={value => {
updateAppointmentDetails({period: value});
updateErrorIndicators({recurrencePeriodError: false});
}}
period={appointmentDetails.period}
recurrenceType={appointmentDetails.recurrenceType}/>
<ErrorMessage
message={errors.recurrencePeriodError ? errorTranslations.recurrencePeriodErrorMessage : undefined}/>
</div>
<div className={classNames(weekDaysContainer)}>
<ButtonGroup buttonsList={appointmentDetails.weekDays} onClick={buttonKey => {
const prevWeekDaysMap = new Map(appointmentDetails.weekDays);
const nextEntry = {
...prevWeekDaysMap.get(buttonKey),
isSelected: !prevWeekDaysMap.get(buttonKey).isSelected
};
prevWeekDaysMap.set(buttonKey, nextEntry);
updateAppointmentDetails({weekDays: prevWeekDaysMap});
updateErrorIndicators({weekDaysError: false});
}} enable={appointmentDetails.recurrenceType === 'WEEK'}/>
<ErrorMessage
message={errors.weekDaysError ? errorTranslations.weekDaysErrorMessage : undefined}/>
</div>
</div>
</div>
<div className={classNames(timeSelector)}>
<Label translationKey="APPOINTMENT_TIME_LABEL" defaultValue="Choose a time slot"/>
<div data-testid="start-time-selector">
<TimeSelector {...appointmentStartTimeProps(appointmentDetails.startTime)}
onChange={time => {
updateAppointmentDetails({startTime: time});
endTimeBasedOnService(time, appointmentDetails.service && appointmentDetails.service.value,
appointmentDetails.serviceType && appointmentDetails.serviceType.value);
updateErrorIndicators({startTimeError: !time});
}}/>
<ErrorMessage message={errors.startTimeError ? errorTranslations.timeErrorMessage : undefined}/>
</div>
<div data-testid="end-time-selector">
<TimeSelector {...appointmentEndTimeProps(appointmentDetails.endTime)}
onChange={time => {
updateAppointmentDetails({endTime: time});
updateErrorIndicators({
startTimeBeforeEndTimeError: !isStartTimeBeforeEndTime(appointmentDetails.startTime, time),
endTimeError: !time
});
}}/>
<ErrorMessage message={errors.endTimeError ? errorTranslations.timeErrorMessage : undefined}/>
</div>
<ErrorMessage
message={appointmentDetails.startTime && appointmentDetails.endTime && errors.startTimeBeforeEndTimeError ? errorTranslations.startTimeLessThanEndTimeMessage : undefined}/>
</div>
</div>
</div> :
<div className={classNames(recurringContainerLeft)}>
<div data-testid="date-selector">
<div className={classNames(dateHeading)}>
<Label translationKey="APPOINTMENT_DATE_LABEL" defaultValue="Appointment date"/>
</div>
<AppointmentDatePicker
onChange={date => {
updateAppointmentDetails({appointmentDate: date});
updateErrorIndicators({appointmentDateError: !date});
}}
value={appointmentDetails.appointmentDate}
minDate={moment()}/>
<ErrorMessage message={errors.appointmentDateError ? errorTranslations.dateErrorMessage : undefined}/>
</div>
<div>
<div className={classNames(dateHeading)}><Label translationKey="APPOINTMENT_TIME_LABEL" defaultValue="Choose a time slot"/></div>
<div data-testid="start-time-selector">
<TimeSelector {...appointmentStartTimeProps(appointmentDetails.startTime)}
onChange={time => {
updateAppointmentDetails({startTime: time});
endTimeBasedOnService(time, appointmentDetails.service && appointmentDetails.service.value,
appointmentDetails.serviceType && appointmentDetails.serviceType.value);
updateErrorIndicators({startTimeError: !time});
}}/>
<ErrorMessage message={errors.startTimeError ? errorTranslations.timeErrorMessage : undefined}/>
</div>
<div data-testid="end-time-selector">
<TimeSelector {...appointmentEndTimeProps(appointmentDetails.endTime)}
onChange={time => {
updateAppointmentDetails({endTime: time});
updateErrorIndicators({
startTimeBeforeEndTimeError: !isStartTimeBeforeEndTime(appointmentDetails.startTime, time),
endTimeError: !time
});
}}/>
<ErrorMessage message={errors.endTimeError ? errorTranslations.timeErrorMessage : undefined}/>
</div>
<ErrorMessage
message={appointmentDetails.startTime && appointmentDetails.endTime && errors.startTimeBeforeEndTimeError ? errorTranslations.startTimeLessThanEndTimeMessage : undefined}/>
</div>
</div>}
<div className={classNames(recurringContainerRight)}>
<div className={classNames(dateHeading)}><Label translationKey="APPOINTMENT_NOTES" defaultValue="Notes"/></div>
<AppointmentNotes value={appointmentDetails.notes} onChange={(event) => updateAppointmentDetails({notes: event.target.value})}/>
</div>
</div>
<AppointmentEditorFooter
errorMessage={serviceErrorMessage}
checkAndSave={isRecurringAppointment() ? checkAndSaveRecurringAppointments : checkAndSave}
cancelConfirmationMessage={CANCEL_CONFIRMATION_MESSAGE_ADD}
disableSaveAndUpdateButton={disableSaveButton}
/>
{conflicts &&
<CustomPopup style={conflictsPopup} open={true}
closeOnDocumentClick={false}
closeOnEscape={true}
onClose={() => setConflicts(undefined)}
popupContent={<Conflicts saveAnyway={saveAppointments}
modifyInformation={() => setConflicts(undefined)}
conflicts={conflicts} service={appointmentDetails.service}
disableSaveAnywayButton={disableSaveButton}
isRecurring={appointmentDetails.isRecurring}/>}/>}
{showSuccessPopup ? React.cloneElement(savePopup, {
open: true,
closeOnDocumentClick: false,
closeOnEscape: false
}) : undefined}
</div>
</Fragment>);
};
AddAppointment.propTypes = {
intl: PropTypes.object.isRequired,
appConfig: PropTypes.object,
appointmentParams: PropTypes.object,
currentProvider: PropTypes.object,
urlParams: PropTypes.object
};
export default injectIntl(AddAppointment);