feat(ui): completed ui user multi role with temporary access

This commit is contained in:
Akhil Mohan
2024-03-11 15:09:15 +05:30
parent edbb7e2b1e
commit fa41b8bb47
7 changed files with 595 additions and 128 deletions

View File

@@ -0,0 +1,15 @@
/**
* Sorts an array of items into groups. The return value is a map where the keys are
* the group ids the given getGroupId function produced and the value is an array of
* each item in that group.
*/
export const groupBy = <T, Key extends string | number | symbol>(
array: readonly T[],
getGroupId: (item: T) => Key
): Record<Key, T[]> =>
array.reduce((acc, item) => {
const groupId = getGroupId(item);
if (!acc[groupId]) acc[groupId] = [];
acc[groupId].push(item);
return acc;
}, {} as Record<Key, T[]>);