This commit is contained in:
2024-05-06 11:44:38 +07:00
parent 092b8375d9
commit 7ee4aceaa6

View File

@@ -229,15 +229,6 @@ export default function AppointmentForm({ isEdit, id, currentAppointment }: Prop
// Autocomplite unit
const [unitOptions, setUnitsOptions] = useState([]);
const [selectedUnitsOptions, setSelectedUnitsOptions] = useState({});
const handleAutocompleteChangeUnit = (newValue, index) => {
setSelectedUnitsOptions((prevState) => ({
...prevState,
[index]: newValue
}));
setValue(`medicine.${index}.unit_id`, newValue ? newValue.value : '');
};
// Ambil data dari API dan atur opsi rumah sakit
useEffect(() => {
axios.get('units')
@@ -248,6 +239,15 @@ export default function AppointmentForm({ isEdit, id, currentAppointment }: Prop
console.error('Error fetching unit options:', error);
});
}, []); // useEffect dijalankan hanya sekali saat komponen dimount
const handleAutocompleteChangeUnit = (newValue, index) => {
setSelectedUnitsOptions((prevState) => ({
...prevState,
[index]: newValue
}));
setValue(`medicine.${index}.unit_id`, newValue ? newValue.value : '');
};
useEffect(() => {
if (defaultValues.medicine.length > 0) {