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