-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
856 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use client"; | ||
|
||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { useApiMutation } from "@/hooks/use-api-mutation"; | ||
import { DropdownMenuContentProps } from "@radix-ui/react-dropdown-menu"; | ||
import { Link2, Pencil, Trash } from "lucide-react"; | ||
import React from "react"; | ||
import { toast } from "sonner"; | ||
import { ConfirmDialog } from "./confirm-dialog"; | ||
import { Button } from "./ui/button"; | ||
import { useRenameModal } from "@/store/use-rename-modal"; | ||
|
||
interface ActionsProps { | ||
children: React.ReactNode; | ||
side?: DropdownMenuContentProps["side"]; | ||
sideOffset?: DropdownMenuContentProps["sideOffset"]; | ||
id: string; | ||
title: string; | ||
} | ||
|
||
export const Actions = ({ | ||
children, | ||
side, | ||
sideOffset, | ||
id, | ||
title, | ||
}: ActionsProps) => { | ||
const { onOpen } = useRenameModal(); | ||
const { mutate, pending } = useApiMutation(api.board.remove); | ||
|
||
const onCopyLink = () => { | ||
navigator.clipboard | ||
.writeText(`${window.location.origin}/board/${id}`) | ||
.then(() => toast.success("Link Copied")) | ||
.catch(() => toast.error("Failed to copy board link")); | ||
}; | ||
|
||
const onDelete = () => { | ||
mutate({ id }) | ||
.then(() => toast.success("Board deleted")) | ||
.catch(() => toast.error("Failed to delete board")); | ||
}; | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger> | ||
<DropdownMenuContent | ||
onClick={(e) => e.stopPropagation()} | ||
side={side} | ||
sideOffset={sideOffset} | ||
className="w-60" | ||
> | ||
<DropdownMenuItem onClick={onCopyLink} className="p-3 cursor-pointer"> | ||
<Link2 className="h-4 w-4 mr-2" /> | ||
Copy board link | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
onClick={() => onOpen(id, title)} | ||
className="p-3 cursor-pointer" | ||
> | ||
<Pencil className="h-4 w-4 mr-2" /> | ||
Rename | ||
</DropdownMenuItem> | ||
<ConfirmDialog | ||
header="Delete board?" | ||
description="This will delete the board and all of its contents." | ||
disabled={pending} | ||
onConfirm={onDelete} | ||
> | ||
<Button | ||
variant="ghost" | ||
className="p-3 cursor-pointer text-sm w-full justify-start font-normal" | ||
> | ||
<Trash className="h-4 w-4 mr-2" /> | ||
Delete | ||
</Button> | ||
</ConfirmDialog> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; |
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,52 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogTitle, | ||
AlertDialogTrigger, | ||
} from "@/components/ui/alert-dialog"; | ||
|
||
interface ConfirmModalProps { | ||
children: React.ReactNode; | ||
onConfirm: () => void; | ||
disabled?: boolean; | ||
header: string; | ||
description?: string; | ||
} | ||
|
||
export const ConfirmDialog = ({ | ||
children, | ||
onConfirm, | ||
disabled, | ||
header, | ||
description, | ||
}: ConfirmModalProps) => { | ||
const handleConfirm = () => { | ||
onConfirm(); | ||
}; | ||
|
||
return ( | ||
<AlertDialog> | ||
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>{header}</AlertDialogTitle> | ||
<AlertDialogDescription>{description}</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel>Cancel</AlertDialogCancel> | ||
<AlertDialogAction disabled={disabled} onClick={handleConfirm}> | ||
Confirm | ||
</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
); | ||
}; |
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,73 @@ | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "@/components/ui/dialog"; | ||
import { useRenameModal } from "@/store/use-rename-modal"; | ||
import { Input } from "@/components/ui/input"; | ||
import { FormEventHandler, useEffect, useState } from "react"; | ||
import { useApiMutation } from "@/hooks/use-api-mutation"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { Button } from "../ui/button"; | ||
import { toast } from "sonner"; | ||
|
||
export const RenameModal = () => { | ||
const { mutate, pending } = useApiMutation(api.board.update); | ||
|
||
const { isOpen, onClose, initialValues } = useRenameModal(); | ||
|
||
const [title, setTitle] = useState(initialValues.title); | ||
|
||
useEffect(() => { | ||
setTitle(initialValues.title); | ||
}, [initialValues.title]); | ||
|
||
const onSubmit: FormEventHandler<HTMLFormElement> = (e) => { | ||
e.preventDefault(); | ||
|
||
mutate({ | ||
id: initialValues.id, | ||
title, | ||
}) | ||
.then(() => { | ||
toast.success("Board renamed"); | ||
onClose(); | ||
}) | ||
.catch(() => toast.error("Failed to rename board")); | ||
}; | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={onClose}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Edit board title</DialogTitle> | ||
</DialogHeader> | ||
<DialogDescription>Enter a new title for this board</DialogDescription> | ||
<form onSubmit={onSubmit} className="space-y-4"> | ||
<Input | ||
disabled={pending} | ||
required | ||
maxLength={60} | ||
value={title} | ||
onChange={(e) => setTitle(e.target.value)} | ||
placeholder="Board title" | ||
/> | ||
<DialogFooter> | ||
<DialogClose asChild> | ||
<Button type="button" variant="outline"> | ||
Cancel | ||
</Button> | ||
</DialogClose> | ||
<Button disabled={pending} type="submit"> | ||
Save | ||
</Button> | ||
</DialogFooter> | ||
</form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.