Skip to content

Commit 28230d9

Browse files
authored
feat: delete button confirm (danny-avila#875)
* base for confirm delete * more like OpenAI
1 parent 2b54e3f commit 28230d9

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

client/src/components/Conversations/Conversation.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export default function Conversation({ conversation, retainView }) {
126126
renaming={renaming}
127127
cancelHandler={cancelHandler}
128128
retainView={retainView}
129+
title={title}
129130
/>
130131
</div>
131132
) : (

client/src/components/Conversations/DeleteButton.jsx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ import TrashIcon from '../svg/TrashIcon';
33
import CrossIcon from '../svg/CrossIcon';
44
import { useRecoilValue } from 'recoil';
55
import { useDeleteConversationMutation } from 'librechat-data-provider';
6-
6+
import { Dialog, DialogTrigger, Label } from '~/components/ui/';
7+
import DialogTemplate from '~/components/ui/DialogTemplate';
78
import store from '~/store';
9+
import { useLocalize } from '~/hooks';
810

9-
export default function DeleteButton({ conversationId, renaming, cancelHandler, retainView }) {
11+
export default function DeleteButton({ conversationId, renaming, retainView, title }) {
12+
const localize = useLocalize();
1013
const currentConversation = useRecoilValue(store.conversation) || {};
1114
const { newConversation } = store.useConversation();
1215
const { refreshConversations } = store.useConversations();
1316

17+
const confirmDelete = () => {
18+
deleteConvoMutation.mutate({ conversationId, source: 'button' });
19+
};
20+
1421
const deleteConvoMutation = useDeleteConversationMutation(conversationId);
1522

1623
useEffect(() => {
@@ -25,15 +32,31 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler,
2532
// eslint-disable-next-line react-hooks/exhaustive-deps
2633
}, [deleteConvoMutation.isSuccess]);
2734

28-
const clickHandler = () => {
29-
deleteConvoMutation.mutate({ conversationId, source: 'button' });
30-
};
31-
32-
const handler = renaming ? cancelHandler : clickHandler;
33-
3435
return (
35-
<button className="p-1 hover:text-white" onClick={handler}>
36-
{renaming ? <CrossIcon /> : <TrashIcon />}
37-
</button>
36+
<Dialog>
37+
<DialogTrigger asChild>
38+
<button className="p-1 hover:text-white">{renaming ? <CrossIcon /> : <TrashIcon />}</button>
39+
</DialogTrigger>
40+
<DialogTemplate
41+
title={localize('com_ui_delete_conversation')}
42+
className="max-w-[450px]"
43+
main={
44+
<>
45+
<div className="flex w-full flex-col items-center gap-2">
46+
<div className="grid w-full items-center gap-2">
47+
<Label htmlFor="chatGptLabel" className="text-left text-sm font-medium">
48+
{localize('com_ui_delete_conversation_confirm')} <strong>{title}</strong>
49+
</Label>
50+
</div>
51+
</div>
52+
</>
53+
}
54+
selection={{
55+
selectHandler: confirmDelete,
56+
selectClasses: 'bg-red-600 hover:bg-red-700 dark:hover:bg-red-800 text-white',
57+
selectText: localize('com_ui_delete'),
58+
}}
59+
/>
60+
</Dialog>
3861
);
3962
}

client/src/localization/languages/Eng.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export default {
2828
com_ui_of: 'of',
2929
com_ui_entries: 'Entries',
3030
com_ui_pay_per_call: 'All AI conversations in one place. Pay per call and not per month',
31+
com_ui_delete: 'Delete',
32+
com_ui_delete_conversation: 'Delete chat?',
33+
com_ui_delete_conversation_confirm: 'This will delete',
3134
com_auth_error_login:
3235
'Unable to login with the information provided. Please check your credentials and try again.',
3336
com_auth_no_account: 'Don\'t have an account?',

client/src/localization/languages/It.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default {
2929
com_ui_entries: 'Voci',
3030
com_ui_pay_per_call:
3131
'Tutte le conversazioni con l\'IA in un unico posto. Paga per chiamata e non al mese',
32+
com_ui_delete_conversation: 'Elimina chat?',
33+
com_ui_delete_conversation_confirm: 'Questo eliminerà',
3234
com_auth_error_login:
3335
'Impossibile effettuare l\'accesso con le informazioni fornite. Controlla le tue credenziali e riprova.',
3436
com_auth_no_account: 'Non hai un account?',

0 commit comments

Comments
 (0)