import React, {useState, useEffect} from "react"; // import { useDispatch } from "react-redux"; import { useNavigate, useParams } from "react-router-dom"; // import { customerSlice } from "./../../store"; import { AuthService, CustomerService, EventsService, ResourceService } from "../../services"; import Select from 'react-select'; import DatePicker from "react-datepicker"; import { Spinner, Breadcrumb, BreadcrumbItem, Tabs, Tab } from "react-bootstrap"; const CreateEvent = () => { const navigate = useNavigate(); // const [medicalResource, setMedicalResource] = useState(undefined); // const [currentResource, setCurrentResource] = useState(undefined); const [resources, setResources] = useState([]); const [customers, setCustomers] = useState([]); const [customerName, setCustomerName] = useState(undefined); const [currentCustomer, setCurrentCustomer] = useState(undefined); const [startTime, setStartTime] = useState(''); // const [title, setTitle] = useState(''); // const [description, setDescription] = useState(''); // const [newPatient, setNewPatient] = useState(''); // const [confirmed, setConfirmed] = useState(''); // const [fasting, setFasting] = useState(''); // const [interpreter, setInterpreter] = useState(''); // const [docOrder, setDocOrder] = useState(''); // const [disability, setDisability] = useState(''); // const [needId, setNeedId] = useState(''); // const [needMedicationList, setNeedMedicationList] = useState(''); // const [disabilitySupport, setDisabilitySupport] = useState(''); // const [notes, setNotes] = useState(''); // const [reason, setReason] = useState(''); // const [otherRequirement, setOtherRequirement] = useState(''); // const [todayEvents, setTodayEvents] = useState([]); // const [transportationInfo, setTransportationInfo] = useState(undefined); const params = new URLSearchParams(window.location.search); const redirectToCalendar = () => { navigate(`/medical/events/calendar`); } const redirectToView = (id) => { navigate(`/medical/events/${id}`); } const redirectTo = () => { navigate(`/medical/events/list`); } const goToNext = (id) => { navigate(`/medical/events/edit/${id}?from=create`) } const saveEvent = () => { console.log('customer', currentCustomer); // console.log('resource', currentResource); const newEventData = { customer: currentCustomer.id, // resource: currentResource.id, client_name: currentCustomer.name, client_pharmacy: currentCustomer.pharmacy, client_pcp: currentCustomer.care_provider, client_birth_date: currentCustomer.birth_date, client_seating: currentCustomer.seating, // resource_type: currentResource.type, // resource_name: currentResource.name, // resource_phone: currentResource.phone, // resource_contact: currentResource.contact, // resource_address: currentResource.address, // resource_city: currentResource.city, // resource_state: currentResource.state, // // legacy fields end // // We still wanna keep the legacy fields below // new_patient: newPatient, // confirmed: confirmed, // fasting: fasting, // interpreter: interpreter, // doc_order: docOrder, // need_id: needId, // need_med_list: needMedicationList, // notes: notes, // reason: reason, // other: otherRequirement, disability: currentCustomer.disability? 'yes' : 'no', // disability_support: disabilitySupport } const newEvent = { data: newEventData, // title: title, // descrption: description, // notes: notes, start_time: new Date(startTime), type: 'medical', // stop_time: new Date(startTime), // source_type: currentResource.type, // source_uuid: currentResource.id, // source_name: currentResource.name, target_type: currentCustomer.type, target_uuid: currentCustomer.id, target_name: currentCustomer.name, create_by: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, create_date: new Date(), edit_by: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, edit_date: new Date(), edit_history:[{ employee: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, date: new Date() }] } navigate(`/medical/events/create-from-request?event=${encodeURIComponent(JSON.stringify(newEvent))}`) // EventsService.createNewEvent(newEvent).then(data => goToNext(data.data?.id)); }; useEffect(() => { if (!AuthService.canAccessLegacySystem()) { window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.') AuthService.logout(); navigate(`/login`); } Promise.all([ResourceService.getAll(), CustomerService.getAllCustomers()]).then(([resourcesData, customersData]) => { setResources(resourcesData.data); setCustomers(customersData.data); }) }, []); const onCustomerChange = (selectedCustomer) => { setCustomerName(selectedCustomer); setCurrentCustomer(customers.find(customer => customer.id === selectedCustomer.value)) } // const onResourceChange = (selectedResource) => { // setMedicalResource(selectedResource); // setCurrentResource(resources.find(resource => resource.id === selectedResource.value)); // } return ( <>