Merge branch 'alwi'
This commit is contained in:
@ -136,7 +136,7 @@ const EditDialog = () => {
|
||||
description: response?.data.description,
|
||||
type: response?.data.type,
|
||||
status: response?.data.status,
|
||||
transactionTypeId: response?.data.transactionTypeId,
|
||||
transactionTypeId: response?.data.transaction_type.id,
|
||||
agent: response?.data.agent
|
||||
}));
|
||||
}
|
||||
|
||||
@ -16,21 +16,21 @@ const ListToolbar = () => {
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search Menu"
|
||||
value={(table.getColumn('subMenu')?.getFilterValue() as string) ?? ''}
|
||||
onChange={(event) => table.getColumn('subMenu')?.setFilterValue(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'}>
|
||||
{/* <DefaultTooltip title={'Filter'} placement={'top'}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-7.5 disabled:bg-gray-400"
|
||||
// disabled={isLoading}
|
||||
// onClick={handleFilterData}
|
||||
>
|
||||
{/* {loadingButton === 'filter' ? <ContentLoader /> : <KeenIcon icon="filter" />} */}
|
||||
{loadingButton === 'filter' ? <ContentLoader /> : <KeenIcon icon="filter" />}
|
||||
<KeenIcon icon="filter" />
|
||||
</Button>
|
||||
</DefaultTooltip>
|
||||
</DefaultTooltip> */}
|
||||
</div>
|
||||
<div className="flex gap-3 items-center">
|
||||
<Button
|
||||
|
||||
@ -118,7 +118,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.name,
|
||||
id: 'subMenu',
|
||||
id: 'name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Sub Menu" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
@ -174,15 +174,31 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
);
|
||||
|
||||
const flattenChildren = (parent: any, parentIdx: number, depth = 0, parentName = '') => {
|
||||
let result: any[] = [];
|
||||
|
||||
if (parent.link === '/') {
|
||||
if (!parents.find((el: any) => el.id === parent.id))
|
||||
setParents((el: any) => [...el, { id: parent.id, name: parent.name }]); // GET PARENTS
|
||||
}
|
||||
if (!parent.children || parent.children.length === 0) {
|
||||
return []; // Jika tidak ada children, kembalikan array kosong
|
||||
|
||||
// Menambahkan parent ke dalam result meskipun tidak memiliki children
|
||||
result.push({
|
||||
id: parent.id,
|
||||
module: parent.module,
|
||||
parentName: parentName || parent.name,
|
||||
name: parent.name,
|
||||
link: parent.link,
|
||||
id_parent: parent.id_parent,
|
||||
status: parent.status,
|
||||
order_number: parent.order_number
|
||||
});
|
||||
}
|
||||
|
||||
return parent.children.flatMap((child: any, childIdx: number) => {
|
||||
// Jika parent tidak memiliki children, langsung return hasil yang sudah ada
|
||||
if (!parent.children || parent.children.length === 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const childrenFlattened = parent.children.flatMap((child: any, childIdx: number) => {
|
||||
if (child.children && child.children.length > 0) {
|
||||
return flattenChildren(child, parentIdx * 100 + childIdx, depth + 1, child.name);
|
||||
}
|
||||
@ -198,6 +214,9 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
order_number: parent.order_number
|
||||
};
|
||||
});
|
||||
|
||||
// Gabungkan parent dengan children yang sudah diflatten
|
||||
return [...result, ...childrenFlattened];
|
||||
};
|
||||
|
||||
const getMenusLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
||||
@ -210,7 +229,8 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
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)
|
||||
});
|
||||
|
||||
if (!response?.data.list) return { data: [], totalCount: 0 };
|
||||
@ -220,10 +240,11 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
);
|
||||
|
||||
const total_count = transformedData.length;
|
||||
const paginatedData = transformedData.slice(page * limit, (page + 1) * limit);
|
||||
|
||||
console.log(response.data);
|
||||
setMenus(transformedData);
|
||||
return { data: transformedData, totalCount: response.data.total_count };
|
||||
// setMenus(transformedData);
|
||||
return { data: paginatedData, totalCount: total_count };
|
||||
} catch (error) {
|
||||
console.error('Error fetching Menus', error);
|
||||
return { data: [], totalCount: 0 };
|
||||
@ -250,7 +271,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
||||
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 30 }}
|
||||
pagination={{ size: 25 }}
|
||||
toolbar={<ListToolbar />}
|
||||
layout={{ card: true }}
|
||||
sorting={[{ id: 'id', desc: false }]}
|
||||
|
||||
@ -35,16 +35,22 @@ const EditDialog = () => {
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
const [formField, setFormField] = useState({
|
||||
const initialState = {
|
||||
name: '',
|
||||
username: '',
|
||||
email: '',
|
||||
id_role: '',
|
||||
id_role_old: '',
|
||||
status: ''
|
||||
});
|
||||
};
|
||||
const [formField, setFormField] = useState(initialState);
|
||||
|
||||
/* actions */
|
||||
const doResetForm = () => {
|
||||
setAlert({ show: false, message: '' });
|
||||
setFormField(initialState);
|
||||
};
|
||||
|
||||
const doUpdateUser = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
@ -103,6 +109,12 @@ const EditDialog = () => {
|
||||
}
|
||||
}, [selectedUser]);
|
||||
|
||||
useEffect(() => {
|
||||
if (showEditDialog === false) {
|
||||
doResetForm();
|
||||
}
|
||||
}, [showEditDialog]);
|
||||
|
||||
return (
|
||||
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
|
||||
@ -22,17 +22,17 @@ const ListToolBar = () => {
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<DefaultTooltip title={'Filter'} placement={'top'}>
|
||||
{/* <DefaultTooltip title={'Filter'} placement={'top'}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-7.5 disabled:bg-gray-400"
|
||||
// disabled={isLoading}
|
||||
// onClick={handleFilterData}
|
||||
>
|
||||
{/* {loadingButton === 'filter' ? <ContentLoader /> : <KeenIcon icon="filter" />} */}
|
||||
{loadingButton === 'filter' ? <ContentLoader /> : <KeenIcon icon="filter" />}
|
||||
<KeenIcon icon="filter" />
|
||||
</Button>
|
||||
</DefaultTooltip>
|
||||
</DefaultTooltip> */}
|
||||
</div>
|
||||
<div className="flex gap-3 items-center">
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user