import React from 'react'; import { Button, ButtonSet, Dropdown, Layer, SelectItem, TextInput, TimePicker, TimePickerSelect } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { Form, Formik, type FormikHelpers } from 'formik'; import { validationSchema } from './appointment-services-validation'; import { useAppointmentServices } from './appointment-services-hook'; import { showSnackbar, useLocations } from '@openmrs/esm-framework'; import type { AppointmentService } from '../../types'; import { closeOverlay } from '../../hooks/useOverlay'; import styles from './appointment-services.scss'; import { appointmentLocationTagName } from '../../constants'; interface AppointmentServicesProps {} const AppointmentServices: React.FC = () => { const { t } = useTranslation(); const { appointmentServiceInitialValue, addNewAppointmentService } = useAppointmentServices(); const locations = useLocations(appointmentLocationTagName); const handleSubmit = async (values: AppointmentService, helpers: FormikHelpers) => { const payload = { name: values.name, startTime: values.startTime.concat(':00'), endTime: values.endTime.concat(':00'), durationMins: values.durationMins, color: values.color, locationUuid: values.location.uuid, }; addNewAppointmentService(payload).then( ({ status }) => { if (status === 200) { showSnackbar({ isLowContrast: true, kind: 'success', subtitle: t('appointmentServiceCreate', 'Appointment service created successfully'), title: t('appointmentService', 'Appointment service'), }); closeOverlay(); } }, (error) => { showSnackbar({ title: t('errorCreatingAppointmentService', 'Error creating appointment service'), kind: 'error', subtitle: error?.message, }); }, ); }; return ( {(props) => { return (

{t('createAppointmentService', 'Create appointment service')}

(item ? item.display : '')} selectedItem={props.values.location} invalid={!!(props.touched && props.errors.location?.uuid)} name="location" onChange={({ selectedItem }) => props.setValues({ ...props.values, location: selectedItem })} />
); }}
); }; export default AppointmentServices;