diff --git a/src/entities/chain/model.ts b/src/entities/chain/model.ts index a6c6e1e..43cea6f 100644 --- a/src/entities/chain/model.ts +++ b/src/entities/chain/model.ts @@ -12,6 +12,7 @@ interface ChainState { updateChain: (chain: Chain) => void; deleteChain: (id: string) => void; addCommentAction: (chainId: string, action: Action) => void; + updateAction: (chainId: string, actionIndex: number, action: Action) => void; } export const useChainState = create((set, get) => ({ @@ -88,4 +89,22 @@ export const useChainState = create((set, get) => ({ chains[chainIndex].actions = actions; return state; }), + + updateAction: (chainId, actionIndex, action) => + set((state) => { + const chains = state.chains; + if (!chains) return state; + + const chain = state.getChain(chainId); + + if ( + !chain || + typeof chain.actions === "undefined" || + !chain.actions[actionIndex] + ) + return state; + + chain.actions[actionIndex] = action; + return state; + }), }));