diff --git a/apps/web/src/views/board/components/List.tsx b/apps/web/src/views/board/components/List.tsx index 463dfeb6..cfed9de1 100644 --- a/apps/web/src/views/board/components/List.tsx +++ b/apps/web/src/views/board/components/List.tsx @@ -9,6 +9,8 @@ import { HiOutlineTrash, } from "react-icons/hi2"; +import { authClient } from "@kan/auth/client"; + import Dropdown from "~/components/Dropdown"; import { usePermissions } from "~/hooks/usePermissions"; import { useModal } from "~/providers/modal"; @@ -24,6 +26,7 @@ interface ListProps { interface List { publicId: string; name: string; + createdBy?: string | null; } interface FormValues { @@ -41,6 +44,9 @@ export default function List({ }: ListProps) { const { openModal } = useModal(); const { canCreateCard, canEditList, canDeleteList } = usePermissions(); + const { data: session } = authClient.useSession(); + const isCreator = list.createdBy && session?.user.id === list.createdBy; + const canEdit = canEditList || isCreator; const openNewCardForm = (publicListId: PublicListId) => { if (!canCreateCard) return; @@ -62,7 +68,7 @@ export default function List({ }); const onSubmit = (values: FormValues) => { - if (!canEditList) return; + if (!canEdit) return; updateList.mutate({ listPublicId: values.listPublicId, name: values.name, @@ -94,7 +100,7 @@ export default function List({ type="text" {...register("name")} onBlur={handleSubmit(onSubmit)} - readOnly={!canEditList} + readOnly={!canEdit} className="w-full border-0 bg-transparent px-4 pt-1 text-sm font-medium text-neutral-900 focus:ring-0 focus-visible:outline-none dark:text-dark-1000" /> @@ -124,7 +130,7 @@ export default function List({ }, ] : []), - ...(canDeleteList + ...(canDeleteList || isCreator ? [ { label: t`Delete list`, diff --git a/apps/web/src/views/card/components/Comment.tsx b/apps/web/src/views/card/components/Comment.tsx index b51b076c..e9587c36 100644 --- a/apps/web/src/views/card/components/Comment.tsx +++ b/apps/web/src/views/card/components/Comment.tsx @@ -91,7 +91,7 @@ const Comment = ({ }, ] : []), - ...((isAuthor || isAdmin) && canDeleteComment + ...((isAuthor || canDeleteComment) ? [ { label: t`Delete comment`, diff --git a/apps/web/src/views/card/components/Dropdown.tsx b/apps/web/src/views/card/components/Dropdown.tsx index af8f2309..c6308398 100644 --- a/apps/web/src/views/card/components/Dropdown.tsx +++ b/apps/web/src/views/card/components/Dropdown.tsx @@ -5,13 +5,21 @@ import { HiOutlineTrash, } from "react-icons/hi2"; +import { authClient } from "@kan/auth/client"; + import Dropdown from "~/components/Dropdown"; import { usePermissions } from "~/hooks/usePermissions"; import { useModal } from "~/providers/modal"; -export default function CardDropdown() { +export default function CardDropdown({ + cardCreatedBy, +}: { + cardCreatedBy?: string | null; +}) { const { openModal } = useModal(); const { canEditCard, canDeleteCard } = usePermissions(); + const { data: session } = authClient.useSession(); + const isCreator = cardCreatedBy && session?.user.id === cardCreatedBy; const items = [ ...(canEditCard @@ -25,7 +33,7 @@ export default function CardDropdown() { }, ] : []), - ...(canDeleteCard + ...(canDeleteCard || isCreator ? [ { label: t`Delete card`, diff --git a/apps/web/src/views/card/index.tsx b/apps/web/src/views/card/index.tsx index 8e726fa3..700b34a4 100644 --- a/apps/web/src/views/card/index.tsx +++ b/apps/web/src/views/card/index.tsx @@ -14,6 +14,8 @@ import Modal from "~/components/modal"; import { NewWorkspaceForm } from "~/components/NewWorkspaceForm"; import { PageHead } from "~/components/PageHead"; import { EditYouTubeModal } from "~/components/YouTubeEmbed/EditYouTubeModal"; +import { authClient } from "@kan/auth/client"; + import { usePermissions } from "~/hooks/usePermissions"; import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; @@ -46,6 +48,7 @@ interface FormValues { export function CardRightPanel({ isTemplate }: { isTemplate?: boolean }) { const router = useRouter(); const { canEditCard } = usePermissions(); + const { data: session } = authClient.useSession(); const cardId = Array.isArray(router.query.cardId) ? router.query.cardId[0] : router.query.cardId; @@ -54,6 +57,9 @@ export function CardRightPanel({ isTemplate }: { isTemplate?: boolean }) { cardPublicId: cardId ?? "", }); + const isCreator = card?.createdBy && session?.user.id === card.createdBy; + const canEdit = canEditCard || isCreator; + const board = card?.list.board; const labels = board?.labels; const workspaceMembers = board?.workspace.members; @@ -112,7 +118,7 @@ export function CardRightPanel({ isTemplate }: { isTemplate?: boolean }) { return (
- {canEditCard && ( + {canEdit && ( <>

{t`List`}

@@ -169,6 +175,7 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) { const { showPopup } = usePopup(); const { workspace } = useWorkspace(); const { canEditCard } = usePermissions(); + const { data: session } = authClient.useSession(); const [activeChecklistForm, setActiveChecklistForm] = useState( null, ); @@ -181,6 +188,9 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) { cardPublicId: cardId ?? "", }); + const isCreator = card?.createdBy && session?.user.id === card.createdBy; + const canEdit = canEditCard || isCreator; + const refetchCard = async () => { if (cardId) await utils.card.byId.refetch({ cardPublicId: cardId }); }; @@ -305,7 +315,7 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) {
- +
)} @@ -333,10 +343,10 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) {