Currently, I am using ngrx to manage the state in my application. I recently attempted to introduce a new property called selected shifts which should have a specific structure.
state: {
shifts: {
selectedShifts: [
[employeeId]: [
[shiftId]: shift
]
]
}
}
However, my current state setup is different:
state: {
selectedShifts: {
[employeeId]: {
[shiftId]: shift
}
}
}
This difference in structure has made it challenging for me to manipulate and interact with the state as intended.
I have made an attempt to modify the reducer logic like this:
return {
...state,
selectedShifts: {
...state.selectedShifts,
[action.payload.employeeId]: {
...state.selectedShifts[action.payload.employeeId],
[action.payload.shiftId]: action.payload[shift.shiftId]
}
}
};
However, when I try to view the state after these changes, it appears like this:
state: {
selectedShifts: {
[action.payload.employeeId]:
[0]: {[action.payload.shiftId]: { shift }}
}
}
I am encountering an issue where the {} symbols are not being replaced by [], resulting in an error message mentioning that a "," is expected.
Additionally, I would prefer for the index of the array to be based on the specific shift's id rather than numerical values such as [0], [1].
Is it feasible to achieve this desired structure? Would changing the index from numeric values to the actual shift's id pose any drawbacks?