Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
import { cn } from "@rallly/ui";
import type * as React from "react";
import type { ParsedDateTimeOpton } from "@/lib/utils/date-time-utils";
import PollOptions from "./poll-options";
export interface GroupedOptionsProps {
options: ParsedDateTimeOpton[];
editable?: boolean;
selectedParticipantId?: string;
group: (option: ParsedDateTimeOpton) => string;
groupClassName?: string;
}
const GroupedOptions: React.FunctionComponent<GroupedOptionsProps> = ({
options,
editable,
selectedParticipantId,
group,
groupClassName,
}) => {
const grouped = new Map<string, ParsedDateTimeOpton[]>();
for (const option of options) {
const key = group(option);
const list = grouped.get(key);
if (list) {
list.push(option);
} else {
grouped.set(key, [option]);
}
}
return (
<div className="select-none divide-y">
{Array.from(grouped, ([day, options]) => {
return (
<div key={day}>
<div
className={cn(
"border-b bg-card/80 px-4 py-3 font-semibold text-sm",
groupClassName,
)}
>
{day}
</div>
<PollOptions
options={options}
editable={editable}
selectedParticipantId={selectedParticipantId}
/>
</div>
);
})}
</div>
);
};
export default GroupedOptions;