mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
feat: delete button confirm (#875)
* base for confirm delete * more like OpenAI
This commit is contained in:
parent
2b54e3f9fe
commit
28230d9305
4 changed files with 40 additions and 11 deletions
|
|
@ -126,6 +126,7 @@ export default function Conversation({ conversation, retainView }) {
|
|||
renaming={renaming}
|
||||
cancelHandler={cancelHandler}
|
||||
retainView={retainView}
|
||||
title={title}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -3,14 +3,21 @@ import TrashIcon from '../svg/TrashIcon';
|
|||
import CrossIcon from '../svg/CrossIcon';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { useDeleteConversationMutation } from 'librechat-data-provider';
|
||||
|
||||
import { Dialog, DialogTrigger, Label } from '~/components/ui/';
|
||||
import DialogTemplate from '~/components/ui/DialogTemplate';
|
||||
import store from '~/store';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
export default function DeleteButton({ conversationId, renaming, cancelHandler, retainView }) {
|
||||
export default function DeleteButton({ conversationId, renaming, retainView, title }) {
|
||||
const localize = useLocalize();
|
||||
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(() => {
|
||||
|
|
@ -25,15 +32,31 @@ 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={localize('com_ui_delete_conversation')}
|
||||
className="max-w-[450px]"
|
||||
main={
|
||||
<>
|
||||
<div className="flex w-full flex-col items-center gap-2">
|
||||
<div className="grid w-full items-center gap-2">
|
||||
<Label htmlFor="chatGptLabel" className="text-left text-sm font-medium">
|
||||
{localize('com_ui_delete_conversation_confirm')} <strong>{title}</strong>
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
selection={{
|
||||
selectHandler: confirmDelete,
|
||||
selectClasses: 'bg-red-600 hover:bg-red-700 dark:hover:bg-red-800 text-white',
|
||||
selectText: localize('com_ui_delete'),
|
||||
}}
|
||||
/>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue