Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
Update participant row appearence and behaviour (#195)
Luke Vellaf928472078ab
diff --git a/src/components/home/hero.tsx b/src/components/home/hero.tsxindex abc00d6a5..b063487b0 100644--- a/src/components/home/hero.tsx+++ b/src/components/home/hero.tsx@@ -26,13 +26,13 @@ const Hero: React.VoidFunctionComponent = () => {</div><div className="space-x-3"><Link href="/new">- <a className="bg-primary-500 hover:bg-primary-500/90 focus:ring-primary-200 active:bg-primary-600/90 rounded-lg px-5 py-3 font-semibold text-white shadow-sm transition-all hover:text-white hover:no-underline hover:shadow-md focus:ring-2">+ <a className="rounded-lg bg-primary-500 px-5 py-3 font-semibold text-white shadow-sm transition-all hover:bg-primary-500/90 hover:text-white hover:no-underline hover:shadow-md focus:ring-2 focus:ring-primary-200 active:bg-primary-600/90">{t("getStarted")}</a></Link><Link href="/demo"><a- className="focus:ring-primary-200 rounded-lg bg-slate-500 px-5 py-3 font-semibold text-white shadow-sm transition-all hover:bg-slate-500/90 hover:text-white hover:no-underline hover:shadow-md focus:ring-2 active:bg-slate-600/90"+ className="rounded-lg bg-slate-500 px-5 py-3 font-semibold text-white shadow-sm transition-all hover:bg-slate-500/90 hover:text-white hover:no-underline hover:shadow-md focus:ring-2 focus:ring-primary-200 active:bg-slate-600/90"rel="nofollow">{t("viewDemo")}@@ -44,13 +44,13 @@ const Hero: React.VoidFunctionComponent = () => {<UserAvatarProvider seed="mock" names={names}><div className="relative inline-block"><motion.div- className="border-primary-500 bg-primary-200/10 absolute z-20 h-full rounded-2xl border-4 shadow-md"- initial={{ opacity: 0, width: 100, scale: 1.2, translateX: 384 }}- animate={{ opacity: 1, scale: 1.1 }}+ className="absolute z-20 h-full rounded-2xl border-4 border-primary-500 bg-primary-200/10 shadow-md"+ initial={{ opacity: 0, width: 100, scale: 1.1, x: 480 }}+ animate={{ opacity: 1, x: 381 }}transition={{ type: "spring", delay: 1 }}/><motion.div- className="bg-primary-500 absolute z-20 rounded-full py-1 px-3 text-sm text-slate-100"+ className="absolute z-20 rounded-full bg-primary-500 py-1 px-3 text-sm text-slate-100"initial={{opacity: 0,right: 190,diff --git a/src/components/home/poll-demo.tsx b/src/components/home/poll-demo.tsxindex a5c5403b7..e38bf325c 100644--- a/src/components/home/poll-demo.tsx+++ b/src/components/home/poll-demo.tsx@@ -2,11 +2,11 @@ import { format } from "date-fns";import { useTranslation } from "next-i18next";import * as React from "react";+import { ParticipantRowView } from "../poll/desktop-poll/participant-row";import { ScoreSummary } from "../poll/score-summary";-import UserAvatar from "../poll/user-avatar";-import VoteIcon from "../poll/vote-icon";const sidebarWidth = 180;+const columnWidth = 100;const participants = [{name: "Reed",@@ -61,7 +61,7 @@ const PollDemo: React.VoidFunctionComponent = () => {<divkey={i}className="shrink-0 space-y-3 py-2 pt-3 text-center transition-colors"- style={{ width: 100 }}+ style={{ width: columnWidth }}><div><div className="font-semibold leading-9">@@ -82,35 +82,16 @@ const PollDemo: React.VoidFunctionComponent = () => {})}</div>{participants.map((participant, i) => (- <div className="flex h-14" key={i}>- <div- className="flex shrink-0 items-center px-4"- style={{ width: sidebarWidth }}- >- <UserAvatar- color={participant.color}- name={participant.name}- showName={true}- />- </div>- <div className="flex">- {options.map((_, i) => {- return (- <div- key={i}- className="flex shrink-0 items-center justify-center"- style={{ width: 100 }}- >- {participant.votes.some((vote) => vote === i) ? (- <VoteIcon type="yes" />- ) : (- <VoteIcon type="no" />- )}- </div>- );- })}- </div>- </div>+ <ParticipantRowView+ key={i}+ color={participant.color}+ sidebarWidth={sidebarWidth}+ columnWidth={columnWidth}+ name={participant.name}+ votes={options.map((_, i) => {+ return participant.votes.some((vote) => vote === i) ? "yes" : "no";+ })}+ />))}</div>);diff --git a/src/components/poll/desktop-poll/participant-row-form.tsx b/src/components/poll/desktop-poll/participant-row-form.tsxindex 7ae9dfa6d..e868157f5 100644--- a/src/components/poll/desktop-poll/participant-row-form.tsx+++ b/src/components/poll/desktop-poll/participant-row-form.tsx@@ -28,8 +28,6 @@ const ParticipantRowForm: React.ForwardRefRenderFunction<ParticipantRowFormProps> = ({ defaultValues, onSubmit, className, onCancel }, ref) => {const {- setActiveOptionId,- activeOptionId,columnWidth,scrollPosition,sidebarWidth,@@ -120,15 +118,8 @@ const ParticipantRowForm: React.ForwardRefRenderFunction<return (<divkey={optionId}- className={clsx(- "flex shrink-0 items-center justify-center transition-colors",- {- "bg-gray-50": activeOptionId === optionId,- },- )}+ className="flex shrink-0 items-center justify-center"style={{ width: columnWidth }}- onMouseOver={() => setActiveOptionId(optionId)}- onMouseOut={() => setActiveOptionId(null)}><VoteSelectorvalue={value?.type}@@ -153,9 +144,6 @@ const ParticipantRowForm: React.ForwardRefRenderFunction<ref={(el) => {checkboxRefs.current[index] = el;}}- onFocus={() => {- setActiveOptionId(optionId);- }}/></div>);diff --git a/src/components/poll/desktop-poll/participant-row.tsx b/src/components/poll/desktop-poll/participant-row.tsxindex d1332918d..2c8c6c28a 100644--- a/src/components/poll/desktop-poll/participant-row.tsx+++ b/src/components/poll/desktop-poll/participant-row.tsx@@ -1,4 +1,4 @@-import { Participant, Vote } from "@prisma/client";+import { Participant, Vote, VoteType } from "@prisma/client";import clsx from "clsx";import * as React from "react";@@ -19,16 +19,84 @@ import { usePollContext } from "./poll-context";export interface ParticipantRowProps {participant: Participant & { votes: Vote[] };editMode: boolean;- onChangeEditMode?: (value: boolean) => void;+ onChangeEditMode: (value: boolean) => void;}+export const ParticipantRowView: React.VoidFunctionComponent<{+ name: string;+ editable?: boolean;+ color?: string;+ votes: Array<VoteType | undefined>;+ onEdit?: () => void;+ onDelete?: () => void;+ columnWidth: number;+ sidebarWidth: number;+ isYou?: boolean;+}> = ({+ name,+ editable,+ votes,+ onEdit,+ onDelete,+ sidebarWidth,+ columnWidth,+ isYou,+ color,+}) => {+ return (+ <div data-testid="participant-row" className="group flex h-14">+ <div+ className="flex shrink-0 items-center px-4"+ style={{ width: sidebarWidth }}+ >+ <UserAvatar+ className="mr-2"+ name={name}+ showName={true}+ isYou={isYou}+ color={color}+ />+ {editable ? (+ <div className="hidden shrink-0 items-center space-x-2 overflow-hidden group-hover:flex">+ <CompactButton icon={Pencil} onClick={onEdit} />+ <CompactButton icon={Trash} onClick={onDelete} />+ </div>+ ) : null}+ </div>+ <ControlledScrollArea>+ {votes.map((vote, i) => {+ return (+ <div+ key={i}+ className="relative shrink-0 transition-colors"+ style={{ width: columnWidth }}+ >+ <div+ className={clsx(+ "absolute inset-1 flex items-center justify-center rounded-lg",+ {+ "bg-green-50": vote === "yes",+ "bg-amber-50": vote === "ifNeedBe",+ "bg-slate-50": vote === "no",+ },+ )}+ >+ <VoteIcon type={vote} />+ </div>+ </div>+ );+ })}+ </ControlledScrollArea>+ </div>+ );+};+const ParticipantRow: React.VoidFunctionComponent<ParticipantRowProps> = ({participant,editMode,onChangeEditMode,}) => {- const { setActiveOptionId, activeOptionId, columnWidth, sidebarWidth } =- usePollContext();+ const { columnWidth, sidebarWidth } = usePollContext();const updateParticipant = useUpdateParticipantMutation();@@ -69,60 +137,22 @@ const ParticipantRow: React.VoidFunctionComponent<ParticipantRowProps> = ({}return (- <div- key={participant.id}- data-testid="participant-row"- className="group flex h-14 transition-colors hover:bg-slate-300/10"- >- <div- className="flex shrink-0 items-center px-4"- style={{ width: sidebarWidth }}- >- <UserAvatar- className="mr-2"- name={participant.name}- showName={true}- isYou={isYou}- />- {canEdit ? (- <div className="hidden shrink-0 items-center space-x-2 overflow-hidden group-hover:flex">- <CompactButton- icon={Pencil}- onClick={() => {- onChangeEditMode?.(true);- }}- />- <CompactButton- icon={Trash}- onClick={() => {- confirmDeleteParticipant(participant.id);- }}- />- </div>- ) : null}- </div>- <ControlledScrollArea>- {options.map(({ optionId }) => {- const vote = getVote(participant.id, optionId);- return (- <div- key={optionId}- className={clsx(- "flex shrink-0 items-center justify-center transition-colors",- {- "bg-gray-50": activeOptionId === optionId,- },- )}- style={{ width: columnWidth }}- onMouseOver={() => setActiveOptionId(optionId)}- onMouseOut={() => setActiveOptionId(null)}- >- <VoteIcon type={vote} />- </div>- );- })}- </ControlledScrollArea>- </div>+ <ParticipantRowView+ sidebarWidth={sidebarWidth}+ columnWidth={columnWidth}+ name={participant.name}+ votes={options.map(({ optionId }) => {+ return getVote(participant.id, optionId);+ })}+ editable={canEdit}+ isYou={isYou}+ onEdit={() => {+ onChangeEditMode?.(true);+ }}+ onDelete={() => {+ confirmDeleteParticipant(participant.id);+ }}+ />);};diff --git a/src/components/poll/desktop-poll/poll-context.ts b/src/components/poll/desktop-poll/poll-context.tsindex 8e2c3296b..c200c420f 100644--- a/src/components/poll/desktop-poll/poll-context.ts+++ b/src/components/poll/desktop-poll/poll-context.ts@@ -9,7 +9,7 @@ export const PollContext = React.createContext<{columnWidth: number;sidebarWidth: number;numberOfColumns: number;- availableSpace: number;+ availableSpace: number | string;actionColumnWidth: number;goToNextPage: () => void;goToPreviousPage: () => void;@@ -21,7 +21,7 @@ export const PollContext = React.createContext<{columnWidth: 100,sidebarWidth: 200,numberOfColumns: 0,- availableSpace: 0,+ availableSpace: "auto",goToNextPage: noop,goToPreviousPage: noop,actionColumnWidth: 0,diff --git a/src/components/poll/desktop-poll/poll-header.tsx b/src/components/poll/desktop-poll/poll-header.tsxindex d7928ee52..f7c8968ca 100644--- a/src/components/poll/desktop-poll/poll-header.tsx+++ b/src/components/poll/desktop-poll/poll-header.tsx@@ -27,7 +27,7 @@ const TimeRange: React.VoidFunctionComponent<{const PollHeader: React.VoidFunctionComponent = () => {const { options, getScore } = usePoll();- const { activeOptionId, setActiveOptionId, columnWidth } = usePollContext();+ const { setActiveOptionId, columnWidth } = usePollContext();return (<ControlledScrollArea>@@ -37,12 +37,7 @@ const PollHeader: React.VoidFunctionComponent = () => {return (<divkey={optionId}- className={clsx(- "shrink-0 space-y-3 py-3 text-center transition-colors",- {- "bg-gray-50": activeOptionId === optionId,- },- )}+ className="shrink-0 space-y-3 py-3 text-center"style={{ width: columnWidth }}onMouseOver={() => setActiveOptionId(optionId)}onMouseOut={() => setActiveOptionId(null)}