Hello everyone, I am facing an issue with implementing an entity that includes another entity within the interface. Please excuse any grammatical errors in my English. I am currently having trouble updating the child entity and I'm not sure if there is a mistake in the code or if I am approaching it correctly.
Is it advisable to have nested states in NgRx? Apologies for my limited understanding; I am new to using NgRx and Angular.
https://i.sstatic.net/nyqvC.png
// Here, I am passing the parent id and the data I need to update in the nested child data
export const TestUpdate = createAction(
'[testtttt] Load WorkFromHomes Description Success',
props<{ id: number; WorkFromHomeDescription }>()
);
export interface WorkFromHomeDescription {
id: number;
wfmId: number;
day: Date;
awaDescription: string;
startTime: string;
endTime: string;
targetDeliverables: string;
accomplishment: string;
evidence: string;
createdBy?: any;
dateCreated?: any;
modifiedBy: number;
dateModified: Date;
employeeId: number;
}
export interface WorkFromHome {
id: number;
wfmStart: Date;
wfmEnd: Date;
employeeId: number;
immediateSupervisorId: number;
vpId: number;
isApprove: boolean;
createdBy?: any;
dateCreated?: any;
modifiedBy: number;
dateModified: Date;
workFromHomeDescriptions: EntityState<WorkFromHomeDescription>;
}
export interface WorkFromHomeState extends EntityState<WorkFromHome> {
loaded: boolean;
loading: boolean;
error: string | null;
}
export const adapter: EntityAdapter<WorkFromHome> = createEntityAdapter<WorkFromHome>();
export const adapterWorkDesc: EntityAdapter<WorkFromHomeDescription> = createEntityAdapter<WorkFromHomeDescription>();
export const initialState: WorkFromHomeState = adapter.getInitialState({
loaded: false,
loading: false,
error: null,
});
export const WorkFromHomeReducer = createReducer(
initialState,
on(WorkFromHomeAction.test, (state, action) => {
const workdata = action.WorkFromHomeDescription;
return adapter.mapOne(
{
id: action.id,
map: data => ({
...data,
workFromHomeDescriptions: adapterWorkDesc.updateOne(
{
id: workdata.id,
...workdata,
},
data.workFromHomeDescriptions
),
}),
},
state
);
})
);