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, EventRequestsService, EventsService, ResourceService } from "../../services"; import Select from 'react-select'; import { Button, Modal } from "react-bootstrap"; const CreateEvent = () => { const navigate = useNavigate(); const [resources, setResources] = useState([]); const [customers, setCustomers] = useState([]); const [currentCustomer, setCurrentCustomer] = useState(undefined); const [customerDisplay, setCustomerDisplay] = useState(''); const [medicalResource, setMedicalResource] = useState(undefined) const [currentResource, setCurrentResource] = useState(undefined); const [resourceType, setResourceType] = useState(''); const [source, setSource] = useState(''); const [np, setNp] = useState(''); const [symptom, setSymptom] = useState(''); const [transportation, setTransportation] = useState(''); const [showResourceModal, setShowResourceModal] = useState(false); const [keyword, setKeyword] = useState(''); const [filteredResources, setFilteredResources] = useState([]); // const [upload, setUpload] = useState(''); // const [uploadOther, setUploadOther] = useState(''); const [type, setType] = useState(''); // const params = new URLSearchParams(window.location.search); const goToRequestList = () => { navigate(`/medical/event-request/list`); } const redirectTo = () => { navigate(`/medical/index`); } const saveEventRequest = () => { const newEventRequest = { customer_id: currentCustomer?.id, customer_display: `${currentCustomer?.name} - ${currentCustomer?.name_cn} - ${currentCustomer?.birth_date}`, source, symptom, resource: currentResource?.id, resource_display: currentResource?.name, transportation, np, upload: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, type, status: 'active', create_by: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, create_date: new Date(), edit_history:[{ employee: localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name, date: new Date() }] } console.log('new Event Request', newEventRequest); EventRequestsService.createNewEventRequest(newEventRequest).then(data => goToRequestList()); }; 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); setFilteredResources(resourcesData.data); setCustomers(customersData.data); }) }, []); useEffect(() => { const newResources = [...resources]; if (resourceType && resourceType !== '') { setFilteredResources(newResources?.filter(item => item.type === resourceType)); } }, [resourceType]) const onCustomerChange = (selectedCustomer) => { setCustomerDisplay(selectedCustomer); setCurrentCustomer(customers.find(customer => customer.id === selectedCustomer.value)) } const filterResourceListByKeyword = (item) => { if (keyword.length > 0) { const newKeyword = keyword.toLowerCase(); return item?.name.toLowerCase()?.includes(newKeyword) || item?.address?.toLowerCase()?.includes(newKeyword) || item?.specialty?.toLowerCase()?.includes(newKeyword); } else { return true; } } const filterResourcesListBySpecialty = (item) => { if (resourceType.length > 0) { return item?.type === resourceType; } else { return true; } } // const onResourceChange = (selectedResource) => { // setMedicalResource(selectedResource); // setCurrentResource(resources.find(resource => resource.id === selectedResource.value)); // } return ( <>
Create Event Request
Source*:
Type*:
Patient*:
Doctor:
{currentResource ? (<>{currentResource?.name} ) : ()} {/* */}
Symptom 和特殊要求: