update
This commit is contained in:
@@ -149,22 +149,8 @@ export default function AppointmentForm({ isEdit, id, currentAppointment }: Prop
|
|||||||
|
|
||||||
const {fields, append, remove} = useFieldArray({name: 'medicine',control: methods.control})
|
const {fields, append, remove} = useFieldArray({name: 'medicine',control: methods.control})
|
||||||
|
|
||||||
// Autocomplite ICD
|
// Autocomplite ICD
|
||||||
const [icdOptions, setIcdOptions] = useState([
|
const [icdOptions, setIcdOptions] = useState([]);
|
||||||
{ value: '-', label: '-' }
|
|
||||||
]);
|
|
||||||
const codes = defaultValues.diagnosis.split(',');
|
|
||||||
const [selectedIcdOptions, setSelectedIcdOptions] = useState([]);
|
|
||||||
useEffect(() => {
|
|
||||||
const selectedCodes = icdOptions.filter((icd) => {
|
|
||||||
return codes.includes(icd.value);
|
|
||||||
});
|
|
||||||
setSelectedIcdOptions(selectedCodes);
|
|
||||||
setValue('diagnosis', selectedCodes);
|
|
||||||
}, [defaultValues.diagnosis]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Ambil data dari API dan atur opsi ICD
|
// Ambil data dari API dan atur opsi ICD
|
||||||
axios.get('diagnosis')
|
axios.get('diagnosis')
|
||||||
@@ -175,7 +161,20 @@ export default function AppointmentForm({ isEdit, id, currentAppointment }: Prop
|
|||||||
console.error('Error fetching ICD options:', error);
|
console.error('Error fetching ICD options:', error);
|
||||||
});
|
});
|
||||||
}, []); // useEffect dijalankan hanya sekali saat komponen dimount
|
}, []); // useEffect dijalankan hanya sekali saat komponen dimount
|
||||||
|
|
||||||
|
// Menggunakan selectedIcdOptions sebagai state untuk nilai default
|
||||||
|
const [selectedIcdOptions, setSelectedIcdOptions] = useState([]);
|
||||||
|
const codes = defaultValues.diagnosis.split(',');
|
||||||
|
useEffect(() => {
|
||||||
|
// Pastikan bahwa icdOptions sudah terisi sebelum memfilter
|
||||||
|
if (icdOptions.length > 0) {
|
||||||
|
const selectedCodes = icdOptions.filter((icd) => {
|
||||||
|
return codes.includes(icd.value);
|
||||||
|
});
|
||||||
|
setSelectedIcdOptions(selectedCodes);
|
||||||
|
// setValue('diagnosis', selectedCodes); // Ini bisa Anda hilangkan jika tidak diperlukan
|
||||||
|
}
|
||||||
|
}, [icdOptions, defaultValues.diagnosis]);
|
||||||
|
|
||||||
|
|
||||||
// Autocomplite Rumah Sakit
|
// Autocomplite Rumah Sakit
|
||||||
|
|||||||
Reference in New Issue
Block a user