delete chain logic
This commit is contained in:
parent
d380f259b1
commit
7eefcecdb5
6
src/entities/chain/api/delete.ts
Normal file
6
src/entities/chain/api/delete.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { getAxios } from "@/shared/lib/getAxios";
|
||||
|
||||
export async function deleteChainById(id: string) {
|
||||
const axios = getAxios();
|
||||
await axios.delete(`/chain/delete/${id}`);
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ interface ChainState {
|
|||
addChain: (chain: Chain) => void;
|
||||
getChain: (id: string) => Chain | null;
|
||||
updateChain: (chain: Chain) => void;
|
||||
deleteChain: (id: string) => void;
|
||||
}
|
||||
|
||||
export const useChainState = create<ChainState>((set, get) => ({
|
||||
|
|
@ -43,4 +44,19 @@ export const useChainState = create<ChainState>((set, get) => ({
|
|||
],
|
||||
};
|
||||
}),
|
||||
|
||||
deleteChain: (id) =>
|
||||
set((state) => {
|
||||
const chains = state.chains;
|
||||
if (!chains) return state;
|
||||
const chainIndex = chains.findIndex((value) => value._id === id);
|
||||
if (chainIndex === -1) return state;
|
||||
|
||||
return {
|
||||
chains: [
|
||||
...chains.slice(0, chainIndex),
|
||||
...chains.slice(chainIndex + 1),
|
||||
],
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user