2024-07-29 07:45:59 -07:00
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
import type { FC } from 'react';
|
|
|
|
|
import { useDeleteConversationTagMutation } from '~/data-provider';
|
|
|
|
|
import TooltipIcon from '~/components/ui/TooltipIcon';
|
|
|
|
|
import { NotificationSeverity } from '~/common';
|
|
|
|
|
import { useToastContext } from '~/Providers';
|
|
|
|
|
import { TrashIcon } from '~/components/svg';
|
|
|
|
|
import { Label } from '~/components/ui';
|
|
|
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
|
|
2024-07-29 19:25:36 -04:00
|
|
|
const DeleteBookmarkButton: FC<{
|
|
|
|
|
bookmark: string;
|
|
|
|
|
tabIndex?: number;
|
|
|
|
|
onFocus?: () => void;
|
|
|
|
|
onBlur?: () => void;
|
|
|
|
|
}> = ({ bookmark, tabIndex = 0, onFocus, onBlur }) => {
|
2024-07-29 07:45:59 -07:00
|
|
|
const localize = useLocalize();
|
|
|
|
|
const { showToast } = useToastContext();
|
|
|
|
|
|
|
|
|
|
const deleteBookmarkMutation = useDeleteConversationTagMutation({
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
showToast({
|
|
|
|
|
message: localize('com_ui_bookmarks_delete_success'),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onError: () => {
|
|
|
|
|
showToast({
|
|
|
|
|
message: localize('com_ui_bookmarks_delete_error'),
|
|
|
|
|
severity: NotificationSeverity.ERROR,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const confirmDelete = useCallback(async () => {
|
|
|
|
|
await deleteBookmarkMutation.mutateAsync(bookmark);
|
|
|
|
|
}, [bookmark, deleteBookmarkMutation]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<TooltipIcon
|
|
|
|
|
disabled={false}
|
|
|
|
|
appendLabel={false}
|
|
|
|
|
title="Delete Bookmark"
|
|
|
|
|
confirmMessage={
|
|
|
|
|
<Label htmlFor="bookmark" className="text-left text-sm font-medium">
|
2024-07-29 19:25:36 -04:00
|
|
|
{localize('com_ui_bookmark_delete_confirm')} {bookmark}
|
2024-07-29 07:45:59 -07:00
|
|
|
</Label>
|
|
|
|
|
}
|
|
|
|
|
confirm={confirmDelete}
|
2024-08-31 13:42:20 -04:00
|
|
|
className="transition-colors flex size-7 items-center justify-center rounded-lg duration-200 hover:bg-surface-hover"
|
2024-07-29 07:45:59 -07:00
|
|
|
icon={<TrashIcon className="size-4" />}
|
2024-07-29 19:25:36 -04:00
|
|
|
tabIndex={tabIndex}
|
|
|
|
|
onFocus={onFocus}
|
|
|
|
|
onBlur={onBlur}
|
2024-07-29 07:45:59 -07:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-07-29 19:25:36 -04:00
|
|
|
|
2024-07-29 07:45:59 -07:00
|
|
|
export default DeleteBookmarkButton;
|