Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prod Update - GroupMembers title sort #46

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
15 changes: 13 additions & 2 deletions packages/quilombo/components/GroupMembers/GroupMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Spinner } from '@nextui-org/spinner';
import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/table';
import { useAtomValue } from 'jotai';
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';

import { GroupMembersSkeleton } from '@/components/skeletons/GroupSkeletons';
import { TitleEnum } from '@/config/constants';
import {
groupAdminIdsAtom,
groupFounderAtom,
Expand All @@ -27,6 +28,16 @@ const GroupMembers = () => {
(userId: string): GroupMemberRole[] => getGroupMemberRoles(userId, groupFounder, groupLeader, groupAdminIds),
[groupFounder, groupLeader, groupAdminIds],
);
const sortedGroupMembers = useMemo(
() =>
groupMembers?.sort((a, b) => {
if (!a.title && !b.title) return 0;
if (!a.title) return -1;
if (!b.title) return 1;
return TitleEnum[a.title] - TitleEnum[b.title];
}) ?? [],
[groupMembers],
);

const filteredColumns = [...COLUMNS].filter((column) => (isGroupAdmin ? true : column.uid !== 'actions'));

Expand All @@ -42,7 +53,7 @@ const GroupMembers = () => {
)}
</TableHeader>
<TableBody
items={groupMembers}
items={sortedGroupMembers}
isLoading={isPending}
loadingContent={<Spinner label="Loading..." size="sm" color="default" />}
emptyContent="No members found"
Expand Down
20 changes: 13 additions & 7 deletions packages/quilombo/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ import { ImageType } from '@/types/model';
import { ResizeOptions } from 'sharp';

export const titles = [
'mestre',
'mestra',
'contra-mestre',
'mestre',
'contra-mestra',
'mestrando',
'contra-mestre',
'mestranda',
'professor',
'mestrando',
'professora',
'instrutor',
'professor',
'instrutora',
'monitor',
'instrutor',
'monitora',
'aluno',
'monitor',
'aluna',
'aluno',
'iniciante',
] as const;

// used to sort titles in the UI
export const TitleEnum = titles.reduce<Record<string, number>>((acc, title, index) => {
acc[title] = index;
return acc;
}, {});

export const styles = ['angola', 'regional', 'contemporânea'] as const;

export const linkTypes = ['twitter', 'facebook', 'instagram', 'linkedin'] as const;
Expand Down
4 changes: 4 additions & 0 deletions packages/quilombo/db/migrations/0011_overrated_cloak.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE "public"."users" ALTER COLUMN "title" SET DATA TYPE text;--> statement-breakpoint
DROP TYPE "public"."title";--> statement-breakpoint
CREATE TYPE "public"."title" AS ENUM('mestra', 'mestre', 'contra-mestra', 'contra-mestre', 'mestranda', 'mestrando', 'professora', 'professor', 'instrutora', 'instrutor', 'monitora', 'monitor', 'aluna', 'aluno', 'iniciante');--> statement-breakpoint
ALTER TABLE "public"."users" ALTER COLUMN "title" SET DATA TYPE "public"."title" USING "title"::"public"."title";
Loading