Merge branch 'alwi'

This commit is contained in:
Wikzyy
2025-03-18 10:49:05 +07:00
8 changed files with 217 additions and 96 deletions

View File

@ -78,6 +78,24 @@ const AddDialog = () => {
[formField]
);
const doFetchSucos = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/sucos/list`, {
limit: 1000,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('SUCOS', response?.data);
setSucos(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -102,25 +120,7 @@ const AddDialog = () => {
}, [formattedTime]);
useEffect(() => {
const fetchSucos = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/sucos/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('SUCOS', response?.data);
setSucos(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
fetchSucos([{ id: 'name', desc: false }]);
doFetchSucos([{ id: 'name', desc: false }]);
}, []);
useEffect(() => {

View File

@ -77,6 +77,42 @@ const EditDialog = () => {
[selectedAldeias, formField]
);
const doFetchSucos = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/sucos/list`, {
limit: 1000,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('SUCOS', response?.data);
setSucos(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/aldeias/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name,
sucos_id: response.data.sucos.id
}));
} else {
setFormField((prev) => ({
...prev,
name: '',
sucos_id: 0
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -90,6 +126,18 @@ const EditDialog = () => {
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (selectedAldeias) {
doFetchData(selectedAldeias);
}
}, [selectedAldeias]);
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (showEditDialog) {
setFormField({
@ -101,25 +149,7 @@ const EditDialog = () => {
}, [formattedTime]);
useEffect(() => {
const fetchSucos = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/sucos/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('SUCOS', response?.data);
setSucos(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
fetchSucos([{ id: 'name', desc: false }]);
doFetchSucos([{ id: 'name', desc: false }]);
}, []);
return (

View File

@ -25,7 +25,7 @@ const EditDialog = () => {
const { showEditDialog, handleEditDialog, selectedMunicipios, municipios } =
useManageMunicipiosContext();
const { reload } = useDataGrid();
const { PutData } = useCallApi();
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const [alert, setAlert] = useState({
show: false,
@ -44,6 +44,7 @@ const EditDialog = () => {
const resetForm = () => {
setFormField(initialState);
setAlert({ show: false, message: '' });
};
const doUpdateMunicipios = useCallback(
@ -74,6 +75,22 @@ const EditDialog = () => {
[selectedMunicipios, formField]
);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/municipios/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name
}));
} else {
setFormField((prev) => ({
...prev,
name: ''
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -82,20 +99,22 @@ const EditDialog = () => {
return;
}
// setFormField({
// name: formField.name,
// created_by: parsedUser.email,
// created_at: formattedTime
// });
doUpdateMunicipios(e);
console.log(formField);
setAlert({ show: false, message: '' });
};
// const doFetchMunicipios = useCallback(async (id: string) => {
// const response = await axios.get(`${API_URL}/municipios/${id}`);
// }, []);
useEffect(() => {
if (selectedMunicipios) {
doFetchData(selectedMunicipios);
}
}, [selectedMunicipios]);
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedMunicipios) {
@ -127,7 +146,9 @@ const EditDialog = () => {
<div className="card-body grid gap-5">
<div className="w-full">
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label className="form-label flex items-center gap-1 max-w-56">Name</label>
<label className="form-label flex items-center gap-1 max-w-56">
Name<span className="text-red-500">*</span>
</label>
<Input
className="input"
type="text"

View File

@ -80,6 +80,24 @@ const AddDialog = () => {
[formField]
);
const doFetchMunicipios = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -110,25 +128,7 @@ const AddDialog = () => {
}, [showAddDialog]);
useEffect(() => {
const fetchMunicipios = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
fetchMunicipios([{ id: 'name', desc: false }]);
doFetchMunicipios([{ id: 'name', desc: false }]);
}, []);
return (

View File

@ -80,6 +80,41 @@ const EditDialog = () => {
[selectedPostoAdms, formField]
);
const doFetchMunicipios = useCallback(async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('MUNICIPIOS: ', response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
}, []);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/postoadms/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name,
municipio_id: response.data.municipios.id
}));
} else {
setFormField((prev) => ({
...prev,
name: ''
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -93,6 +128,18 @@ const EditDialog = () => {
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedPostoAdms) {
doFetchData(selectedPostoAdms);
}
}, [selectedPostoAdms]);
useEffect(() => {
if (selectedPostoAdms) {
setFormField({
@ -104,25 +151,7 @@ const EditDialog = () => {
}, [formattedTime]);
useEffect(() => {
try {
const fetchMunicipios = async (sorting: any) => {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
};
fetchMunicipios([{ id: 'name', desc: false }]);
} catch (error) {
console.error('Error fetching municipios', error);
}
doFetchMunicipios([{ id: 'name', desc: false }]);
}, []);
// console.log(selectedPostoAdms);

View File

@ -20,7 +20,7 @@ const API_URL = apiConfig.service_master_data;
const EditDialog = () => {
const { showEditDialog, handleEditDialog, selectedProducts } = useManageProductsContext();
const { reload } = useDataGrid();
const { PutData } = useCallApi();
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const created_time = new Date();
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
@ -66,6 +66,25 @@ const EditDialog = () => {
[selectedProducts, formField]
);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/product/getdata/${selectedProducts}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name,
description: response.data.description,
price_point: response.data.price_point,
price_cash: response.data.price_cash,
cashback_point: response.data.cashback_point,
cashback_cash: response.data.cashback_cash,
status: response.data.status
}));
} else {
setFormField(initialState);
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -89,6 +108,18 @@ const EditDialog = () => {
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedProducts) {
doFetchData(selectedProducts);
}
}, [selectedProducts]);
useEffect(() => {
if (showEditDialog) {
setFormField({

View File

@ -85,11 +85,16 @@ const ManagePositionContextProvider = ({ children }: { children: React.ReactNode
enableSorting: false,
enableHiding: false,
cell: ({ row }) => {
const isActive = row.original.status === 'Y';
return (
<EnforceSwitch
enforce={row.original.status == 'Y' ? true : false}
onChange={() => {}}
/>
<span
className={`px-2 py-1 text-xs font-semibold rounded-full ${
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
}`}
>
{isActive ? 'Active' : 'Inactive'}
</span>
);
},
meta: {

View File

@ -127,11 +127,16 @@ const ManageUserContextProvider = ({ children }: { children: React.ReactNode })
enableSorting: false,
enableHiding: false,
cell: ({ row }) => {
const isActive = row.original.status === 'Y';
return (
<EnforceSwitch
enforce={row.original.status == 'Y' ? true : false}
onChange={() => {}}
/>
<span
className={`px-2 py-1 text-xs font-semibold rounded-full ${
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
}`}
>
{isActive ? 'Active' : 'Inactive'}
</span>
);
},
meta: {