-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
848 additions
and
1,459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
apps/web/src/components/happening/registrations-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { type Registration, type User } from "@echo-webkom/db/schemas"; | ||
|
||
import { ellipsis, initials } from "@/utils/string"; | ||
import { Text } from "../typography/text"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; | ||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "../ui/dialog"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; | ||
|
||
type ProfilePreviewProps = { | ||
user: User; | ||
}; | ||
|
||
const ProfilePreview = ({ user }: ProfilePreviewProps) => { | ||
const fallback = initials(user.name ?? "BO"); | ||
|
||
return ( | ||
<Avatar className="size-8"> | ||
<AvatarImage src={user.image ?? ""} /> | ||
<AvatarFallback>{fallback}</AvatarFallback> | ||
</Avatar> | ||
); | ||
}; | ||
|
||
type RegistrationsPreviewProps = { | ||
registrations: Array< | ||
Registration & { | ||
user: User; | ||
} | ||
>; | ||
}; | ||
|
||
const MAX = 7; | ||
|
||
export const RegistrationsPreview = ({ registrations }: RegistrationsPreviewProps) => { | ||
const sorted = registrations | ||
.filter((registration) => registration.status === "registered") | ||
.sort((a, b) => { | ||
if (a.user.image && !b.user.image) { | ||
return -1; | ||
} else if (!a.user.image && b.user.image) { | ||
return 1; | ||
} | ||
return 0; | ||
}) | ||
.slice(0, MAX); | ||
|
||
if (sorted.length < 3) { | ||
return null; | ||
} | ||
|
||
const extra = registrations.length - MAX; | ||
const names = `${sorted.map((registration) => ellipsis(registration.user?.name ?? "", 7)).join(", ")}${ | ||
extra > 0 ? ` +${extra}` : "" | ||
}`; | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger className="group flex w-fit items-start"> | ||
<TooltipProvider> | ||
<Tooltip> | ||
<div> | ||
<TooltipTrigger> | ||
<div className="flex items-center"> | ||
<div className="flex items-center -space-x-4"> | ||
{sorted.map((registration) => ( | ||
<ProfilePreview key={registration.user.id} user={registration.user} /> | ||
))} | ||
</div> | ||
{extra > 0 && ( | ||
<div className="ml-2 text-sm font-medium text-gray-600 group-hover:underline"> | ||
+{extra} | ||
</div> | ||
)} | ||
</div> | ||
</TooltipTrigger> | ||
</div> | ||
<TooltipContent> | ||
<p>{names}</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Påmeldte brukere</DialogTitle> | ||
</DialogHeader> | ||
<div className="px-4 pb-4"> | ||
{registrations | ||
.filter((registration) => registration.status === "registered") | ||
.map((registration) => ( | ||
<div key={registration.userId} className="flex items-center space-x-4"> | ||
<ProfilePreview user={registration.user} /> | ||
<Text className="text-muted-foreground">{registration.user.name}</Text> | ||
</div> | ||
))} | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"; | ||
|
||
import { cn } from "@/utils/cn"; | ||
|
||
const TooltipProvider = TooltipPrimitive.Provider; | ||
|
||
const Tooltip = TooltipPrimitive.Root; | ||
|
||
const TooltipTrigger = TooltipPrimitive.Trigger; | ||
|
||
const TooltipContent = React.forwardRef< | ||
React.ElementRef<typeof TooltipPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> | ||
>(({ className, sideOffset = 4, ...props }, ref) => ( | ||
<TooltipPrimitive.Portal> | ||
<TooltipPrimitive.Content | ||
ref={ref} | ||
sideOffset={sideOffset} | ||
className={cn( | ||
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
</TooltipPrimitive.Portal> | ||
)); | ||
TooltipContent.displayName = TooltipPrimitive.Content.displayName; | ||
|
||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.