mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-06-15 00:48:44 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
30
components/activity-item.tsx
Normal file
30
components/activity-item.tsx
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { format } from "date-fns";
|
||||
import { AuditLog } from "@prisma/client";
|
||||
|
||||
import { generateLogMessage } from "@/lib/generate-log-message";
|
||||
import { Avatar, AvatarImage } from "@/components/ui/avatar";
|
||||
|
||||
interface ActivityItemProps {
|
||||
data: AuditLog;
|
||||
}
|
||||
|
||||
export const ActivityItem = ({ data }: ActivityItemProps) => {
|
||||
return (
|
||||
<li className="flex items-center gap-x-2">
|
||||
<Avatar className="h-8 w-8">
|
||||
<AvatarImage src={data.userImage} />
|
||||
</Avatar>
|
||||
<div className="flex flex-col space-y-0.5">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
<span className="font-semibold lowercase text-neutral-700">
|
||||
{data.userName}
|
||||
</span>{" "}
|
||||
{generateLogMessage(data)}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{format(new Date(data.createdAt), "MMM d, yyyy 'at' h:mm a")}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
};
|
28
components/form/form-errors.tsx
Normal file
28
components/form/form-errors.tsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { XCircle } from "lucide-react";
|
||||
|
||||
interface FormErrorsProps {
|
||||
id: string;
|
||||
errors?: Record<string, string[] | undefined>;
|
||||
}
|
||||
|
||||
export const FormErrors = ({ id, errors }: FormErrorsProps) => {
|
||||
if (!errors) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
id={`${id}-error`}
|
||||
aria-live="polite"
|
||||
className="mt-2 text-xs text-rose-500"
|
||||
>
|
||||
{errors?.[id]?.map((error: string) => (
|
||||
<div
|
||||
key={error}
|
||||
className="flex items-center font-medium p-2 border border-rose-500 bg-rose-500/10 rounded-sm"
|
||||
>
|
||||
<XCircle className="h-4 w-4 mr-2" />
|
||||
{error}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
73
components/form/form-input.tsx
Normal file
73
components/form/form-input.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
"use client";
|
||||
|
||||
import { forwardRef } from "react";
|
||||
import { useFormStatus } from "react-dom";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { FormErrors } from "./form-errors";
|
||||
|
||||
interface FormInputProps {
|
||||
id: string;
|
||||
label?: string;
|
||||
type?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
errors?: Record<string, string[] | undefined>;
|
||||
className?: string;
|
||||
defaultValue?: string;
|
||||
onBlur?: () => void;
|
||||
}
|
||||
|
||||
export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
|
||||
(
|
||||
{
|
||||
id,
|
||||
label,
|
||||
type,
|
||||
placeholder,
|
||||
required,
|
||||
disabled,
|
||||
errors,
|
||||
className,
|
||||
defaultValue = "",
|
||||
onBlur,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="space-y-1">
|
||||
{label ? (
|
||||
<Label
|
||||
htmlFor={id}
|
||||
className="text-xs font-semibold text-neutral-700"
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
) : null}
|
||||
<Input
|
||||
onBlur={onBlur}
|
||||
defaultValue={defaultValue}
|
||||
ref={ref}
|
||||
required={required}
|
||||
name={id}
|
||||
id={id}
|
||||
placeholder={placeholder}
|
||||
type={type}
|
||||
disabled={pending ?? disabled}
|
||||
className={cn("text-sm px-2 py-1 h-7", className)}
|
||||
aria-describedby={`${id}-error`}
|
||||
/>
|
||||
</div>
|
||||
<FormErrors id={id} errors={errors} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
FormInput.displayName = "FormInput";
|
109
components/form/form-picker.tsx
Normal file
109
components/form/form-picker.tsx
Normal file
|
@ -0,0 +1,109 @@
|
|||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useFormStatus } from "react-dom";
|
||||
import { Check, Loader2 } from "lucide-react";
|
||||
|
||||
import { unsplash } from "@/lib/unsplash";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { defaultImages } from "@/constants/images";
|
||||
import { FormErrors } from "./form-errors";
|
||||
|
||||
interface FormPickerProps {
|
||||
id: string;
|
||||
errors?: Record<string, string[] | undefined>;
|
||||
}
|
||||
|
||||
export const FormPicker = ({ id, errors }: FormPickerProps) => {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
const [images, setImages] =
|
||||
useState<Array<Record<string, any>>>(defaultImages);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [selectedImageId, setSelectedImageId] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchImages = async () => {
|
||||
try {
|
||||
const result = await unsplash.photos.getRandom({
|
||||
collectionIds: ["317099"],
|
||||
count: 9,
|
||||
});
|
||||
|
||||
if (result?.response) {
|
||||
const newImages = result.response as Array<Record<string, any>>;
|
||||
setImages(newImages);
|
||||
} else {
|
||||
console.error("Failed to get images.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setImages(defaultImages);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchImages();
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 flex items-center justify-center">
|
||||
<Loader2 className="h-6 w-6 text-sky-700 animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className="grid grid-cols-3 gap-2 mb-2">
|
||||
{images.map((image) => (
|
||||
<div
|
||||
key={image.id}
|
||||
className={cn(
|
||||
"cursor-pointer relative aspect-video group hover:opacity-75 transition bg-muted",
|
||||
pending && "opacity-50 hover:opacity-50 cursor-auto"
|
||||
)}
|
||||
onClick={() => {
|
||||
if (pending) return;
|
||||
setSelectedImageId(image.id);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
id={id}
|
||||
name={id}
|
||||
className="hidden"
|
||||
checked={selectedImageId === image.id}
|
||||
disabled={pending}
|
||||
value={`${image.id}|${image.urls.thumb}|${image.urls.full}|${image.links.html}|${image.user.name}`}
|
||||
/>
|
||||
<Image
|
||||
src={image.urls.thumb}
|
||||
alt="Unsplash image"
|
||||
className="object-cover rounded-sm"
|
||||
fill
|
||||
/>
|
||||
{selectedImageId === image.id && (
|
||||
<div className="absolute inset-y-0 h-full w-full bg-black/30 flex items-center justify-center">
|
||||
<Check className="h-4 w-4 text-white" />
|
||||
</div>
|
||||
)}
|
||||
<Link
|
||||
href={image.links.html}
|
||||
target="_blank"
|
||||
className="opacity-0 group-hover:opacity-100 absolute bottom-0 w-full text-[10px] truncate text-white hover:underline p-1 bg-black/50"
|
||||
>
|
||||
{image.user.name}
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<FormErrors id="image" errors={errors} />
|
||||
</div>
|
||||
);
|
||||
};
|
94
components/form/form-popover.tsx
Normal file
94
components/form/form-popover.tsx
Normal file
|
@ -0,0 +1,94 @@
|
|||
"use client";
|
||||
|
||||
import { X } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { ElementRef, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import {
|
||||
Popover,
|
||||
PopoverClose,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { useAction } from "@/hooks/use-action";
|
||||
import { createBoard } from "@/actions/create-board";
|
||||
import { Button } from "@/components//ui/button";
|
||||
import { useProModal } from "@/hooks/use-pro-modal";
|
||||
|
||||
import { FormInput } from "./form-input";
|
||||
import { FormSubmit } from "./form-submit";
|
||||
import { FormPicker } from "./form-picker";
|
||||
|
||||
interface FormPopoverProps {
|
||||
children: React.ReactNode;
|
||||
side?: "left" | "right" | "top" | "bottom";
|
||||
align?: "center" | "start" | "end";
|
||||
sideOffset?: number;
|
||||
}
|
||||
|
||||
export const FormPopover = ({
|
||||
children,
|
||||
side = "bottom",
|
||||
align,
|
||||
sideOffset = 0,
|
||||
}: FormPopoverProps) => {
|
||||
const proModal = useProModal();
|
||||
const router = useRouter();
|
||||
const closeRef = useRef<ElementRef<"button">>(null);
|
||||
|
||||
const { execute, fieldErrors } = useAction(createBoard, {
|
||||
onSuccess: (data) => {
|
||||
toast.success("Board created");
|
||||
closeRef.current?.click();
|
||||
router.push(`/board/${data.id}`);
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
proModal.onOpen();
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = (formData: FormData) => {
|
||||
const title = formData.get("title") as string;
|
||||
const image = formData.get("image") as string;
|
||||
|
||||
execute({ title, image });
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>{children}</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align={align}
|
||||
className="w-80 pt-3"
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
>
|
||||
<div className="text-sm font-medium text-center text-neutral-600 pb-4">
|
||||
Create board
|
||||
</div>
|
||||
<PopoverClose ref={closeRef} asChild>
|
||||
<Button
|
||||
className="h-auto w-auto p-2 absolute top-2 right-2 text-neutral-600"
|
||||
variant="ghost"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</PopoverClose>
|
||||
<form action={onSubmit} className="space-y-4">
|
||||
<div className="space-y-4">
|
||||
<FormPicker id="image" errors={fieldErrors} />
|
||||
<FormInput
|
||||
id="title"
|
||||
label="Board Title"
|
||||
type="text"
|
||||
errors={fieldErrors}
|
||||
/>
|
||||
</div>
|
||||
<FormSubmit className="w-full">Create</FormSubmit>
|
||||
</form>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
};
|
41
components/form/form-submit.tsx
Normal file
41
components/form/form-submit.tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
"Use client";
|
||||
|
||||
import { useFormStatus } from "react-dom";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
interface FormSubmitProps {
|
||||
children: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
variant?:
|
||||
| "default"
|
||||
| "destructive"
|
||||
| "outline"
|
||||
| "secondary"
|
||||
| "ghost"
|
||||
| "link"
|
||||
| "primary";
|
||||
}
|
||||
|
||||
export const FormSubmit = ({
|
||||
children,
|
||||
disabled,
|
||||
className,
|
||||
variant = "primary",
|
||||
}: FormSubmitProps) => {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<Button
|
||||
disabled={pending || disabled}
|
||||
type="submit"
|
||||
variant={variant}
|
||||
size="sm"
|
||||
className={cn(className)}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
};
|
80
components/form/form-textarea.tsx
Normal file
80
components/form/form-textarea.tsx
Normal file
|
@ -0,0 +1,80 @@
|
|||
"use client";
|
||||
|
||||
import { useFormStatus } from "react-dom";
|
||||
import { KeyboardEventHandler, forwardRef } from "react";
|
||||
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { FormErrors } from "./form-errors";
|
||||
|
||||
interface FormTextareaProps {
|
||||
id: string;
|
||||
label?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
errors?: Record<string, string[] | undefined>;
|
||||
className?: string;
|
||||
onBlur?: () => void;
|
||||
onClick?: () => void;
|
||||
onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement> | undefined;
|
||||
defaultValue?: string;
|
||||
}
|
||||
|
||||
export const FormTextarea = forwardRef<HTMLTextAreaElement, FormTextareaProps>(
|
||||
(
|
||||
{
|
||||
id,
|
||||
label,
|
||||
placeholder,
|
||||
required,
|
||||
disabled,
|
||||
errors,
|
||||
className,
|
||||
onBlur,
|
||||
onClick,
|
||||
onKeyDown,
|
||||
defaultValue,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<div className="space-y-2 w-full">
|
||||
<div className="space-y-1 w-full">
|
||||
{label ? (
|
||||
<Label
|
||||
htmlFor={id}
|
||||
className="text-xs font-semibold text-neutral-700"
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
) : null}
|
||||
<Textarea
|
||||
onKeyDown={onKeyDown}
|
||||
onBlur={onBlur}
|
||||
onClick={onClick}
|
||||
ref={ref}
|
||||
required={required}
|
||||
placeholder={placeholder}
|
||||
name={id}
|
||||
id={id}
|
||||
disabled={pending || disabled}
|
||||
className={cn(
|
||||
"resize-none focus-visible:ring-0 focus-visible:ring-offset-0 ring-0 focus:ring-0 outline-none shadow-sm",
|
||||
className
|
||||
)}
|
||||
aria-describedby={`${id}-error`}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
</div>
|
||||
<FormErrors id={id} errors={errors} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
FormTextarea.displayName = "FormTextarea";
|
35
components/hint.tsx
Normal file
35
components/hint.tsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
|
||||
interface HintProps {
|
||||
children: React.ReactNode;
|
||||
description: string;
|
||||
side?: "left" | "right" | "top" | "bottom";
|
||||
sideOffset?: number;
|
||||
}
|
||||
|
||||
export const Hint = ({
|
||||
children,
|
||||
description,
|
||||
side = "bottom",
|
||||
sideOffset = 0,
|
||||
}: HintProps) => {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip delayDuration={0}>
|
||||
<TooltipTrigger>{children}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
sideOffset={sideOffset}
|
||||
side={side}
|
||||
className="text-xs max-w-[220px] break-words"
|
||||
>
|
||||
{description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
};
|
12
components/logo.tsx
Normal file
12
components/logo.tsx
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
export const Logo = () => {
|
||||
return (
|
||||
<Link href="/">
|
||||
<div className="hover:opacity-75 transition items-center gap-x-2 hidden md:flex">
|
||||
<Image src="/logo-transparent.svg" alt="logo" height={100} width={100} />
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
};
|
103
components/modals/card-modal/actions.tsx
Normal file
103
components/modals/card-modal/actions.tsx
Normal file
|
@ -0,0 +1,103 @@
|
|||
"use client";
|
||||
|
||||
import { Copy, Trash } from "lucide-react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { deleteCard } from "@/actions/delete-card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAction } from "@/hooks/use-action";
|
||||
import { copyCard } from "@/actions/copy-card";
|
||||
|
||||
import { CardWithList } from "@/types";
|
||||
import { useCardModal } from "@/hooks/use-card-modal";
|
||||
|
||||
interface ActionsProps {
|
||||
data: CardWithList;
|
||||
}
|
||||
|
||||
export const Actions = ({ data }: ActionsProps) => {
|
||||
const params = useParams();
|
||||
const cardModal = useCardModal();
|
||||
|
||||
const { execute: executeDeleteCard, isLoading: isLoadingDelete } = useAction(
|
||||
deleteCard,
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.success(`Card "${data.title}" deleted`);
|
||||
cardModal.onClose();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const { execute: executeCopyCard, isLoading: isLoadingCopy } = useAction(
|
||||
copyCard,
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.success(`Card "${data.title}" copied`);
|
||||
cardModal.onClose();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const onCopy = () => {
|
||||
const boardId = params.boardId as string;
|
||||
|
||||
executeCopyCard({
|
||||
id: data.id,
|
||||
boardId,
|
||||
});
|
||||
};
|
||||
|
||||
const onDelete = () => {
|
||||
const boardId = params.boardId as string;
|
||||
|
||||
executeDeleteCard({
|
||||
id: data.id,
|
||||
boardId,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-2 mt-2">
|
||||
<p className="text-xs font-semibold">Actions</p>
|
||||
<Button
|
||||
onClick={onCopy}
|
||||
disabled={isLoadingCopy}
|
||||
variant="gray"
|
||||
className="w-full justify-start"
|
||||
size="inline"
|
||||
>
|
||||
<Copy className="h-4 w-4 mr-2" />
|
||||
Copy
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onDelete}
|
||||
disabled={isLoadingDelete}
|
||||
variant="gray"
|
||||
className="w-full justify-start text-destructive"
|
||||
size="inline"
|
||||
>
|
||||
<Trash className="h-4 w-4 mr-2" />
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Actions.Skeleton = function ActionsSkeleton() {
|
||||
return (
|
||||
<div className="space-y-2 mt-2">
|
||||
<Skeleton className="w-20 h-4 bg-neutral-200" />
|
||||
<Skeleton className="w-full h-8 bg-neutral-200" />
|
||||
<Skeleton className="w-full h-8 bg-neutral-200" />
|
||||
</div>
|
||||
);
|
||||
};
|
39
components/modals/card-modal/activity.tsx
Normal file
39
components/modals/card-modal/activity.tsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
"use client";
|
||||
|
||||
import { AuditLog } from "@prisma/client";
|
||||
import { ActivityIcon } from "lucide-react";
|
||||
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { ActivityItem } from "@/components/activity-item";
|
||||
|
||||
interface ActivityProps {
|
||||
items: AuditLog[];
|
||||
}
|
||||
|
||||
export const Activity = ({ items }: ActivityProps) => {
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 w-full">
|
||||
<ActivityIcon className="h-5 w-5 mt-0.5 text-neutral-700" />
|
||||
<div className="w-full">
|
||||
<p className="font-semibold text-neutral-700 mb-2">Activity</p>
|
||||
<ol className="mt-2 space-y-4">
|
||||
{items.map((item) => (
|
||||
<ActivityItem key={item.id} data={item} />
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Activity.Skeleton = function ActivitySkeleton() {
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 w-full">
|
||||
<Skeleton className="h-6 w-6 bg-neutral-200" />
|
||||
<div className="w-full">
|
||||
<Skeleton className="w-24 h-6 mb-2 bg-neutral-200" />
|
||||
<Skeleton className="w-full h-10 bg-neutral-200" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
126
components/modals/card-modal/description.tsx
Normal file
126
components/modals/card-modal/description.tsx
Normal file
|
@ -0,0 +1,126 @@
|
|||
"use client";
|
||||
|
||||
import { useEventListener, useOnClickOutside } from "usehooks-ts";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useState, ElementRef, useRef } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { AlignLeft } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { FormTextarea } from "@/components/form/form-textarea";
|
||||
import { FormSubmit } from "@/components/form/form-submit";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { updateCard } from "@/actions/update-card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAction } from "@/hooks/use-action";
|
||||
|
||||
import { CardWithList } from "@/types";
|
||||
|
||||
interface DescriptionProps {
|
||||
data: CardWithList;
|
||||
}
|
||||
|
||||
export const Description = ({ data }: DescriptionProps) => {
|
||||
const queryClient = useQueryClient();
|
||||
const params = useParams();
|
||||
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
|
||||
const textareaRef = useRef<ElementRef<"textarea">>(null);
|
||||
const formRef = useRef<ElementRef<"form">>(null);
|
||||
|
||||
const enaleEditing = () => {
|
||||
setIsEditing(true);
|
||||
setTimeout(() => {
|
||||
textareaRef.current?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
const disableEditing = () => {
|
||||
setIsEditing(false);
|
||||
};
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
disableEditing();
|
||||
}
|
||||
};
|
||||
|
||||
useEventListener("keydown", onKeyDown);
|
||||
useOnClickOutside(formRef, disableEditing);
|
||||
|
||||
const { execute, fieldErrors } = useAction(updateCard, {
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["card", data.id] });
|
||||
queryClient.invalidateQueries({ queryKey: ["card-logs", data.id] });
|
||||
toast.success(`Card "${data.title}" updated`);
|
||||
disableEditing();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = (formData: FormData) => {
|
||||
const description = formData.get("description") as string;
|
||||
const boardId = params.boardId as string;
|
||||
|
||||
execute({
|
||||
id: data.id,
|
||||
description,
|
||||
boardId,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 w-full">
|
||||
<AlignLeft className="w-5 h-5 mt-0.5 text-neutral-700" />
|
||||
<div className="w-full">
|
||||
<p className="font-semibold text-neutral-700 mb-2">Description</p>
|
||||
{isEditing ? (
|
||||
<form ref={formRef} className="space-y-2" action={onSubmit}>
|
||||
<FormTextarea
|
||||
id="description"
|
||||
ref={textareaRef}
|
||||
className="w-full mt-2"
|
||||
placeholder="Add a more detailed description..."
|
||||
defaultValue={data.description ?? undefined}
|
||||
errors={fieldErrors}
|
||||
/>
|
||||
<div className="flex items-center gap-x-2">
|
||||
<FormSubmit>Save</FormSubmit>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={disableEditing}
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<div
|
||||
onClick={enaleEditing}
|
||||
role="button"
|
||||
className="min-h-[78px] bg-neutral-200 text-sm font-medium py-3 px-3.5 rounded-md"
|
||||
>
|
||||
{data.description ?? "Add a more detailed description..."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Description.Skeleton = function DescriptionSkeleton() {
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 w-full">
|
||||
<Skeleton className="h-6 w-6 bg-neutral-200" />
|
||||
<div className="w-full">
|
||||
<Skeleton className="h-6 w-24 mb-2 bg-neutral-200" />
|
||||
<Skeleton className="w-full h-[78px] bg-neutral-200" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
93
components/modals/card-modal/header.tsx
Normal file
93
components/modals/card-modal/header.tsx
Normal file
|
@ -0,0 +1,93 @@
|
|||
"use client";
|
||||
|
||||
import { useRef, ElementRef, useState } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useParams } from "next/navigation";
|
||||
import { Layout } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { CardWithList } from "@/types";
|
||||
import { useAction } from "@/hooks/use-action";
|
||||
import { updateCard } from "@/actions/update-card";
|
||||
import { FormInput } from "@/components/form/form-input";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
interface HeaderProps {
|
||||
data: CardWithList;
|
||||
}
|
||||
|
||||
export const Header = ({ data }: HeaderProps) => {
|
||||
const queryClient = useQueryClient();
|
||||
const params = useParams();
|
||||
|
||||
const { execute } = useAction(updateCard, {
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["card", data.id],
|
||||
});
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["card-logs", data.id],
|
||||
});
|
||||
|
||||
toast.success(`Card renamed to "${data.title}"`);
|
||||
setTitle(data.title);
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
const inputRef = useRef<ElementRef<"input">>(null);
|
||||
|
||||
const [title, setTitle] = useState(data.title);
|
||||
|
||||
const onBlur = () => {
|
||||
inputRef.current?.form?.requestSubmit();
|
||||
};
|
||||
|
||||
const onSubmit = (formData: FormData) => {
|
||||
const title = formData.get("title") as string;
|
||||
const boardId = params.boardId as string;
|
||||
|
||||
if (title === data.title) return;
|
||||
|
||||
execute({
|
||||
id: data.id,
|
||||
title,
|
||||
boardId,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 mb-6 w-full">
|
||||
<Layout className="h-5 w-5 mt-1 text-neutral-700" />
|
||||
<div className="w-full">
|
||||
<form action={onSubmit}>
|
||||
<FormInput
|
||||
id="title"
|
||||
ref={inputRef}
|
||||
onBlur={onBlur}
|
||||
defaultValue={title}
|
||||
className="font-semi-bold text-xl px-1 text-neutral-700 bg-transparent border-transparent relative -left-1 w-[95%] focus-visible:bg-white focus-visible:border-input mb-0.5 truncate"
|
||||
/>
|
||||
</form>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
in list <span className="underline">{data.list.title}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Header.Skeleton = function HeaderSkelton() {
|
||||
return (
|
||||
<div className="flex items-start gap-x-3 mb-6">
|
||||
<Skeleton className="h-6 w-6 mt-1 bg-neutral-200" />
|
||||
<div>
|
||||
<Skeleton className="w-24 h-6 mb-1 bg-neutral-200" />
|
||||
<Skeleton className="w-12 h-4 bg-neutral-200" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
55
components/modals/card-modal/index.tsx
Normal file
55
components/modals/card-modal/index.tsx
Normal file
|
@ -0,0 +1,55 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { CardWithList } from "@/types";
|
||||
import { fetcher } from "@/lib/fetcher";
|
||||
import { AuditLog } from "@prisma/client";
|
||||
import { useCardModal } from "@/hooks/use-card-modal";
|
||||
import { Dialog, DialogContent } from "@/components/ui/dialog";
|
||||
|
||||
import { Header } from "./header";
|
||||
import { Description } from "./description";
|
||||
import { Actions } from "./actions";
|
||||
import { Activity } from "./activity";
|
||||
|
||||
export const CardModal = () => {
|
||||
const id = useCardModal((state) => state.id);
|
||||
const isOpen = useCardModal((state) => state.isOpen);
|
||||
const onClose = useCardModal((state) => state.onClose);
|
||||
|
||||
const { data: cardData } = useQuery<CardWithList>({
|
||||
queryKey: ["card", id],
|
||||
queryFn: () => fetcher(`/api/cards/${id}`),
|
||||
});
|
||||
|
||||
const { data: auditLogsData } = useQuery<AuditLog[]>({
|
||||
queryKey: ["card-logs", id],
|
||||
queryFn: () => fetcher(`/api/cards/${id}/logs`),
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent>
|
||||
{!cardData ? <Header.Skeleton /> : <Header data={cardData} />}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 md:gap-4">
|
||||
<div className="col-span-3">
|
||||
<div className="w-full space-y-6">
|
||||
{!cardData ? (
|
||||
<Description.Skeleton />
|
||||
) : (
|
||||
<Description data={cardData} />
|
||||
)}
|
||||
{!auditLogsData ? (
|
||||
<Activity.Skeleton />
|
||||
) : (
|
||||
<Activity items={auditLogsData} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!cardData ? <Actions.Skeleton /> : <Actions data={cardData} />}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
61
components/modals/pro-modal.tsx
Normal file
61
components/modals/pro-modal.tsx
Normal file
|
@ -0,0 +1,61 @@
|
|||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Dialog, DialogContent } from "@/components/ui/dialog";
|
||||
import { useProModal } from "@/hooks/use-pro-modal";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAction } from "@/hooks/use-action";
|
||||
import { stripeRedirect } from "@/actions/stripe-redirect";
|
||||
|
||||
export const ProModal = () => {
|
||||
const proModal = useProModal();
|
||||
|
||||
const { execute, isLoading } = useAction(stripeRedirect, {
|
||||
onSuccess: (data) => {
|
||||
window.location.href = data;
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
const onClick = () => {
|
||||
execute({});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={proModal.isOpen} onOpenChange={proModal.onClose}>
|
||||
<DialogContent className="max-w-md p-0 overflow-hidden">
|
||||
<div className="aspect-video relative flex items-center justify-center">
|
||||
<Image src="/hero.svg" alt="hero" className="object-cover" fill />
|
||||
</div>
|
||||
<div className="text-neutral-700 mx-auto space-y-6 p-6">
|
||||
<h1 className="font-semibold text-xl">Upgrade to Tasko Pro Today!</h1>
|
||||
<p className="text-xs font-semibold text-neutral-600">
|
||||
Explore the best of Tasko
|
||||
</p>
|
||||
<div className="pl-3">
|
||||
<ul className="text-sm list-disc">
|
||||
<li>Unlimited boards</li>
|
||||
<li className="italic">Advanced Checklists (Coming Soon)</li>
|
||||
<li className="italic">
|
||||
Admin and Security Features (Coming Soon)
|
||||
</li>
|
||||
<li className="italic">And More to Come Soon!</li>
|
||||
</ul>
|
||||
</div>
|
||||
<Button
|
||||
disabled={isLoading}
|
||||
onClick={onClick}
|
||||
className="w-full"
|
||||
variant="primary"
|
||||
>
|
||||
Upgrade
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
23
components/providers/modal-provider.tsx
Normal file
23
components/providers/modal-provider.tsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { CardModal } from "@/components/modals/card-modal";
|
||||
import { ProModal } from "@/components/modals/pro-modal";
|
||||
|
||||
export const ModalProvider = () => {
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!isMounted) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<CardModal />
|
||||
<ProModal />
|
||||
</>
|
||||
)
|
||||
}
|
18
components/providers/query-provider.tsx
Normal file
18
components/providers/query-provider.tsx
Normal file
|
@ -0,0 +1,18 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
export const QueryProvider = ({
|
||||
children
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) => {
|
||||
const [queryClient] = useState(() => new QueryClient());
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{children}
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
58
components/ui/accordion.tsx
Normal file
58
components/ui/accordion.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { ChevronDown } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Accordion = AccordionPrimitive.Root
|
||||
|
||||
const AccordionItem = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AccordionPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn("border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AccordionItem.displayName = "AccordionItem"
|
||||
|
||||
const AccordionTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
))
|
||||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
||||
|
||||
const AccordionContent = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Content
|
||||
ref={ref}
|
||||
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
))
|
||||
|
||||
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
50
components/ui/avatar.tsx
Normal file
50
components/ui/avatar.tsx
Normal file
|
@ -0,0 +1,50 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Avatar = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Avatar.displayName = AvatarPrimitive.Root.displayName
|
||||
|
||||
const AvatarImage = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Image
|
||||
ref={ref}
|
||||
className={cn("aspect-square h-full w-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
||||
|
||||
const AvatarFallback = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Fallback
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback }
|
60
components/ui/button.tsx
Normal file
60
components/ui/button.tsx
Normal file
|
@ -0,0 +1,60 @@
|
|||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline:
|
||||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
primary: "bg-sky-700 text-primary-foreground hover:bg-sky-700/90",
|
||||
transparent: "bg-transparent text-white hover:bg-white/20",
|
||||
gray: "bg-neutral-200 text-secondary-foreground hover:bg-neutral-300",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-9 rounded-md px-3",
|
||||
lg: "h-11 rounded-md px-8",
|
||||
icon: "h-10 w-10",
|
||||
inline: "h-auto px-2 py-1.5 text-sm",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
122
components/ui/dialog.tsx
Normal file
122
components/ui/dialog.tsx
Normal file
|
@ -0,0 +1,122 @@
|
|||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { X } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
const DialogPortal = DialogPrimitive.Portal;
|
||||
|
||||
const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-3xl translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
));
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogHeader.displayName = "DialogHeader";
|
||||
|
||||
const DialogFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogFooter.displayName = "DialogFooter";
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-lg font-semibold leading-none tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogPortal,
|
||||
DialogOverlay,
|
||||
DialogClose,
|
||||
DialogTrigger,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
};
|
25
components/ui/input.tsx
Normal file
25
components/ui/input.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export interface InputProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-10 w-full rounded-sm border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-0 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Input.displayName = "Input"
|
||||
|
||||
export { Input }
|
26
components/ui/label.tsx
Normal file
26
components/ui/label.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const labelVariants = cva(
|
||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||
)
|
||||
|
||||
const Label = React.forwardRef<
|
||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
||||
VariantProps<typeof labelVariants>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<LabelPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(labelVariants(), className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Label.displayName = LabelPrimitive.Root.displayName
|
||||
|
||||
export { Label }
|
33
components/ui/popover.tsx
Normal file
33
components/ui/popover.tsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Popover = PopoverPrimitive.Root
|
||||
|
||||
const PopoverTrigger = PopoverPrimitive.Trigger
|
||||
|
||||
const PopoverClose = PopoverPrimitive.Close
|
||||
|
||||
const PopoverContent = React.forwardRef<
|
||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
||||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
ref={ref}
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
))
|
||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName
|
||||
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverClose }
|
31
components/ui/separator.tsx
Normal file
31
components/ui/separator.tsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Separator = React.forwardRef<
|
||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||
>(
|
||||
(
|
||||
{ className, orientation = "horizontal", decorative = true, ...props },
|
||||
ref
|
||||
) => (
|
||||
<SeparatorPrimitive.Root
|
||||
ref={ref}
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"shrink-0 bg-border",
|
||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
)
|
||||
Separator.displayName = SeparatorPrimitive.Root.displayName
|
||||
|
||||
export { Separator }
|
140
components/ui/sheet.tsx
Normal file
140
components/ui/sheet.tsx
Normal file
|
@ -0,0 +1,140 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { X } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Sheet = SheetPrimitive.Root
|
||||
|
||||
const SheetTrigger = SheetPrimitive.Trigger
|
||||
|
||||
const SheetClose = SheetPrimitive.Close
|
||||
|
||||
const SheetPortal = SheetPrimitive.Portal
|
||||
|
||||
const SheetOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Overlay
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
))
|
||||
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName
|
||||
|
||||
const sheetVariants = cva(
|
||||
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
||||
{
|
||||
variants: {
|
||||
side: {
|
||||
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
||||
bottom:
|
||||
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
||||
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
|
||||
right:
|
||||
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
side: "right",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
interface SheetContentProps
|
||||
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||
VariantProps<typeof sheetVariants> {}
|
||||
|
||||
const SheetContent = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Content>,
|
||||
SheetContentProps
|
||||
>(({ side = "right", className, children, ...props }, ref) => (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(sheetVariants({ side }), className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
))
|
||||
SheetContent.displayName = SheetPrimitive.Content.displayName
|
||||
|
||||
const SheetHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-2 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
SheetHeader.displayName = "SheetHeader"
|
||||
|
||||
const SheetFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
SheetFooter.displayName = "SheetFooter"
|
||||
|
||||
const SheetTitle = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn("text-lg font-semibold text-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SheetTitle.displayName = SheetPrimitive.Title.displayName
|
||||
|
||||
const SheetDescription = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SheetDescription.displayName = SheetPrimitive.Description.displayName
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetPortal,
|
||||
SheetOverlay,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
15
components/ui/skeleton.tsx
Normal file
15
components/ui/skeleton.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Skeleton({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<div
|
||||
className={cn("animate-pulse rounded-md bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
24
components/ui/textarea.tsx
Normal file
24
components/ui/textarea.tsx
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export interface TextareaProps
|
||||
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
||||
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ className, ...props }, ref) => {
|
||||
return (
|
||||
<textarea
|
||||
className={cn(
|
||||
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Textarea.displayName = "Textarea"
|
||||
|
||||
export { Textarea }
|
30
components/ui/tooltip.tsx
Normal file
30
components/ui/tooltip.tsx
Normal file
|
@ -0,0 +1,30 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
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.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md 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}
|
||||
/>
|
||||
))
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
Loading…
Add table
Add a link
Reference in a new issue