From 898d6fb7fc65fa20d3b07230eb522ddf969f9d28 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Mon, 27 May 2024 20:57:17 +0300 Subject: [PATCH] Fix users order --- .../frontend/src/context/UsersContext.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/rsconcept/frontend/src/context/UsersContext.tsx b/rsconcept/frontend/src/context/UsersContext.tsx index 50f83cc1..d404c453 100644 --- a/rsconcept/frontend/src/context/UsersContext.tsx +++ b/rsconcept/frontend/src/context/UsersContext.tsx @@ -41,7 +41,7 @@ export const UsersState = ({ children }: UsersStateProps) => { if (!hasFirstName) { return user.last_name; } - return user.first_name + ' ' + user.last_name; + return user.last_name + ' ' + user.first_name; } return `Аноним ${userID}`; } @@ -52,6 +52,25 @@ export const UsersState = ({ children }: UsersStateProps) => { showError: true, onError: () => setUsers([]), onSuccess: newData => { + newData.sort((a, b) => { + if (a.last_name === '') { + if (b.last_name === '') { + return a.id - b.id; + } else { + return 1; + } + } else if (b.last_name === '') { + if (a.last_name === '') { + return a.id - b.id; + } else { + return -1; + } + } else if (a.last_name !== b.last_name) { + return a.last_name.localeCompare(b.last_name); + } else { + return a.first_name.localeCompare(b.first_name); + } + }); setUsers(newData); if (callback) callback(); }