mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-22 06:15:47 +00:00
feat: implement url query param tab navigation
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||
|
||||
const Layout = ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
@@ -1,26 +1,38 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import Tabs from '@/components/Tabs';
|
||||
|
||||
import { useTabActionsStore } from '@/stores/tab-actions/tab-actions.store';
|
||||
import ReportExpenseTab from '@/components/pages/report/expense/tab/ReportExpenseTab';
|
||||
import ReportDepreciationTab from '@/components/pages/report/expense/tab/ReportDepreciationTab';
|
||||
|
||||
const VALID_TAB_IDS = ['operational-expense', 'depreciation'];
|
||||
|
||||
const ReportExpenseTabs = () => {
|
||||
const [activeTabId, setActiveTabId] = useState<string>('1');
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const tabParam = searchParams.get('tab') ?? 'operational-expense';
|
||||
const activeTabId = VALID_TAB_IDS.includes(tabParam)
|
||||
? tabParam
|
||||
: 'operational-expense';
|
||||
const tabActions = useTabActionsStore((state) => state.tabActions);
|
||||
|
||||
const handleTabChange = (tabId: string) => {
|
||||
router.push(`${pathname}?tab=${tabId}`);
|
||||
};
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
id: '1',
|
||||
id: 'operational-expense',
|
||||
label: 'Laporan Biaya Operasional',
|
||||
content: <ReportExpenseTab tabId={'1'} />,
|
||||
content: <ReportExpenseTab tabId={'operational-expense'} />,
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
id: 'depreciation',
|
||||
label: 'Laporan Depresiasi',
|
||||
content: <ReportDepreciationTab tabId={'2'} />,
|
||||
content: <ReportDepreciationTab tabId={'depreciation'} />,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -30,7 +42,7 @@ const ReportExpenseTabs = () => {
|
||||
tabs={tabs}
|
||||
variant='boxed'
|
||||
activeTabId={activeTabId}
|
||||
onTabChange={setActiveTabId}
|
||||
onTabChange={handleTabChange}
|
||||
className={{
|
||||
tabHeaderWrapper:
|
||||
'justify-between items-center p-3 border-b border-base-content/10',
|
||||
|
||||
Reference in New Issue
Block a user