feat: delete post from timeline

This commit is contained in:
Nevo David 2025-07-03 16:35:36 +07:00
parent 86128f7573
commit 7c70bc7c79
3 changed files with 65 additions and 0 deletions

View File

@ -53,6 +53,7 @@ import { StatisticsModal } from '@gitroom/frontend/components/launches/statistic
import { useT } from '@gitroom/react/translation/get.transation.service.client';
import i18next from 'i18next';
import { AddEditModal } from '@gitroom/frontend/components/new-launch/add.edit.modal';
import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';
// Extend dayjs with necessary plugins
extend(isSameOrAfter);
@ -474,6 +475,7 @@ export const CalendarColumn: FC<{
},
[]
);
const editPost = useCallback(
(
loadPost: Post & {
@ -632,6 +634,34 @@ export const CalendarColumn: FC<{
},
[]
);
const deletePost = useCallback(
(post: Post) => async () => {
if (
!(await deleteDialog(
t(
'are_you_sure_you_want_to_delete_post',
'Are you sure you want to delete post?'
)
))
) {
return;
}
await fetch(`/posts/${post.group}`, {
method: 'DELETE',
});
toaster.show(
t('post_deleted_successfully', 'Post deleted successfully'),
'success'
);
reloadCalendarView();
},
[toaster, t]
);
const addProvider = useAddProvider();
return (
<div className="flex flex-col w-full min-h-full" ref={drop as any}>
@ -682,6 +712,7 @@ export const CalendarColumn: FC<{
duplicatePost={editPost(post, true)}
post={post}
integrations={integrations}
deletePost={deletePost(post)}
/>
</div>
</div>
@ -782,6 +813,7 @@ const CalendarItem: FC<{
isBeforeNow: boolean;
editPost: () => void;
duplicatePost: () => void;
deletePost: () => void;
statistics: () => void;
integrations: Integrations[];
state: State;
@ -803,6 +835,7 @@ const CalendarItem: FC<{
isBeforeNow,
state,
display,
deletePost,
} = props;
const preview = useCallback(() => {
window.open(`/p/` + post.id + '?share=true', '_blank');
@ -871,6 +904,15 @@ const CalendarItem: FC<{
onClick={statistics}
>
<Statistics />
</div>{' '}
<div
className={clsx(
'hidden group-hover:block hover:underline cursor-pointer',
post?.tags?.[0]?.tag?.color && 'mix-blend-difference'
)}
onClick={deletePost}
>
<DeletePost />
</div>
</div>
<div
@ -966,6 +1008,26 @@ export const Statistics = () => {
);
};
export const DeletePost = () => {
const t = useT();
return (
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
data-tooltip-id="tooltip"
data-tooltip-content={t('delete_post', 'Delete Post')}
>
<path
d="M15 10V18H9V10H15ZM14 4H9.9L8.9 5H6V7H18V5H15L14 4ZM17 8H7V18C7 19.1 7.9 20 9 20H15C16.1 20 17 19.1 17 18V8Z"
fill="currentColor"
/>
</svg>
);
};
export const SetSelectionModal: FC<{
sets: any[];
onSelect: (set: any) => void;

View File

@ -160,6 +160,7 @@ export class PostsRepository {
submittedForOrderId: true,
state: true,
intervalInDays: true,
group: true,
tags: {
select: {
tag: true,

View File

@ -180,6 +180,8 @@
"add_comment_or_post": "Add comment / post",
"you_are_in_global_editing_mode": "You are in global editing mode",
"the_post_should_be_at_least_6_characters_long": "The post should be at least 6 characters long",
"are_you_sure_you_want_to_delete_post": "Are you sure you want to delete this post?",
"post_deleted_successfully": "Post deleted successfully",
"delete_post": "Delete Post",
"save_as_draft": "Save as draft",
"post_now": "Post now",