diff --git a/packages/esm-appointments-app/src/form/appointments-form.component.tsx b/packages/esm-appointments-app/src/form/appointments-form.component.tsx index 27b0486b1..94df7b62e 100644 --- a/packages/esm-appointments-app/src/form/appointments-form.component.tsx +++ b/packages/esm-appointments-app/src/form/appointments-form.component.tsx @@ -489,11 +489,22 @@ const AppointmentsForm: React.FC = ({ invalidText="Required" labelText={t('selectService', 'Select a service')} onChange={(event) => { + if (context === 'creating') { + setValue( + 'duration', + services?.find((service) => service.name === event.target.value)?.durationMins, + ); + } else if (context === 'editing') { + const previousServiceDuration = services?.find( + (service) => service.name === getValues('selectedService'), + )?.durationMins; + const selectedServiceDuration = services?.find((service) => service.name === event.target.value) + ?.durationMins; + if (selectedServiceDuration && previousServiceDuration === getValues('duration')) { + setValue('duration', selectedServiceDuration); + } + } onChange(event); - setValue( - 'duration', - services?.find((service) => service.name === event.target.value)?.durationMins, - ); }} onBlur={onBlur} value={value}