Skip to content

Commit

Permalink
[CAI-237] Add modal for history deletion (#1216)
Browse files Browse the repository at this point in the history
* add modal

* add changeset

* fix required by review

---------

Co-authored-by: marcobottaro <[email protected]>
  • Loading branch information
MarBert and marcobottaro authored Oct 30, 2024
1 parent e5e9647 commit acae444
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-pumpkins-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": minor
---

Add modal to confirm history deletion
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import ChatbotHistoryMessages from '@/components/molecules/ChatbotHistoryMessage
import { defaultLocale } from '@/config';
import { Query } from '@/lib/chatbot/queries';
import { Delete } from '@mui/icons-material';
import { Box, Button, Stack, Typography, useTheme } from '@mui/material';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
Stack,
Typography,
useTheme,
} from '@mui/material';
import { isEmpty } from 'fp-ts/lib/Array';
import { useTranslations } from 'next-intl';
import React from 'react';
import React, { useState } from 'react';

type DateFormatOptions = {
locale?: string;
Expand Down Expand Up @@ -39,9 +50,18 @@ const ChatbotHistoryDetailLayout = ({
nextSession,
onDeleteChatSession,
}: ChatbotHistoryDetailLayoutProps) => {
const [open, setOpen] = useState(false);
const t = useTranslations();
const { palette } = useTheme();

const handleClickOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

if (isEmpty(queries)) {
return (
<Typography variant='h4'>{t('chatBot.thereAreNoMessages')}</Typography>
Expand All @@ -56,6 +76,33 @@ const ChatbotHistoryDetailLayout = ({

return (
<Stack direction='column' spacing={2}>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby='alert-dialog-title'
aria-describedby='alert-dialog-description'
>
<DialogTitle id='alert-dialog-title'>
{t('chatBot.deleteHeader')}
</DialogTitle>
<DialogContent>
<DialogContentText id='alert-dialog-description'>
{t('chatBot.confirmDelete')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button variant='outlined' onClick={handleClose}>
{t('chatBot.deleteDismiss')}
</Button>
<Button
variant='contained'
onClick={() => onDeleteChatSession(firstQuery.sessionId)}
autoFocus
>
{t('chatBot.deleteConfirm')}
</Button>
</DialogActions>
</Dialog>
<Typography variant='h4'>{firstQuery.question}</Typography>
<Stack direction='row' justifyContent='space-between'>
<Typography
Expand All @@ -70,7 +117,7 @@ const ChatbotHistoryDetailLayout = ({
startIcon={<Delete />}
color='error'
sx={{ display: { xs: 'none', sm: 'flex' } }}
onClick={() => onDeleteChatSession(firstQuery.sessionId)}
onClick={handleClickOpen}
>
{t('chatBot.deleteChat')}
</Button>
Expand Down
4 changes: 4 additions & 0 deletions apps/nextjs-website/src/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@
"copied": "Copiato",
"welcomeMessage": "**Benvenuto nel Dev Portal!**\n\nSono _Discovery_, il tuo assistente virtuale per la documentazione tecnica. Posso aiutarti con informazioni su API, guide e altro.\n\n_Nota_: Discovery è in versione beta, quindi alcune risposte potrebbero non essere accurate. Verifica sempre le informazioni importanti con la documentazione ufficiale.\n\nCome posso aiutarti oggi?",
"deleteChat": "Elimina Chat",
"deleteHeader":"Elimina le conversazioni",
"deleteConfirm": "Si",
"deleteDismiss": "No",
"confirmDelete": "Sei sicuro di voler eliminare tutte le conversazioni passate?",
"previousChat": "Chat Precedente",
"nextChat": "Chat Successiva",
"guestMessage": "Ciao sono _Discovery_ , il chatbot di DevPortal!\n\nPosso aiutarti a trovare in modo semplice e rapido le informazioni presenti nella documentazione del Portale.\n\nPer poter accedere al servizio, ti invito ad [accedere]({host}/auth/login)",
Expand Down

0 comments on commit acae444

Please sign in to comment.