mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +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';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
import Tabs from '@/components/Tabs';
|
import Tabs from '@/components/Tabs';
|
||||||
|
|
||||||
import { useTabActionsStore } from '@/stores/tab-actions/tab-actions.store';
|
import { useTabActionsStore } from '@/stores/tab-actions/tab-actions.store';
|
||||||
import ReportExpenseTab from '@/components/pages/report/expense/tab/ReportExpenseTab';
|
import ReportExpenseTab from '@/components/pages/report/expense/tab/ReportExpenseTab';
|
||||||
import ReportDepreciationTab from '@/components/pages/report/expense/tab/ReportDepreciationTab';
|
import ReportDepreciationTab from '@/components/pages/report/expense/tab/ReportDepreciationTab';
|
||||||
|
|
||||||
|
const VALID_TAB_IDS = ['operational-expense', 'depreciation'];
|
||||||
|
|
||||||
const ReportExpenseTabs = () => {
|
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 tabActions = useTabActionsStore((state) => state.tabActions);
|
||||||
|
|
||||||
|
const handleTabChange = (tabId: string) => {
|
||||||
|
router.push(`${pathname}?tab=${tabId}`);
|
||||||
|
};
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: 'operational-expense',
|
||||||
label: 'Laporan Biaya Operasional',
|
label: 'Laporan Biaya Operasional',
|
||||||
content: <ReportExpenseTab tabId={'1'} />,
|
content: <ReportExpenseTab tabId={'operational-expense'} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: 'depreciation',
|
||||||
label: 'Laporan Depresiasi',
|
label: 'Laporan Depresiasi',
|
||||||
content: <ReportDepreciationTab tabId={'2'} />,
|
content: <ReportDepreciationTab tabId={'depreciation'} />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -30,7 +42,7 @@ const ReportExpenseTabs = () => {
|
|||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
variant='boxed'
|
variant='boxed'
|
||||||
activeTabId={activeTabId}
|
activeTabId={activeTabId}
|
||||||
onTabChange={setActiveTabId}
|
onTabChange={handleTabChange}
|
||||||
className={{
|
className={{
|
||||||
tabHeaderWrapper:
|
tabHeaderWrapper:
|
||||||
'justify-between items-center p-3 border-b border-base-content/10',
|
'justify-between items-center p-3 border-b border-base-content/10',
|
||||||
|
|||||||
Reference in New Issue
Block a user