From 8b066104e633623bd35bb7af767618edfddd884c Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:41:49 +0300 Subject: [PATCH] Hotfix/can edit fix (#421) Fix canEdit() in Commetns --- src/components/Article/Comment/Comment.tsx | 37 +++++++++++----------- src/components/AuthorsList/AuthorsList.tsx | 13 ++++---- src/stores/ui.ts | 4 ++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index d22a8da7..d5b794e6 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -46,14 +46,13 @@ export const Comment = (props: Props) => { const canEdit = createMemo( () => Boolean(author()?.id) && - (props.comment?.created_by?.id === author().id || session()?.user?.roles.includes('editor')), + (props.comment?.created_by?.slug === author().slug || session()?.user?.roles.includes('editor')), ) - const comment = createMemo(() => props.comment) - const body = createMemo(() => (comment().body || '').trim()) + const body = createMemo(() => (props.comment.body || '').trim()) const remove = async () => { - if (comment()?.id) { + if (props.comment?.id) { try { const isConfirmed = await showConfirm({ confirmBody: t('Are you sure you want to delete this comment?'), @@ -63,7 +62,7 @@ export const Comment = (props: Props) => { }) if (isConfirmed) { - await deleteReaction(comment().id) + await deleteReaction(props.comment.id) await showSnackbar({ body: t('Comment successfully deleted') }) } @@ -113,8 +112,10 @@ export const Comment = (props: Props) => { return (