-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tag name length validation and add delete tag functionality + car…
…d link improvements
- Loading branch information
Showing
8 changed files
with
169 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use client"; | ||
|
||
import type { Tags } from "@prisma/client"; | ||
import { type ReactNode, useState } from "react"; | ||
|
||
import { toast } from "sonner"; | ||
|
||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/ui/dialog"; | ||
|
||
import { removeTag } from "@/server/actions/tags"; | ||
import { Button } from "@/ui/button"; | ||
import { LoaderIcon } from "lucide-react"; | ||
|
||
interface DeleteTagProps { | ||
tag: Tags; | ||
trigger: ReactNode; | ||
} | ||
|
||
const DeleteTag = ({ trigger, tag }: DeleteTagProps) => { | ||
const [open, setOpen] = useState<boolean>(false); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
|
||
const handleDeleteTag = async () => { | ||
try { | ||
setLoading(true); | ||
await removeTag(tag.id); | ||
setOpen(false); | ||
toast.success("Link deleted successfully.", { | ||
description: `The tag ${tag.name} has been deleted.`, | ||
}); | ||
} catch (error) { | ||
toast.error( | ||
"An error occurred while deleting the tag. Please try again.", | ||
); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger asChild>{trigger}</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Delete "{tag.name}" tag</DialogTitle> | ||
<DialogDescription> | ||
Delete the tag will not delete the links associated with it. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button | ||
variant="destructive" | ||
onClick={handleDeleteTag} | ||
disabled={loading} | ||
> | ||
{loading ? <LoaderIcon size={16} /> : "Delete Tag"} | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default DeleteTag; |
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