Skip to content

Commit f461693

Browse files
authored
Merge pull request #316 from ioet/277-order-entries-by-start-date
fix: #277 order entries by start_date desc
2 parents 326e2b9 + 2de96a1 commit f461693

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/app/modules/time-clock/store/entry.reducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
9696
}
9797

9898
case EntryActionTypes.CREATE_ENTRY_SUCCESS: {
99+
const entryList = [action.payload, ...state.entryList];
100+
entryList.sort((a, b) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime());
99101
return {
100102
...state,
101103
active: action.payload,
102-
entryList: [action.payload, ...state.entryList],
104+
entryList,
103105
isLoading: false,
104106
createError: false,
105107
message: 'You clocked-in successfully',
@@ -151,9 +153,9 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
151153
const entryList = [...state.entryList];
152154
const index = entryList.findIndex((entry) => entry.id === action.payload.id);
153155
entryList[index] = action.payload;
156+
entryList.sort((a, b) => b.start_date.getTime() - a.start_date.getTime());
154157
return {
155158
...state,
156-
entryList,
157159
isLoading: false,
158160
updateError: false,
159161
};

0 commit comments

Comments
 (0)