update
This commit is contained in:
@ -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(() => {
|
||||
|
||||
@ -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 (
|
||||
|
||||
@ -142,15 +142,17 @@ const ManageAldeiasContextProvider = ({ children }: { children: React.ReactNode
|
||||
|
||||
const getAldeiasLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
||||
try {
|
||||
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
|
||||
const response = await GetData(`${API_URL}/aldeias/list`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: true,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
// console.log(response?.data);
|
||||
console.log(response?.data);
|
||||
setAldeias(response?.data.list);
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
} catch (error) {
|
||||
|
||||
@ -42,6 +42,7 @@ const AddDialog = () => {
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(initialState);
|
||||
setAlert({ show: false, message: '' });
|
||||
};
|
||||
|
||||
const doCreateMunicipio = useCallback(
|
||||
@ -72,7 +73,7 @@ const AddDialog = () => {
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (formField.name === '') {
|
||||
if (formField.name.trim() === '') {
|
||||
setAlert({ show: true, message: 'Please fill name field.' });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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,28 +75,46 @@ 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();
|
||||
|
||||
if (formField.name === '') {
|
||||
if (formField.name.trim() === '') {
|
||||
setAlert({ show: true, message: 'Please fill name field.' });
|
||||
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"
|
||||
|
||||
@ -29,8 +29,8 @@ const ListToolbar = () => {
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search Municipios"
|
||||
value={searchName}
|
||||
onChange={(event) => setSearchName(event.target.value)}
|
||||
value={(table.getColumn('name')?.getFilterValue() as string) ?? ''}
|
||||
onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<DefaultTooltip title={'Filter'} placement={'top'}>
|
||||
|
||||
@ -113,8 +113,9 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) =
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.name,
|
||||
id: 'name',
|
||||
// accessorFn: (row) => row.name,
|
||||
// id: 'name',
|
||||
accessorKey: 'name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Municipios Name" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
@ -159,73 +160,27 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) =
|
||||
try {
|
||||
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
|
||||
const response = await axios.get(`${API_URL}/municipios/list`, {
|
||||
params: {
|
||||
limit: limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
|
||||
}
|
||||
const response = await GetData(`${API_URL}/municipios/list`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
// console.log(response.data);
|
||||
// console.log(response?.data);
|
||||
// const sortedList = response.data.data.list.sort((a: MunicipiosProps, b: MunicipiosProps) => {
|
||||
// if (a.name < b.name) return -1;
|
||||
// if (a.name > b.name) return 1;
|
||||
// return 0;
|
||||
// });
|
||||
setMunicipios(response.data.data.list);
|
||||
return { data: response?.data.data.list, totalCount: response?.data.data.total_count };
|
||||
setMunicipios(response?.data.list);
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
} catch (error) {
|
||||
console.error('Error fetching municipios', error);
|
||||
}
|
||||
};
|
||||
|
||||
const getPostoadmsByMunicipio = async (name: string) => {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/municipios/postoadms/${name}`);
|
||||
const data = response.data;
|
||||
console.log(data);
|
||||
} catch (error) {
|
||||
console.error(`Error fetching municipios by ${name}`, error);
|
||||
}
|
||||
};
|
||||
|
||||
const createMunicipios = async (data: Partial<MunicipiosProps>) => {
|
||||
try {
|
||||
await axios.post(`${API_URL}/municipios/create`, data);
|
||||
// getMunicipiosLists(10, 1, false, 'name', 'ASC');
|
||||
} catch (error) {
|
||||
console.error('Error creating municipios', error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateMunicipios = async (id: number, data: Partial<MunicipiosProps>) => {
|
||||
try {
|
||||
await axios.put(`${API_URL}/update/${id}`, data);
|
||||
// getMunicipiosLists(10, 1, false, 'name', 'ASC');
|
||||
} catch (error) {
|
||||
console.error('Error updating municipios', error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteMunicipios = async (id: number, hardDelete?: boolean) => {
|
||||
try {
|
||||
await axios.delete(`${API_URL}/delete/${id}/${hardDelete}`);
|
||||
// getMunicipiosLists(10, 1, false, 'name', 'ASC');
|
||||
} catch (error) {
|
||||
console.error('Error deleting municipios', error);
|
||||
}
|
||||
};
|
||||
|
||||
const restoreMunicipios = async (id: number) => {
|
||||
try {
|
||||
await axios.put(`${API_URL}/restore/${id}`);
|
||||
// getMunicipiosLists(10, 1, false, 'name', 'ASC');
|
||||
} catch (error) {
|
||||
console.error('Error restoring municipios', error);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<ManageMunicipiosContext.Provider
|
||||
value={{
|
||||
|
||||
@ -80,10 +80,28 @@ 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();
|
||||
|
||||
if (formField.name === '' || formField.municipio_id === 0) {
|
||||
if (formField.name.trim() === '' || formField.municipio_id === 0) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
}
|
||||
@ -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 (
|
||||
|
||||
@ -80,10 +80,45 @@ 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();
|
||||
|
||||
if (formField.name === '' || formField.municipio_id === 0) {
|
||||
if (formField.name.trim() === '' || formField.municipio_id === 0) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -17,9 +17,9 @@ const ListToolbar = () => {
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search Postu"
|
||||
value={(table.getColumn('posto_adms_name')?.getFilterValue() as string) ?? ''}
|
||||
value={(table.getColumn('PostoAdms_name')?.getFilterValue() as string) ?? ''}
|
||||
onChange={(event) =>
|
||||
table.getColumn('posto_adms_name')?.setFilterValue(event.target.value)
|
||||
table.getColumn('PostoAdms_name')?.setFilterValue(event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
|
||||
@ -83,7 +83,7 @@ const SearchDialog = () => {
|
||||
setIsFound(false);
|
||||
setSucos([]);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<Dialog open={showSearchDialog} onOpenChange={handleSearchDialog}>
|
||||
<DialogContent className="container-fixed max-w-[700px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
@ -128,17 +128,17 @@ const SearchDialog = () => {
|
||||
<CommandGroup>
|
||||
{postoAdms.map((postoAdm) => (
|
||||
<CommandItem
|
||||
key={postoAdm.posto_adms_id}
|
||||
value={postoAdm.posto_adms_name}
|
||||
key={postoAdm.PostoAdms_id}
|
||||
value={postoAdm.PostoAdms_name}
|
||||
onSelect={() => {
|
||||
setFormField({
|
||||
id: postoAdm.posto_adms_id,
|
||||
name: postoAdm.posto_adms_name
|
||||
id: postoAdm.PostoAdms_id,
|
||||
name: postoAdm.PostoAdms_name
|
||||
});
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
{postoAdm.posto_adms_name}
|
||||
{postoAdm.PostoAdms_name}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
|
||||
@ -9,8 +9,8 @@ import ListToolbar from '../blocks/ListToolbar';
|
||||
import { useCallApi } from '@/hooks';
|
||||
|
||||
interface PostoAdmsProps {
|
||||
posto_adms_id: number;
|
||||
posto_adms_name: string;
|
||||
PostoAdms_id: number;
|
||||
PostoAdms_name: string;
|
||||
municipios_name: string;
|
||||
}
|
||||
|
||||
@ -84,8 +84,9 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
const columns = useMemo<ColumnDef<any>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorFn: (row) => row.posto_adms_id,
|
||||
id: 'id',
|
||||
// accessorFn: (row) => row.PostoAdms_id,
|
||||
// id: 'PostoAdms_id',
|
||||
accessorKey: 'PostoAdms_id',
|
||||
header: ({ column }) => <DataGridColumnHeader title="ID" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
@ -96,7 +97,7 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
{
|
||||
// accessorFn: (row) => row.posto_adms_name,
|
||||
// id: 'posto_adms_name',
|
||||
accessorKey: 'posto_adms_name',
|
||||
accessorKey: 'PostoAdms_name',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="Posto Administrativo Name" column={column} />
|
||||
),
|
||||
@ -127,13 +128,13 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
<>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleEditDialog(true, row.posto_adms_id)}
|
||||
onClick={() => handleEditDialog(true, row.PostoAdms_id)}
|
||||
>
|
||||
<KeenIcon icon="notepad-edit" />
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleDeleteDialog(true, row.posto_adms_id)}
|
||||
onClick={() => handleDeleteDialog(true, row.PostoAdms_id)}
|
||||
>
|
||||
<KeenIcon icon="trash" />
|
||||
</button>
|
||||
@ -151,16 +152,17 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
|
||||
const getPostoAdmsLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
||||
try {
|
||||
sorting: sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
|
||||
const response = await GetData(`${API_URL}/postoadms/list`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
// console.log(response.data);
|
||||
console.log(response?.data);
|
||||
// const sortedList = response.data.data.list.sort((a: PostoAdmsProps, b: PostoAdmsProps) => {
|
||||
// if (a.name < b.name) return -1;
|
||||
// if (a.name > b.name) return 1;
|
||||
|
||||
@ -71,15 +71,15 @@ const AddDialog = () => {
|
||||
e.preventDefault();
|
||||
|
||||
if (
|
||||
formField.name === '' ||
|
||||
formField.description === '' ||
|
||||
formField.name.trim() === '' ||
|
||||
formField.description.trim() === '' ||
|
||||
formField.price_point === 0 ||
|
||||
formField.price_cash === 0 ||
|
||||
formField.cashback_point === 0 ||
|
||||
formField.cashback_cash === 0 ||
|
||||
formField.status === '' ||
|
||||
formField.created_by === '' ||
|
||||
formField.created_at === ''
|
||||
formField.status.trim() === '' ||
|
||||
formField.created_by.trim() === '' ||
|
||||
formField.created_at.trim() === ''
|
||||
) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
|
||||
@ -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,19 +66,38 @@ 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();
|
||||
|
||||
if (
|
||||
formField.name === '' ||
|
||||
formField.description === '' ||
|
||||
formField.name.trim() === '' ||
|
||||
formField.description.trim() === '' ||
|
||||
formField.price_point === 0 ||
|
||||
formField.price_cash === 0 ||
|
||||
formField.cashback_point === 0 ||
|
||||
formField.cashback_cash === 0 ||
|
||||
formField.status === '' ||
|
||||
formField.updated_by === '' ||
|
||||
formField.updated_at === ''
|
||||
formField.updated_by.trim() === '' ||
|
||||
formField.updated_at.trim() === ''
|
||||
) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
@ -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({
|
||||
|
||||
@ -61,7 +61,7 @@ const AddDialog = () => {
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (formField.name === '') {
|
||||
if (formField.name.trim() === '') {
|
||||
setAlert({ show: true, message: 'Please fill name field.' });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ const EditDialog = () => {
|
||||
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (formField.name === '') {
|
||||
if (formField.name.trim() === '') {
|
||||
setAlert({ show: true, message: 'Please fill name field.' });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -100,12 +100,12 @@ const AddDialog = () => {
|
||||
e.preventDefault();
|
||||
|
||||
if (
|
||||
formField.name === '' ||
|
||||
formField.description === '' ||
|
||||
formField.type === '' ||
|
||||
formField.status === '' ||
|
||||
formField.transactionTypeId === '' ||
|
||||
formField.agentId === ''
|
||||
formField.name.trim() === '' ||
|
||||
formField.description.trim() === '' ||
|
||||
formField.type.trim() === '' ||
|
||||
formField.status.trim() === '' ||
|
||||
formField.transactionTypeId.trim() === '' ||
|
||||
formField.agentId.trim() === ''
|
||||
) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
|
||||
@ -114,12 +114,12 @@ const EditDialog = () => {
|
||||
e.preventDefault();
|
||||
|
||||
if (
|
||||
formField.name === '' ||
|
||||
formField.description === '' ||
|
||||
formField.type === '' ||
|
||||
formField.status === '' ||
|
||||
formField.transactionTypeId === '' ||
|
||||
formField.agentId === ''
|
||||
formField.name.trim() === '' ||
|
||||
formField.description.trim() === '' ||
|
||||
formField.type.trim() === '' ||
|
||||
formField.status.trim() === '' ||
|
||||
formField.transactionTypeId.trim() === '' ||
|
||||
formField.agentId.trim() === ''
|
||||
) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
|
||||
@ -80,7 +80,7 @@ const AddDialog = () => {
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (formField.name === '' || formField.posto_adm_id === 0) {
|
||||
if (formField.name.trim() === '' || formField.posto_adm_id === 0) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ const EditDialog = () => {
|
||||
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (formField.name === '' || formField.posto_adm_id === 0) {
|
||||
if (formField.name.trim() === '' || formField.posto_adm_id === 0) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user