update sucos

This commit is contained in:
Raja Oktafrianto
2025-03-17 11:08:06 +07:00
parent bd2a4ff233
commit ed7671a856
2 changed files with 21 additions and 12 deletions

View File

@ -65,6 +65,9 @@ const SearchDialog = () => {
try { try {
const response = await axios.get(`${API_URL}/sucos/aldeias/${id}`); const response = await axios.get(`${API_URL}/sucos/aldeias/${id}`);
console.log('API Response Data:', response.data.data);
console.log('aldeias data:', aldeias);
console.log('isFound:', isFound);
if (response.data.status) { if (response.data.status) {
setAldeias(response.data.data); setAldeias(response.data.data);
@ -110,7 +113,7 @@ const SearchDialog = () => {
</div> </div>
</div> </div>
</DialogHeader> </DialogHeader>
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}> <DialogBody className="scrollable-x px-0 pb-0" ref={parentRef}>
<div className="flex flex-col px-0"> <div className="flex flex-col px-0">
{alert.show && ( {alert.show && (
<Alert variant="danger" className="mb-5"> <Alert variant="danger" className="mb-5">
@ -127,12 +130,12 @@ const SearchDialog = () => {
<Select <Select
value={formField.id?.toString() ?? ''} value={formField.id?.toString() ?? ''}
onValueChange={(target) => { onValueChange={(target) => {
const selectedSuco = sucos.find((m) => m.id.toString() === target); const selectedSuco = sucos.find((m) => m.sucos_id.toString() === target);
if (selectedSuco) { if (selectedSuco) {
setFormField({ setFormField({
...formField, ...formField,
id: selectedSuco.id, id: selectedSuco.sucos_id,
name: selectedSuco.name name: selectedSuco.sucos_name
}); });
} }
}} }}
@ -142,11 +145,17 @@ const SearchDialog = () => {
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{sucos?.map((suco) => ( {sucos?.map((suco) => {
<SelectItem key={suco.id} value={suco.id}> if (!suco.sucos_id) {
{suco.name} console.error('suco.id is undefined or null', suco);
</SelectItem> return null; // Skip rendering this item if id is not valid
))} }
return (
<SelectItem key={suco.sucos_id} value={suco.sucos_id.toString()}>
{suco.sucos_name}
</SelectItem>
);
})}
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
@ -157,7 +166,7 @@ const SearchDialog = () => {
<br /> <br />
<div className="flex flex-col"> <div className="flex flex-col">
<span className="text-sm form-hint"> <span className="text-sm form-hint">
{aldeias.map((aldeiasID) => aldeiasID.name).join(', ')} {aldeias.map((aldeia) => aldeia.name).join(', ')}
</span> </span>
</div> </div>
</div> </div>

View File

@ -9,8 +9,8 @@ import { useNavigate } from 'react-router';
import axios from 'axios'; import axios from 'axios';
interface SucosProps { interface SucosProps {
id: number; sucos_id: number;
name: string; sucos_name: string;
} }
interface ContextProps { interface ContextProps {