Update CreateServer logic so that it ensures a unique human-friendly ID is set

This commit is contained in:
Alejandro Celaya
2024-11-01 10:27:35 +01:00
parent 9134d07969
commit e786f9d21f
7 changed files with 76 additions and 47 deletions

View File

@@ -1,7 +1,7 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
import type { ServerData, ServersMap, ServerWithId } from '../data';
import { serversListToMap, serverWithId } from '../helpers';
import { serversListToMap } from '../helpers';
interface EditServer {
serverId: string;
@@ -57,10 +57,7 @@ export const { actions, reducer } = createSlice({
},
},
createServers: {
prepare: (servers: ServerData[]) => {
const payload = serversListToMap(servers.map(serverWithId));
return { payload };
},
prepare: (servers: ServerWithId[]) => ({ payload: serversListToMap(servers) }),
reducer: (state, { payload: newServers }: PayloadAction<ServersMap>) => ({ ...state, ...newServers }),
},
},