Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delete button confirm #875

Merged
merged 2 commits into from
Sep 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
base for confirm delete
  • Loading branch information
berry-13 committed Sep 2, 2023
commit 1dc9f27f62b4e833f80adc68f1f1abff9bdc14f6
32 changes: 21 additions & 11 deletions client/src/components/Conversations/DeleteButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import TrashIcon from '../svg/TrashIcon';
import CrossIcon from '../svg/CrossIcon';
import { useRecoilValue } from 'recoil';
import { useDeleteConversationMutation } from 'librechat-data-provider';

import { Dialog, DialogTrigger } from '~/components/ui/';
import DialogTemplate from '~/components/ui/DialogTemplate';
import store from '~/store';

export default function DeleteButton({ conversationId, renaming, cancelHandler, retainView }) {
export default function DeleteButton({ conversationId, renaming, retainView }) {
const currentConversation = useRecoilValue(store.conversation) || {};
const { newConversation } = store.useConversation();
const { refreshConversations } = store.useConversations();

const confirmDelete = () => {
deleteConvoMutation.mutate({ conversationId, source: 'button' });
};

const deleteConvoMutation = useDeleteConversationMutation(conversationId);

useEffect(() => {
Expand All @@ -25,15 +30,20 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler,
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [deleteConvoMutation.isSuccess]);

const clickHandler = () => {
deleteConvoMutation.mutate({ conversationId, source: 'button' });
};

const handler = renaming ? cancelHandler : clickHandler;

return (
<button className="p-1 hover:text-white" onClick={handler}>
{renaming ? <CrossIcon /> : <TrashIcon />}
</button>
<Dialog>
<DialogTrigger asChild>
<button className="p-1 hover:text-white">{renaming ? <CrossIcon /> : <TrashIcon />}</button>
</DialogTrigger>
<DialogTemplate
title="Delete conversation"
description="Are you sure you want to delete this conversation? This is irreversible."
selection={{
selectHandler: confirmDelete,
selectClasses: 'bg-red-600 hover:bg-red-700 dark:hover:bg-red-800 text-white',
selectText: 'Delete',
}}
/>
</Dialog>
);
}