mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Add zustand store for marketing tab actions
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode } from 'react';
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
export type MarketingTabActionsSlice = {
|
||||
// State - actions per tab ID
|
||||
tabActions: Record<string, ReactNode>;
|
||||
|
||||
// Actions
|
||||
setTabActions: (tabId: string, actions: ReactNode) => void;
|
||||
clearTabActions: (tabId: string) => void;
|
||||
clearAllTabActions: () => void;
|
||||
};
|
||||
|
||||
export const useMarketingTabStore = create<MarketingTabActionsSlice>()(
|
||||
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: 'MarketingTabStore',
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user