refactor(FE): Refactor tab actions store to use a unified implementation

This commit is contained in:
rstubryan
2026-02-23 11:05:11 +07:00
parent 75e9b06a83
commit 7e1166b5e8
18 changed files with 75 additions and 150 deletions
-21
View File
@@ -1,21 +0,0 @@
'use client';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import {
createClosingTabSlice,
ClosingTabSlice,
} from '@/stores/closing/slices/closing-tab.slice';
export type ClosingTabStore = ClosingTabSlice;
export const useClosingTabStore = create<ClosingTabStore>()(
devtools(
(...args) => ({
...createClosingTabSlice(...args),
}),
{
name: 'ClosingTabStore',
}
)
);
@@ -1,37 +0,0 @@
import { ReactNode } from 'react';
import { StateCreator } from 'zustand';
export type ClosingTabSlice = {
// State - actions per tab ID
tabActions: Record<string, ReactNode>;
// Actions
setTabActions: (tabId: string, actions: ReactNode) => void;
clearTabActions: (tabId: string) => void;
clearAllTabActions: () => void;
};
export const createClosingTabSlice: StateCreator<
ClosingTabSlice,
[],
[],
ClosingTabSlice
> = (set) => ({
tabActions: {},
setTabActions: (tabId, actions) =>
set((state) => ({
tabActions: {
...state.tabActions,
[tabId]: actions,
},
})),
clearTabActions: (tabId) =>
set((state) => {
const { [tabId]: _, ...rest } = state.tabActions;
return { tabActions: rest };
}),
clearAllTabActions: () => set({ tabActions: {} }),
});
-21
View File
@@ -1,21 +0,0 @@
'use client';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import {
createReportTabSlice,
ReportTabSlice,
} from '@/stores/report/slices/report-tab.slice';
export type ReportTabStore = ReportTabSlice;
export const useReportTabStore = create<ReportTabStore>()(
devtools(
(...args) => ({
...createReportTabSlice(...args),
}),
{
name: 'ReportTabStore',
}
)
);
@@ -1,37 +0,0 @@
import { ReactNode } from 'react';
import { StateCreator } from 'zustand';
export type ReportTabSlice = {
// State - actions per tab ID
tabActions: Record<string, ReactNode>;
// Actions
setTabActions: (tabId: string, actions: ReactNode) => void;
clearTabActions: (tabId: string) => void;
clearAllTabActions: () => void;
};
export const createReportTabSlice: StateCreator<
ReportTabSlice,
[],
[],
ReportTabSlice
> = (set) => ({
tabActions: {},
setTabActions: (tabId, actions) =>
set((state) => ({
tabActions: {
...state.tabActions,
[tabId]: actions,
},
})),
clearTabActions: (tabId) =>
set((state) => {
const { [tabId]: _, ...rest } = state.tabActions;
return { tabActions: rest };
}),
clearAllTabActions: () => set({ tabActions: {} }),
});
@@ -0,0 +1,42 @@
'use client';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { ReactNode } from 'react';
export type TabActionsSlice = {
// State - actions per tab ID
tabActions: Record<string, ReactNode>;
// Actions
setTabActions: (tabId: string, actions: ReactNode) => void;
clearTabActions: (tabId: string) => void;
clearAllTabActions: () => void;
};
export const useTabActionsStore = create<TabActionsSlice>()(
devtools(
(set) => ({
tabActions: {},
setTabActions: (tabId, actions) =>
set((state) => ({
tabActions: {
...state.tabActions,
[tabId]: actions,
},
})),
clearTabActions: (tabId) =>
set((state) => {
const { [tabId]: _, ...rest } = state.tabActions;
return { tabActions: rest };
}),
clearAllTabActions: () => set({ tabActions: {} }),
}),
{
name: 'TabActionsStore',
}
)
);