mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { ReactNode } from 'react';
|
|
import { create } from 'zustand';
|
|
import { devtools } from 'zustand/middleware';
|
|
|
|
export type FinanceTabActionsSlice = {
|
|
// State - actions per tab ID
|
|
tabActions: Record<string, ReactNode>;
|
|
|
|
// Actions
|
|
setTabActions: (tabId: string, actions: ReactNode) => void;
|
|
clearTabActions: (tabId: string) => void;
|
|
clearAllTabActions: () => void;
|
|
};
|
|
|
|
export const useFinanceTabStore = create<FinanceTabActionsSlice>()(
|
|
devtools(
|
|
(set) => ({
|
|
tabActions: {},
|
|
|
|
setTabActions: (tabId, actions) =>
|
|
set(
|
|
(state) => ({
|
|
tabActions: {
|
|
...state.tabActions,
|
|
[tabId]: actions,
|
|
},
|
|
}),
|
|
false,
|
|
'setTabActions'
|
|
),
|
|
|
|
clearTabActions: (tabId) =>
|
|
set(
|
|
(state) => {
|
|
const { [tabId]: _, ...rest } = state.tabActions;
|
|
return { tabActions: rest };
|
|
},
|
|
false,
|
|
'clearTabActions'
|
|
),
|
|
|
|
clearAllTabActions: () =>
|
|
set({ tabActions: {} }, false, 'clearAllTabActions'),
|
|
}),
|
|
{
|
|
name: 'FinanceTabStore',
|
|
}
|
|
)
|
|
);
|