Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor: change tag to tags

Marc Seitz35a3e4a9cf72
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index b6da5489..49700b3e 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -45,7 +45,7 @@ import { ButtonTooltip } from "@/components/ui/tooltip";
import { CustomFieldData } from "./custom-fields-panel";
import DomainSection from "./domain-section";
import { LinkOptions } from "./link-options";
-import TagSection from "./tag/tagSection";
+import TagSection from "./tags/tag-section";
export const DEFAULT_LINK_PROPS = (
linkType: LinkType,
diff --git a/components/links/link-sheet/tag/tagBadge.tsx b/components/links/link-sheet/tags/tag-badge.tsx
similarity index 55%
rename from components/links/link-sheet/tag/tagBadge.tsx
rename to components/links/link-sheet/tags/tag-badge.tsx
index e76a339c..6a2b2e4d 100644
--- a/components/links/link-sheet/tag/tagBadge.tsx
+++ b/components/links/link-sheet/tags/tag-badge.tsx
@@ -1,6 +1,4 @@
-import { Tag } from "lucide-react";
-
-import { Button } from "@/components/ui/button";
+import { TagIcon } from "lucide-react";
import { TagColorProps } from "@/lib/types";
import { cn } from "@/lib/utils";
@@ -21,29 +19,20 @@ export default function TagBadge({
isSelected?: boolean;
}) {
return (
- <Button
- size="sm"
- variant="secondary"
+ <span
className={cn(
- "my-auto block cursor-pointer whitespace-nowrap !rounded-full border px-2 py-0.5 text-sm",
+ "my-auto block whitespace-nowrap rounded-md border px-2 py-0.5 text-sm",
(withIcon || plus) &&
"flex items-center gap-x-1.5 p-1.5 sm:rounded-md sm:px-2 sm:py-0.5",
- color === "red" && "border-red-300 bg-red-100 text-red-600",
- color === "yellow" && "border-yellow-300 bg-yellow-100 text-yellow-600",
- color === "green" && "border-green-300 bg-green-100 text-green-600",
- color === "blue" && "border-blue-300 bg-blue-100 text-blue-600",
- color === "purple" && "border-purple-300 bg-purple-100 text-purple-600",
- color === "slate" && "border-stone-300 bg-stone-400 text-stone-600",
- color === "fuchsia" &&
- "border-fuchsia-300 bg-fuchsia-400 text-fuchsia-600",
+ COLORS_LIST.find((c) => c.color === color)?.css,
isSelected && "border-2 bg-transparent",
className,
)}
>
{withIcon && (
- <Tag
+ <TagIcon
className={cn(
- "shrink-0 p-0.5 dark:text-primary-foreground",
+ "!size-5 shrink-0 p-0.5 dark:text-primary-foreground",
isSelected && `bg-${color}-100 rounded-sm border border-gray-200`,
)}
/>
@@ -58,38 +47,38 @@ export default function TagBadge({
<span className="pr-1.5 opacity-30 md:pl-1 md:pr-2.5">|</span>+{plus}
</span>
)}
- </Button>
+ </span>
);
}
export const COLORS_LIST: { color: TagColorProps; css: string }[] = [
{
color: "red",
- css: "bg-red-100 text-red-600",
+ css: "border-red-300 bg-red-100 text-red-500",
},
{
color: "yellow",
- css: "bg-yellow-100 text-yellow-600",
+ css: "border-yellow-300 bg-yellow-100 text-yellow-500",
},
{
color: "green",
- css: "bg-green-100 text-green-600",
+ css: "border-emerald-300 bg-emerald-100 text-emerald-500",
},
{
color: "blue",
- css: "bg-blue-100 text-blue-600",
+ css: "border-blue-300 bg-blue-100 text-blue-500",
},
{
color: "purple",
- css: "bg-purple-100 text-purple-600",
+ css: "border-purple-300 bg-purple-100 text-purple-500",
},
{
color: "slate",
- css: "bg-slate-100 text-slate-600",
+ css: "border-stone-300 bg-stone-100 text-stone-500",
},
{
color: "fuchsia",
- css: "bg-fuchsia-100 text-fuchsia-600",
+ css: "border-fuchsia-300 bg-fuchsia-100 text-fuchsia-500",
},
];
diff --git a/components/links/link-sheet/tag/tagDetails.tsx b/components/links/link-sheet/tags/tag-details.tsx
similarity index 87%
rename from components/links/link-sheet/tag/tagDetails.tsx
rename to components/links/link-sheet/tags/tag-details.tsx
index ac32b0d8..d8b0c0cb 100644
--- a/components/links/link-sheet/tag/tagDetails.tsx
+++ b/components/links/link-sheet/tags/tag-details.tsx
@@ -4,11 +4,11 @@ import { useRouter } from "next/router";
import { PropsWithChildren, useMemo, useRef } from "react";
-import { BadgeTooltip } from "@/components/ui/tooltip";
+import { LinkWithViews, TagColorProps, TagProps } from "@/lib/types";
-import { LinkWithViews, TagProps } from "@/lib/types";
+import { BadgeTooltip } from "@/components/ui/tooltip";
-import TagBadge from "./tagBadge";
+import TagBadge from "./tag-badge";
function useOrganizedTags(tags: LinkWithViews["tags"]) {
const searchParams = useSearchParams();
@@ -59,7 +59,7 @@ function TagsTooltip({
<BadgeTooltip
align="end"
content={
- <div className="flex flex-wrap gap-1.5 p-3">
+ <div className="flex flex-wrap gap-1.5 rounded-md p-1">
{additionalTags.map((tag) => (
<TagButton key={tag.id} tag={tag} />
))}
@@ -94,14 +94,18 @@ function TagButton({ tag, plus }: { tag: TagProps; plus?: number }) {
params.delete("tagIds");
}
- router.push(`${pathname}?${params.toString()}`, undefined, {
- shallow: true,
- });
+ const paramString = params.toString();
+ router.push(
+ paramString ? `${pathname}?${paramString}` : `${pathname}`,
+ undefined,
+ { shallow: true },
+ );
};
return (
<button onClick={handleClick}>
<TagBadge
{...tag}
+ color={tag.color as TagColorProps}
withIcon
plus={plus}
isSelected={selectedTagIds.includes(tag.id)}
diff --git a/components/links/link-sheet/tag/tagSection.tsx b/components/links/link-sheet/tags/tag-section.tsx
similarity index 88%
rename from components/links/link-sheet/tag/tagSection.tsx
rename to components/links/link-sheet/tags/tag-section.tsx
index ada9ab9b..f26c7ef1 100644
--- a/components/links/link-sheet/tag/tagSection.tsx
+++ b/components/links/link-sheet/tags/tag-section.tsx
@@ -6,13 +6,13 @@ import { Tag } from "lucide-react";
import { toast } from "sonner";
import { mutate } from "swr";
+import { useTags } from "@/lib/swr/use-tags";
+import { TagProps } from "@/lib/types";
+
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { MultiSelect } from "@/components/ui/multi-select-v2";
-import { useTags } from "@/lib/swr/use-tags";
-import { TagProps } from "@/lib/types";
-
import { DEFAULT_LINK_TYPE } from "..";
function getTagOption(tag: TagProps) {
@@ -75,7 +75,7 @@ export default function TagSection({
};
const createTag = async (tag: string) => {
- const res = await fetch(`/api/teams/${teamId}/tag`, {
+ const res = await fetch(`/api/teams/${teamId}/tags`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -90,7 +90,7 @@ export default function TagSection({
const newTag = await res.json();
await mutate(
- `/api/teams/${teamId}/tag?${new URLSearchParams({
+ `/api/teams/${teamId}/tags?${new URLSearchParams({
sortBy: "createdAt",
sortOrder: "desc",
includeLinksCount: false,
@@ -110,14 +110,12 @@ export default function TagSection({
<>
<div className="flex justify-between">
<Label htmlFor="link-domain">Tags</Label>
- <Button
- variant="link"
- className="h-auto p-0 underline"
- type="button"
- onClick={() => router.push("/settings/tag")}
+ <a
+ href={`/settings/tags`}
+ className="text-xs text-muted-foreground hover:text-foreground"
>
- Create and Manage
- </Button>
+ Manage
+ </a>
</div>
<div className="flex">
<MultiSelect
@@ -127,9 +125,9 @@ export default function TagSection({
setIsPopoverOpen={setIsPopoverOpen}
isPopoverOpen={isPopoverOpen}
onValueChange={handleValueChange}
- placeholder="Select options"
+ placeholder="Select tags..."
maxCount={3}
- searchPlaceholder="Search or create tags..."
+ searchPlaceholder="Search or add tags..."
onCreate={(search) => createTag(search)}
/>
</div>
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 98b20c64..c7e6bcea 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -59,7 +59,7 @@ import LinkSheet, {
DEFAULT_LINK_PROPS,
type DEFAULT_LINK_TYPE,
} from "./link-sheet";
-import { TagColumn } from "./link-sheet/tag/tagDetails";
+import { TagColumn } from "./link-sheet/tags/tag-details";
import LinksVisitors from "./links-visitors";
export default function LinksTable({
diff --git a/components/settings/settings-header.tsx b/components/settings/settings-header.tsx
index d8895cf4..8d911000 100644
--- a/components/settings/settings-header.tsx
+++ b/components/settings/settings-header.tsx
@@ -54,9 +54,9 @@ export function SettingsHeader() {
segment: "presets",
},
{
- label: "Tag",
- href: `/settings/tag`,
- segment: "tag",
+ label: "Tags",
+ href: `/settings/tags`,
+ segment: "tags",
},
{
label: "Billing",
diff --git a/components/tag/add-tag-Modal.tsx b/components/tag/add-tag-Modal.tsx
deleted file mode 100644
index 02fb0cc6..00000000
--- a/components/tag/add-tag-Modal.tsx
+++ /dev/null
@@ -1,183 +0,0 @@
-import { ChangeEvent, FormEventHandler, useMemo, useRef } from "react";
-
-import { PlanEnum } from "@/ee/stripe/constants";
-
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
-
-import { usePlan } from "@/lib/swr/use-billing";
-import { TagColorProps } from "@/lib/types";
-import { cn } from "@/lib/utils";
-
-import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
-import { COLORS_LIST } from "../links/link-sheet/tag/tagBadge";
-import { Textarea } from "../ui/textarea";
-import { ToggleGroup, ToggleGroupItem } from "../ui/toggle-group";
-
-export function AddTagsModal({
- open,
- setMenuOpen,
- children,
- tagForm,
- setTagForm,
- handleSubmit,
- tagCount = 0,
-}: {
- tagCount: number | undefined;
- open: boolean;
- setMenuOpen: (open: boolean) => void;
- children?: React.ReactNode;
- tagForm: {
- color: TagColorProps;
- name: string;
- description: string | null;
- loading: boolean;
- id?: string;
- };
- setTagForm: React.Dispatch<
- React.SetStateAction<{
- color: TagColorProps;
- name: string;
- description: string | null;
- loading: boolean;
- }>
- >;
- handleSubmit: FormEventHandler<HTMLFormElement> | undefined;
-}) {
- const { isFree } = usePlan();
- const initialValues = useRef(tagForm);
-
- useMemo(() => {
- if (tagForm.id && tagForm.id !== initialValues.current.id) {
- initialValues.current = tagForm;
- }
- }, [tagForm.id]);
-
- const hasChanged =
- tagForm.name !== initialValues.current.name ||
- tagForm.color !== initialValues.current.color ||
- tagForm.description !== initialValues.current.description;
-
- const isFormValid =
- tagForm.name.length >= 3 && !!tagForm.color && (!tagForm.id || hasChanged);
-
- // If the team is on a free plan and has reached the max limit of 5 tags
- if (isFree && tagCount >= 5) {
- if (children) {
- return (
- <UpgradePlanModal clickedPlan={PlanEnum.Pro} trigger={"Create_tag"}>
- <Button>Upgrade to Create Tags</Button>
- </UpgradePlanModal>
- );
- }
- }
-
- function handleValueChange(
- e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
- ): void {
- setTagForm((prev) => ({
- ...prev,
- [e.target.name]: e.target.value,
- }));
- }
-
- return (
- <Dialog open={open} onOpenChange={setMenuOpen}>
- <DialogTrigger asChild>{children}</DialogTrigger>
- <DialogContent className="sm:max-w-[425px]">
- <DialogHeader className="text-start">
- <DialogTitle>{tagForm.id ? "Create Tag" : "Edit Tag"}</DialogTitle>
- <DialogDescription>
- Organize your Links with tags for easy categorization and search.
- </DialogDescription>
- </DialogHeader>
- <form onSubmit={handleSubmit}>
- <Label htmlFor="name" className="opacity-80">
- Tag name
- </Label>
- <Input
- name="name"
- id="name"
- value={tagForm.name}
- placeholder="documentation"
- className="mb-3 mt-1 w-full"
- onChange={(e) => handleValueChange(e)}
- />
-
- <Label htmlFor="color" className="opacity-80">
- Tag Color
- </Label>
- <ToggleGroup
- id="color"
- type="single"
- value={tagForm.color}
- onValueChange={(value: TagColorProps) => {
- if (value) {
- setTagForm((prev) => ({
- ...prev,
- color: value,
- }));
- }
- }}
- className="my-2 flex-shrink-0 flex-wrap !justify-start gap-3"
- >
- {COLORS_LIST.map((li) => (
- <ToggleGroupItem
- key={li.color}
- value={li.color}
- aria-label={`Select ${li.color}`}
- className={cn(
- "h-8 rounded-full border-0 px-3 text-sm transition-all",
- tagForm.color === li.color
- ? `ring-${li.color}-600 ring-2 text-${li.color}-600`
- : `border-transparent ${li.css}`,
- )}
- >
- {li.color}
- </ToggleGroupItem>
- ))}
- </ToggleGroup>
-
- <div>
- <Label htmlFor="description" className="opacity-80">
- Description
- </Label>
- <Textarea
- value={tagForm.description || ""}
- onChange={(e) => handleValueChange(e)}
- rows={5}
- name="description"
- id="description"
- placeholder="Add a description to understand the purpose of this tag..."
- className="mt-1 flex-1 bg-muted"
- autoComplete="off"
- />
- </div>
- <DialogFooter>
- <Button
- type="submit"
- className="mt-3 h-9 w-full"
- disabled={!isFormValid || tagForm.loading}
- >
- {tagForm.loading
- ? "Saving..."
- : tagForm.id
- ? "Save Changes"
- : "Create Tag"}
- </Button>
- </DialogFooter>
- </form>
- </DialogContent>
- </Dialog>
- );
-}
diff --git a/lib/swr/use-tags.ts b/lib/swr/use-tags.ts
index c8004432..09ea4a90 100644
--- a/lib/swr/use-tags.ts
+++ b/lib/swr/use-tags.ts
@@ -51,10 +51,11 @@ export function useTags({
isValidating,
error,
isLoading,
+ mutate,
} = useSWR<TagsWithTotalCount>(
teamId &&
enabled &&
- `/api/teams/${teamId}/tag?${new URLSearchParams({
+ `/api/teams/${teamId}/tags?${new URLSearchParams({
...query,
includeLinksCount,
} as Record<string, any>).toString()}`,
@@ -71,5 +72,6 @@ export function useTags({
isValidating,
error,
isLoading,
+ mutate,
};
}
diff --git a/pages/api/teams/[teamId]/tag/[tagId]/index.tsx b/pages/api/teams/[teamId]/tags/[id]/index.ts
similarity index 79%
rename from pages/api/teams/[teamId]/tag/[tagId]/index.tsx
rename to pages/api/teams/[teamId]/tags/[id]/index.ts
index 1f64ba24..93fd7609 100644
--- a/pages/api/teams/[teamId]/tag/[tagId]/index.tsx
+++ b/pages/api/teams/[teamId]/tags/[id]/index.ts
@@ -11,14 +11,6 @@ import { createTagBodySchema } from "..";
const updateTagBodySchema = createTagBodySchema;
-export const config = {
- api: {
- bodyParser: {
- sizeLimit: "4mb",
- },
- },
-};
-
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
@@ -53,17 +45,17 @@ export default async function handle(
errorhandler(error, res);
}
if (req.method === "PUT") {
- // PUT /api/teams/:teamId/tag/[tagId]
+ // PUT /api/teams/:teamId/tags/[id]
- const { teamId, tagId } = req.query as { teamId: string; tagId: string };
+ const { teamId, id } = req.query as { teamId: string; id: string };
const {
name,
color,
description = "",
} = updateTagBodySchema.parse(req.body);
- const tag = await prisma.tag.findFirst({
+ const tag = await prisma.tag.findUnique({
where: {
- id: tagId,
+ id: id,
teamId: teamId,
},
});
@@ -74,7 +66,7 @@ export default async function handle(
try {
const response = await prisma.tag.update({
where: {
- id: tagId,
+ id: id,
},
data: {
name,
@@ -88,14 +80,11 @@ export default async function handle(
return res.status(500).json({ error: (error as Error).message });
}
} else if (req.method === "DELETE") {
- // DELETE /api/teams/:teamId/tag/[tagId]
- const { teamId, tagId } = req.query as { teamId: string; tagId: string };
+ // DELETE /api/teams/:teamId/tags/[id]
+ const { teamId, id } = req.query as { teamId: string; id: string };
// First verify the tag belongs to the team
- const tag = await prisma.tag.findFirst({
- where: {
- id: tagId,
- teamId: teamId,
- },
+ const tag = await prisma.tag.findUnique({
+ where: { id, teamId },
});
if (!tag) {
@@ -104,11 +93,9 @@ export default async function handle(
// Then delete the tag
await prisma.tag.delete({
- where: {
- id: tagId,
- },
+ where: { id, teamId },
include: {
- taggedItems: true,
+ items: true,
},
});
return res.status(204).end();
diff --git a/pages/api/teams/[teamId]/tag/index.ts b/pages/api/teams/[teamId]/tags/index.ts
similarity index 97%
rename from pages/api/teams/[teamId]/tag/index.ts
rename to pages/api/teams/[teamId]/tags/index.ts
index 9c50bbbd..a3189cbe 100644
--- a/pages/api/teams/[teamId]/tag/index.ts
+++ b/pages/api/teams/[teamId]/tags/index.ts
@@ -4,15 +4,15 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth";
import { z } from "zod";
-import {
- COLORS_LIST,
- randomBadgeColor,
-} from "@/components/links/link-sheet/tag/tagBadge";
-
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser, tagColors } from "@/lib/types";
+import {
+ COLORS_LIST,
+ randomBadgeColor,
+} from "@/components/links/link-sheet/tags/tag-badge";
+
export const config = {
api: {
bodyParser: {
@@ -75,7 +75,7 @@ export const createTagBodySchema = z
.string()
.trim()
.max(120)
- .optional()
+ .nullish()
.describe("The description of the tag to create."),
})
.partial()
@@ -124,7 +124,6 @@ export default async function handle(
}
if (req.method === "GET") {
// GET /api/teams/:teamId/tag
-
const { search, includeLinksCount, sortBy, sortOrder, pageSize, page } =
searchParamsSchema.parse(req.query);
@@ -148,7 +147,7 @@ export default async function handle(
...(includeLinksCount && {
_count: {
select: {
- taggedItems: true,
+ items: true,
},
},
}),
diff --git a/pages/settings/tag.tsx b/pages/settings/tags.tsx
similarity index 84%
rename from pages/settings/tag.tsx
rename to pages/settings/tags.tsx
index 3d3adc10..8f3ac554 100644
--- a/pages/settings/tag.tsx
+++ b/pages/settings/tags.tsx
@@ -4,21 +4,27 @@ import { useEffect, useState } from "react";
import { useTeam } from "@/context/team-context";
import {
- CircleHelpIcon,
+ InfoIcon,
MoreHorizontalIcon,
Settings2Icon,
Tag,
+ TagIcon,
TrashIcon,
} from "lucide-react";
import { toast } from "sonner";
-import { mutate } from "swr";
import { z } from "zod";
+import { useTags } from "@/lib/swr/use-tags";
+import { TagColorProps, tagColors } from "@/lib/types";
+
import AppLayout from "@/components/layouts/app";
-import { randomBadgeColor } from "@/components/links/link-sheet/tag/tagBadge";
+import {
+ COLORS_LIST,
+ randomBadgeColor,
+} from "@/components/links/link-sheet/tags/tag-badge";
import { SearchBoxPersisted } from "@/components/search-box";
import { SettingsHeader } from "@/components/settings/settings-header";
-import { AddTagsModal } from "@/components/tag/add-tag-Modal";
+import { AddTagsModal } from "@/components/tags/add-tag-modal";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
@@ -47,14 +53,6 @@ import {
} from "@/components/ui/table";
import { BadgeTooltip } from "@/components/ui/tooltip";
-import { useTags } from "@/lib/swr/use-tags";
-import {
- TagColorProps,
- TagProps,
- TagsWithTotalCount,
- tagColors,
-} from "@/lib/types";
-
const schema = z.object({
name: z
.string()
@@ -66,7 +64,7 @@ const schema = z.object({
.string()
.trim()
.max(120)
- .optional()
+ .nullish()
.describe("The description of the tag to create."),
color: z.enum(tagColors, {
required_error: "Please select a color for the tag",
@@ -106,6 +104,7 @@ export default function TagSetting() {
tags: availableTags,
loading: loadingTags,
isValidating,
+ mutate: mutateTags,
} = useTags({
query: {
sortBy: "createdAt",
@@ -119,31 +118,10 @@ export default function TagSetting() {
const handleDeleteTag = async (tagId: string) => {
toast.promise(
- fetch(`/api/teams/${teamId}/tag/${tagId}`, {
+ fetch(`/api/teams/${teamId}/tags/${tagId}`, {
method: "DELETE",
}).then(() => {
- mutate(
- `/api/teams/${teamId}/tag?${new URLSearchParams({
- sortBy: "createdAt",
- sortOrder: "desc",
- page: currentPage,
- pageSize: 10,
- ...(searchQuery ? { search: String(searchQuery) } : {}),
- includeLinksCount: true,
- } as Record<string, any>).toString()}`,
- null,
- {
- populateCache: (_, tags: TagsWithTotalCount | undefined) => {
- if (!tags) return { tags: [], totalCount: 0 };
-
- return {
- tags: tags.tags.filter((tag) => tag.id !== tagId),
- totalCount: tags.totalCount > 0 ? tags.totalCount - 1 : 0,
- };
- },
- revalidate: false,
- },
- );
+ mutateTags();
}),
{
loading: "Deleting tag...",
@@ -163,6 +141,8 @@ export default function TagSetting() {
color: tagForm.color,
});
+ console.log(validation);
+
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}
@@ -173,8 +153,8 @@ export default function TagSetting() {
}));
const url = tagForm.id
- ? `/api/teams/${teamId}/tag/${tagForm.id}`
- : `/api/teams/${teamId}/tag`;
+ ? `/api/teams/${teamId}/tags/${tagForm.id}`
+ : `/api/teams/${teamId}/tags`;
const method = tagForm.id ? "PUT" : "POST";
@@ -200,35 +180,9 @@ export default function TagSetting() {
}));
return;
}
- const newTag = await response.json();
-
- mutate(
- `/api/teams/${teamId}/tag?${new URLSearchParams({
- sortBy: "createdAt",
- sortOrder: "desc",
- page: currentPage,
- pageSize: 10,
- ...(searchQuery ? { search: String(searchQuery) } : {}),
- includeLinksCount: true,
- } as Record<string, any>).toString()}`,
- (tags: TagsWithTotalCount | undefined) => {
- if (!tags?.tags) return { tags: [newTag], totalCount: 1 };
- const updatedTags: TagProps[] = tagForm.id
- ? tags.tags.map((tag: TagProps) =>
- tag.id === tagForm.id ? newTag : tag,
- )
- : [newTag, ...tags.tags];
+ mutateTags();
- return {
- tags: updatedTags,
- totalCount: tagForm.id ? tags.totalCount : tags.totalCount + 1,
- };
- },
- {
- revalidate: false,
- },
- );
setOpen(false);
toast.success(
tagForm.id ? "Tag updated successfully!" : "Tag created successfully!",
@@ -296,9 +250,9 @@ export default function TagSetting() {
<div className="flex items-center overflow-visible sm:space-x-3">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
- <Tag
+ <TagIcon
size={24}
- className={`rounded-sm border border-gray-200 dark:text-primary-foreground bg-${tag.color}-100 p-1`}
+ className={`rounded-sm border p-1 ${COLORS_LIST.find((c) => c.color === tag.color)?.css ?? ""}`}
/>
<p>{tag.name}</p>
{!!tag.description && (
@@ -306,7 +260,7 @@ export default function TagSetting() {
content={tag.description}
key="tag_tooltip"
>
- <CircleHelpIcon className="h-4 w-4 shrink-0 cursor-pointer text-muted-foreground hover:text-foreground" />
+ <InfoIcon className="h-4 w-4 shrink-0 cursor-pointer text-muted-foreground hover:text-foreground" />
</BadgeTooltip>
)}
</div>
@@ -316,7 +270,7 @@ export default function TagSetting() {
{/* Link Count */}
<TableCell className="text-center text-sm text-muted-foreground sm:text-right">
<Button variant="outline" size="sm">
- {tag._count?.taggedItems || 0} links
+ {tag._count?.items || 0} links
</Button>
</TableCell>
@@ -340,7 +294,7 @@ export default function TagSetting() {
onClick={(e) => {
e.stopPropagation();
setTagForm({
- color: tag.color,
+ color: tag.color as TagColorProps,
name: tag.name,
description: tag.description,
id: tag.id,