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

Release 2.5.2 #576

Merged
merged 17 commits into from
May 28, 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
9 changes: 8 additions & 1 deletion packages/api/src/types/CommentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export type GetCommentsRequest = {
optionId: string;
};

export type GetCommentsResponse = (Comment & { user?: { id: string; username: string } })[];
export type GetCommentsResponse = (Comment & {
user?: {
id: string;
username: string;
firstName: string;
lastName: string;
};
})[];

export type PostCommentRequest = {
value: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/berlin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ const router = (queryClient: QueryClient) =>
loader: ({ params }) =>
redirectToCycleIfOpen(queryClient, params.eventId, params.cycleId),
path: ':cycleId/results',
loader: ({ params }) =>
redirectToCycleIfOpen(queryClient, params.eventId, params.cycleId),
Component: Results,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Card = styled(Grid)`
grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) 56px;
@media (min-width: 600px) {
grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) minmax(100px, 150px) 56px;
grid-template-columns: minmax(200px, 600px) minmax(100px, 200px) minmax(80px, 100px) 56px;
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Members = styled(Body)`
font-weight: bold;
`;

export const Secret = styled(Body)`
export const AccessCode = styled(Body)`
font-weight: bold;
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Action, Card, Group, Members, Secret } from './GroupsColumns.styled';
import { Action, Card, Group, Members, AccessCode } from './GroupsColumns.styled';

function GroupsColumns() {
return (
<Card>
<Group>Group</Group>
<Members>Members</Members>
<Secret>Secret</Secret>
<AccessCode>Access Code</AccessCode>
<Action>Action</Action>
</Card>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/berlin/src/components/header/Header.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const ThemeButton = styled(Button)`
}
`;

export const MenuButton = styled.div`
export const MenuButton = styled.li`
align-items: center;
cursor: pointer;
display: flex;
Expand Down
21 changes: 11 additions & 10 deletions packages/berlin/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@ function Header() {
onClick={() => navigate('/account')}
icon={{ src: `/icons/user-${theme}.svg`, alt: 'User' }}
$color="primary"
$height={20}
$width={20}
/>
</>
) : (
<ZupassLoginButton>Login with Zupass</ZupassLoginButton>
)}
</DesktopButtons>
<li>
<MenuButton onClick={() => setIsBurgerMenuOpen(!isBurgerMenuOpen)}>
<Bar $isOpen={isBurgerMenuOpen} />
<Bar $isOpen={isBurgerMenuOpen} />
<Bar $isOpen={isBurgerMenuOpen} />
</MenuButton>
</li>
<MenuButton onClick={() => setIsBurgerMenuOpen(!isBurgerMenuOpen)}>
<Bar $isOpen={isBurgerMenuOpen} />
<Bar $isOpen={isBurgerMenuOpen} />
<Bar $isOpen={isBurgerMenuOpen} />
</MenuButton>
<li>
<ThemeButton onClick={toggleTheme}>
<img
Expand Down Expand Up @@ -182,14 +182,15 @@ function Header() {
)
);
})}
<NavButton to={`/events/${events?.[0].id}/register`} $color="secondary">
My proposals
</NavButton>
<NavButton to={`/events/${events?.[0].id}/cycles`} $color="secondary">
Agenda
</NavButton>
</>
)}
<NavButton to={`/events/${events?.[0].id}/register`} $color="secondary">
My proposals
</NavButton>

<NavButton to="/account" $color="secondary">
Account
</NavButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ export const Card = styled(Grid)`
grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) 56px;
@media (min-width: 600px) {
grid-template-columns: minmax(200px, 600px) minmax(100px, 150px) minmax(100px, 150px) 56px;
grid-template-columns: minmax(200px, 600px) minmax(100px, 200px) minmax(80px, 100px) 56px;
}
`;

export const Comment = styled(Body)``;

export const Author = styled(Body)`
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
`;

export const FormattedDate = styled(Body)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
const currentUserLiked = commentLikes.some((like) => like.userId === user?.id);
setIsCommentLiked(currentUserLiked);
}
}, [commentLikes]);

Check warning on line 56 in packages/berlin/src/components/tables/comment-table/CommentsTable.tsx

View workflow job for this annotation

GitHub Actions / Check linting

React Hook useEffect has a missing dependency: 'user?.id'. Either include it or remove the dependency array

const { mutate: postLikeMutation } = useMutation({
mutationFn: postLike,
Expand Down Expand Up @@ -99,11 +99,13 @@
};

return (
<Card $columns={4}>
<Card>
<FlexRow>
<Comment>{comment.value}</Comment>
</FlexRow>
<Author>@{comment.user?.username}</Author>
<Author title={`@${comment.user?.username}`}>
{comment.user?.firstName} {comment.user?.lastName}
</Author>
<FormattedDate>{formattedDate}</FormattedDate>
<FlexRow
$gap="0.5rem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function ResultsTable({ $expanded, option, onClick }: ResultsTableProps) {
<Bold>Distinct groups:</Bold> {option.distinctGroups}
</Body>
<Body>
<Bold>Group names:</Bold> {option.listOfGroupNames.join(', ')}
<Bold>Voter affiliations:</Bold> {option.listOfGroupNames.join(', ')}
</Body>
</FlexColumn>
</Card>
Expand Down
30 changes: 17 additions & 13 deletions packages/berlin/src/data/groups.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
const groups = {
create: {
subtitle: 'Create a Research Group',
subtitle: 'Create a Group',
body: [
{
id: 0,
text: 'Share the access code with your collaborators so they can join your group',
text: 'Share the access code with your collaborators',
},
{
id: 1,
text: 'Any group member can assign a proposal to this group from My Proposals',
text: 'Any group member can assign their proposal to this group',
},
],
buttonText: 'Create group',
buttonText: 'Create',
dialog: {
actionButtonText: 'Create group',
actionButtonText: 'Create',
form: {
input: {
placeholder: 'Research group name',
requiredMessage: 'Research group name must be 2 characters long or more',
placeholder: 'Group name',
requiredMessage: 'Group name must be 2 characters long or more',
},
buttonText: 'Create group',
buttonText: 'Create',
},
buttonText: 'Create group',
buttonText: 'Create',
},
},
join: {
subtitle: 'Join a Research Group',
body: [],
subtitle: 'Join a Group',
body: [
{
id: 0,
text: 'Ask the group creator for the access code',
},
],
input: {
label: 'Ask the group creator for the access code',
placeholder: 'Enter access code',
requiredMessage: 'Access code is required',
},
buttonText: 'Join group',
buttonText: 'Join',
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/berlin/src/pages/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Account() {
});

const { data: usersToGroups, isLoading: userGroupsIsLoading } = useQuery({
queryKey: ['user', user?.id, 'groups'],
queryKey: ['user', user?.id, 'users-to-groups'],
queryFn: () => fetchUsersToGroups(user?.id || ''),
enabled: !!user?.id,
});
Expand Down
35 changes: 33 additions & 2 deletions packages/berlin/src/pages/Cycle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// React and third-party libraries
import { useEffect, useMemo, useState } from 'react';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import toast from 'react-hot-toast';

// API
Expand Down Expand Up @@ -40,14 +40,16 @@

function Cycle() {
const queryClient = useQueryClient();

const navigate = useNavigate();
const { user } = useUser();
const { eventId, cycleId } = useParams();
const { data: cycle } = useQuery({
queryKey: ['cycles', cycleId],
queryFn: () => fetchCycle(cycleId || ''),
enabled: !!cycleId,
refetchInterval: 5000, // Poll every 5 seconds
});

const { data: userVotes } = useQuery({
queryKey: ['votes', cycleId],
queryFn: () => fetchUserVotes(cycleId || ''),
Expand All @@ -72,6 +74,13 @@
order: 'desc',
});

useEffect(() => {
if (cycle?.status === 'CLOSED') {
toast('Agenda has closed. Redirecting to results.');
navigate(`/events/${eventId}/cycles/${cycleId}/results`);
}
}, [cycle?.status]);

Check warning on line 82 in packages/berlin/src/pages/Cycle.tsx

View workflow job for this annotation

GitHub Actions / Check linting

React Hook useEffect has missing dependencies: 'cycleId', 'eventId', and 'navigate'. Either include them or remove the dependency array

useEffect(() => {
if (cycle && cycle.startAt && cycle.endAt) {
setStartAt(cycle.startAt);
Expand Down Expand Up @@ -202,15 +211,32 @@

const currentCycle = cycle?.forumQuestions[0];

const sortId = (a: QuestionOption, b: QuestionOption, order: Order) => {
const idA = a.id.toUpperCase();
const idB = b.id.toUpperCase();

return order === 'desc' ? idB.localeCompare(idA) : idA.localeCompare(idB);
};

const sortByLead = (a: QuestionOption, b: QuestionOption, order: Order) => {
const leadA = (a.user.lastName || a.user.username).toUpperCase();
const leadB = (b.user.lastName || b.user.username).toUpperCase();

if (leadA === leadB) {
return sortId(a, b, order);
}

return order === 'desc' ? leadB.localeCompare(leadA) : leadA.localeCompare(leadB);
};

const sortByAffiliation = (a: QuestionOption, b: QuestionOption, order: Order) => {
const affiliationA = a.user.group?.name.toUpperCase();
const affiliationB = b.user.group?.name.toUpperCase() ?? '';

if (affiliationA === affiliationB) {
return sortId(a, b, order);
}

return order === 'desc'
? affiliationB.localeCompare(affiliationA)
: affiliationA.localeCompare(affiliationB);
Expand All @@ -224,6 +250,11 @@
) => {
const votesA = localUserVotes?.find((vote) => vote.optionId === a.id)?.numOfVotes || 0;
const votesB = localUserVotes?.find((vote) => vote.optionId === b.id)?.numOfVotes || 0;

if (votesA === votesB) {
return sortId(a, b, order);
}

return order === 'desc' ? votesB - votesA : votesA - votesB;
};

Expand Down
22 changes: 7 additions & 15 deletions packages/berlin/src/pages/PublicGroupRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function PublicGroupRegistration() {
const [searchParams] = useSearchParams();
const groupCategoryNameParam = searchParams.get('groupCategory');

const capitalizedParam =
groupCategoryNameParam &&
groupCategoryNameParam?.slice(0, 1).toUpperCase() + groupCategoryNameParam?.slice(1);

const {
control,
getValues,
Expand Down Expand Up @@ -78,8 +74,8 @@ function PublicGroupRegistration() {
if (!body) {
return;
}
queryClient.invalidateQueries({ queryKey: ['user', user?.id, 'groups'] });
toast.success(`Joined ${groupCategoryNameParam} group successfully!`);
queryClient.invalidateQueries({ queryKey: ['user', user?.id, 'users-to-groups'] });
toast.success(`Joined group successfully!`);
},
onError: () => {
toast.error('Something went wrong.');
Expand All @@ -98,8 +94,8 @@ function PublicGroupRegistration() {
return;
}

queryClient.invalidateQueries({ queryKey: ['user', user?.id, 'groups'] });
toast.success(`Updated ${groupCategoryNameParam} group successfully!`);
queryClient.invalidateQueries({ queryKey: ['user', user?.id, 'users-to-groups'] });
toast.success(`Updated group successfully!`);
},
onError: () => {
toast.error('Something went wrong.');
Expand Down Expand Up @@ -133,15 +129,11 @@ function PublicGroupRegistration() {
name="group"
control={control}
rules={{
required: `${capitalizedParam} group is required`,
required: `Group is required`,
}}
render={({ field }) => (
<Select
placeholder={
prevUserToGroup
? prevUserToGroup.group.name
: `Select your ${groupCategoryNameParam} group`
}
placeholder={prevUserToGroup ? prevUserToGroup.group.name : `Select your group`}
options={selectData}
value={field.value}
errors={[errors.group?.message ?? '']}
Expand All @@ -151,7 +143,7 @@ function PublicGroupRegistration() {
/>
)}
/>
<Button type="submit">Join {groupCategoryNameParam} group</Button>
<Button type="submit">Join group</Button>
</Form>
</FlexColumn>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/berlin/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ function NumberInput(props: {
label={props.name}
required={!!props.required}
placeholder="Enter a value"
min={250}
max={10000}
{...props.register(props.id, {
validate: (value) => {
if (!props.required) {
Expand All @@ -874,7 +876,8 @@ function NumberInput(props: {
const v = z.coerce
.number()
.int('Value has to be an integer')
.nonnegative('Value must be positive')
.min(250, 'Value must be 250 or higher')
.max(10000, 'Value must be 10,000 or lower')
.safeParse(value);

if (v.success) {
Expand Down
Loading
Loading