Skip to content

Commit

Permalink
Improve members listing page
Browse files Browse the repository at this point in the history
  • Loading branch information
kearfy committed Dec 23, 2023
1 parent 4177c3b commit 4c89a63
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"tailwindcss": "^3.3.5",
"tailwindcss-animate": "^1.0.7",
"typescript": "5.2.2",
"vaul": "^0.8.0",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import { RoleName, SelectRole } from '@/components/miscellaneous/Role';
import { Badge } from '@/components/ui/badge';
import { Button, buttonVariants } from '@/components/ui/button';
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog';
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerTrigger,
} from '@/components/ui/drawer';
import { Label } from '@/components/ui/label';
import { Separator } from '@/components/ui/separator';
import { Skeleton } from '@/components/ui/skeleton';
import {
Table,
Expand All @@ -22,6 +29,7 @@ import {
} from '@/components/ui/table';
import { useSurreal } from '@/lib/Surreal';
import { Role } from '@/lib/role';
import { useIsMobileState } from '@/lib/scrolled';
import { record } from '@/lib/zod';
import { Link } from '@/locales/navigation';
import { Organisation } from '@/schema/resources/organisation';
Expand Down Expand Up @@ -346,9 +354,11 @@ function InvitedManager({
<TableCell>
<Avatar profile={user as User} size="small" />
</TableCell>
<TableCell>
{user.name}{' '}
<Badge className="ml-3">{t('pending-invite')}</Badge>
<TableCell className="whitespace-nowrap">
{user.name}
<Badge className="ml-3 whitespace-nowrap">
{t('pending-invite')}
</Badge>
</TableCell>
<TableCell />
<TableCell>
Expand Down Expand Up @@ -389,6 +399,7 @@ function AddMember({
const [role, setRole] = useState<Role>('event_viewer');
const [open, setOpen] = useState(false);
const t = useTranslations('pages.console.organisation.members.add_member');
const isMobile = useIsMobileState();

const { mutateAsync, error } = useMutation({
mutationKey: ['manages', 'invite'],
Expand All @@ -404,6 +415,63 @@ function AddMember({
},
});

if (isMobile)
return (
<Drawer open={open} onOpenChange={setOpen}>
<DrawerTrigger asChild>
<Button>
{t('trigger')}
<Plus className="ml-2 h-6 w-6" />
</Button>
</DrawerTrigger>
<DrawerContent>
<div className="p-8 pb-12">
<h3 className="mb-4 text-2xl font-bold">
{' '}
{t('title')}
</h3>
<div className="space-y-6">
<UserSelector
user={user}
setUser={setUser}
autoFocus
autoComplete="off"
/>

<div className="space-y-3">
<Label htmlFor="role"> {t('role.label')}</Label>
<SelectRole
onRoleUpdate={setRole}
role={role}
className="w-[200px]"
/>
</div>
</div>
<div className="flex flex-col gap-10 pt-10">
<Separator orientation="horizontal" />
<div className="flex flex-col gap-6">
<Button
disabled={!user || !role}
onClick={() => {
mutateAsync().then(() => {
setUser(undefined);
setRole('event_viewer');
setOpen(false);
});
}}
>
<Mail className="mr-2 h-4 w-4" />
{t('submit')}
</Button>
<DrawerClose>Cancel</DrawerClose>
</div>
</div>
{!!error && <p>{(error as Error).message}</p>}
</div>
</DrawerContent>
</Drawer>
);

return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
Expand Down
8 changes: 4 additions & 4 deletions src/components/miscellaneous/Role.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ export function SelectRole({
<SelectItem value="owner">
<div className="flex flex-col text-white">
<RoleName role="owner" />
<span className="max-w-sm text-sm text-muted-foreground">
<span className="max-w-xs text-sm text-muted-foreground">
<RoleDescription role="owner" />
</span>
</div>
</SelectItem>
<SelectItem value="administrator">
<div className="flex flex-col text-white">
<RoleName role="administrator" />
<span className="max-w-sm text-sm text-muted-foreground">
<span className="max-w-xs text-sm text-muted-foreground">
<RoleDescription role="administrator" />
</span>
</div>
</SelectItem>
<SelectItem value="event_manager">
<div className="flex flex-col text-white">
<RoleName role="event_manager" />
<span className="max-w-sm text-sm text-muted-foreground">
<span className="max-w-xs text-sm text-muted-foreground">
<RoleDescription role="event_manager" />
</span>
</div>
</SelectItem>
<SelectItem value="event_viewer">
<div className="flex flex-col text-white">
<RoleName role="event_viewer" />
<span className="max-w-sm text-sm text-muted-foreground">
<span className="max-w-xs text-sm text-muted-foreground">
<RoleDescription role="event_viewer" />
</span>
</div>
Expand Down
118 changes: 118 additions & 0 deletions src/components/ui/drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
"use client"

import * as React from "react"
import { Drawer as DrawerPrimitive } from "vaul"

import { cn } from "@/lib/utils"

const Drawer = ({
shouldScaleBackground = true,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
<DrawerPrimitive.Root
shouldScaleBackground={shouldScaleBackground}
{...props}
/>
)
Drawer.displayName = "Drawer"

const DrawerTrigger = DrawerPrimitive.Trigger

const DrawerPortal = DrawerPrimitive.Portal

const DrawerClose = DrawerPrimitive.Close

const DrawerOverlay = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
className={cn("fixed inset-0 z-50 bg-black/80", className)}
{...props}
/>
))
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName

const DrawerContent = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerOverlay />
<DrawerPrimitive.Content
ref={ref}
className={cn(
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
className
)}
{...props}
>
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
))
DrawerContent.displayName = "DrawerContent"

const DrawerHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
{...props}
/>
)
DrawerHeader.displayName = "DrawerHeader"

const DrawerFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
{...props}
/>
)
DrawerFooter.displayName = "DrawerFooter"

const DrawerTitle = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DrawerTitle.displayName = DrawerPrimitive.Title.displayName

const DrawerDescription = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DrawerDescription.displayName = DrawerPrimitive.Description.displayName

export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
}

0 comments on commit 4c89a63

Please sign in to comment.