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

[CAI-65] Chatbot History Layout #1086

Merged
merged 116 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
1615b60
Update chat input text
Sebastiano-Bertolin Jul 31, 2024
7c90a80
Update input text story
Sebastiano-Bertolin Jul 31, 2024
cc79026
chore: add chandeset
Sebastiano-Bertolin Jul 31, 2024
ee8a7ed
ammend change
Sebastiano-Bertolin Aug 1, 2024
6ddeeae
chore: add changeset
Sebastiano-Bertolin Aug 1, 2024
28652fb
Fix send button position
Sebastiano-Bertolin Aug 1, 2024
7694f9a
add mobile style and remove badge
Sebastiano-Bertolin Aug 1, 2024
7cc6f5a
Fix build error
Sebastiano-Bertolin Aug 1, 2024
5e8b5fb
Update chatbot message
Sebastiano-Bertolin Aug 1, 2024
99daddd
Update story
Sebastiano-Bertolin Aug 1, 2024
185595e
add changeset
Sebastiano-Bertolin Aug 1, 2024
db37d46
Reduce timestamp font size
Sebastiano-Bertolin Aug 2, 2024
f501ab0
Merge branch 'main' into feature/chatbot/CAI-90-chatbot-message
Sebastiano-Bertolin Aug 2, 2024
a7aa341
Cleanup imports
Sebastiano-Bertolin Aug 2, 2024
1f0544b
Merge branch 'feature/chatbot/CAI-90-new-input-textarea' into feature…
Sebastiano-Bertolin Aug 2, 2024
ca8229b
Update chat component with new layout
Sebastiano-Bertolin Aug 2, 2024
2592563
Improve componet layout and style
Sebastiano-Bertolin Aug 2, 2024
67dc013
add changeset
Sebastiano-Bertolin Aug 2, 2024
59656d2
Fix margins
Sebastiano-Bertolin Aug 5, 2024
aad1687
Merge branch 'feature/chatbot/CAI-90-update-chatbot-fab' into feature…
Sebastiano-Bertolin Aug 5, 2024
d406fdd
Remove menu logic
Sebastiano-Bertolin Aug 5, 2024
e7a406a
Merge branch 'feature/chatbot/CAI-90-chatbot-chat-updated-component' …
Sebastiano-Bertolin Aug 5, 2024
7c3e463
Update layout
Sebastiano-Bertolin Aug 5, 2024
586c0a7
Update history button
Sebastiano-Bertolin Aug 5, 2024
6e0b3a3
Merge branch 'feature/chatbot/CAI-90-chatbot-chat-updated-component' …
Sebastiano-Bertolin Aug 5, 2024
9ef1813
Auto instant scroll to botton when chat opens
Sebastiano-Bertolin Aug 5, 2024
96bbb85
Merge branch 'feature/chatbot/CAI-90-chatbot-chat-updated-component' …
Sebastiano-Bertolin Aug 5, 2024
464674d
Fix chatobot sizes
Sebastiano-Bertolin Aug 7, 2024
8fcf4a7
Enter to send
Sebastiano-Bertolin Aug 7, 2024
172ec44
Fix chatbot button border
Sebastiano-Bertolin Aug 7, 2024
c4084b3
Merge branch 'main' into feature/chatbot/CAI-90-update-chatbot-fab
Sebastiano-Bertolin Aug 7, 2024
b0a1fda
Apply suggestions from code review
Sebastiano-Bertolin Aug 7, 2024
2b9251c
Add date badge
Sebastiano-Bertolin Aug 7, 2024
6de113c
Fix story
Sebastiano-Bertolin Aug 7, 2024
d68a141
Merge branch 'main' into feature/chatbot/CAI-90-chatbot-message
Sebastiano-Bertolin Aug 7, 2024
6d9c87c
Merge branch 'main' into feature/chatbot/CAI-90-new-input-textarea
Sebastiano-Bertolin Aug 7, 2024
081b94f
Update apps/nextjs-website/src/components/molecules/Chat/Chat.tsx
Sebastiano-Bertolin Aug 7, 2024
bb075b7
Merge branch 'main' into feature/chatbot/CAI-90-chatbot-chat-updated-…
Sebastiano-Bertolin Aug 7, 2024
4bc0c72
Merge branch 'feature/chatbot/CAI-90-chatbot-message' into feature/ch…
Sebastiano-Bertolin Aug 7, 2024
ce3d152
Merge branch 'feature/chatbot/CAI-90-new-input-textarea' into feature…
Sebastiano-Bertolin Aug 7, 2024
9bdc3d7
Merge branch 'feature/chatbot/CAI-90-update-chatbot-fab' into feature…
Sebastiano-Bertolin Aug 7, 2024
8f07c65
Merge branch 'feature/chatbot/CAI-90-chatbot-chat-updated-component' …
Sebastiano-Bertolin Aug 7, 2024
fb7ea56
Add mobile support
Sebastiano-Bertolin Aug 8, 2024
7a0f69a
Apply suggestions from code review
Sebastiano-Bertolin Aug 8, 2024
bf147c1
Remove imports
Sebastiano-Bertolin Aug 8, 2024
5a69a61
Merge branch 'feature/chatbot/CAI-90-new-input-textarea' into feature…
Sebastiano-Bertolin Aug 8, 2024
8f2b11f
Add awaiting response animation
Sebastiano-Bertolin Aug 8, 2024
bc5042e
Merge branch 'feature/chatbot/CAI-90-chatbot-chat-updated-component' …
Sebastiano-Bertolin Aug 8, 2024
3d5a508
Improve dots generation
Sebastiano-Bertolin Aug 19, 2024
df8c591
Fix as per review
Sebastiano-Bertolin Aug 19, 2024
59aacfd
Add chatbot feedback button atom
Sebastiano-Bertolin Aug 19, 2024
87e07be
Add label
Sebastiano-Bertolin Aug 19, 2024
f0450c0
Apply suggestions from code review
Sebastiano-Bertolin Aug 20, 2024
0fea4f4
Merge branch 'feature/chatbot/CAI-90-update-chatbot-layout' into feat…
Sebastiano-Bertolin Aug 20, 2024
413cfa6
Add separator and feedback button behavuour
Sebastiano-Bertolin Aug 20, 2024
3559a98
Add query idd
Sebastiano-Bertolin Aug 20, 2024
5c4b07d
Add changeset
Sebastiano-Bertolin Aug 20, 2024
0c38d13
remove console log
Sebastiano-Bertolin Aug 20, 2024
1f22d26
Fix feedback management
Sebastiano-Bertolin Aug 20, 2024
6894314
Add copy to clipboard feature
Sebastiano-Bertolin Aug 20, 2024
c9921c2
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
Sebastiano-Bertolin Aug 20, 2024
91be456
add changeset
Sebastiano-Bertolin Aug 20, 2024
43f0572
Fix translation
Sebastiano-Bertolin Aug 20, 2024
da2599b
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
Sebastiano-Bertolin Aug 21, 2024
df6f15c
Merge branch 'feature/chatbot/CAI-64-feedback-toggle-button' into fea…
Sebastiano-Bertolin Aug 21, 2024
780e3b0
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
Sebastiano-Bertolin Aug 21, 2024
16708eb
Fix first messagge md and messge margin
Sebastiano-Bertolin Aug 21, 2024
274beed
Fix input font size and send butto size and margin
Sebastiano-Bertolin Aug 21, 2024
f1afebd
Fix chatbot fab in mobile view
Sebastiano-Bertolin Aug 21, 2024
4e23fcd
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
Sebastiano-Bertolin Aug 21, 2024
5123836
Merge branch 'feature/chatbot/CAI-64-feedback-toggle-button' into fea…
Sebastiano-Bertolin Aug 21, 2024
f118250
Apply suggestions from code review
Sebastiano-Bertolin Aug 21, 2024
d793fcd
Fix lint error
Sebastiano-Bertolin Aug 21, 2024
68ca1ee
Merge branch 'feature/chatbot/CAI-64-feedback-toggle-button' into fea…
Sebastiano-Bertolin Aug 21, 2024
c6ff316
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
MarcoPonchia Aug 27, 2024
e65af49
Merge branch 'main' into feature/chatbot/CAI-64-feedback-toggle-button
Sebastiano-Bertolin Aug 28, 2024
fa96094
Fix test
Sebastiano-Bertolin Aug 28, 2024
4501692
Merge branch 'feature/chatbot/CAI-64-feedback-toggle-button' into fea…
Sebastiano-Bertolin Aug 28, 2024
05a7238
Apply suggestions from code review
Sebastiano-Bertolin Aug 29, 2024
eb5b25d
Merge branch 'main' into feature/chatbot/CAI-80-copy-to-clipboard-answer
Sebastiano-Bertolin Aug 29, 2024
43fea57
Add Chatbot History page
Sebastiano-Bertolin Aug 30, 2024
d29f1ae
Add chatbot history list
Sebastiano-Bertolin Sep 4, 2024
5ab8a10
Add changeset
Sebastiano-Bertolin Sep 4, 2024
7ac2d00
Add Chatbot layout
Sebastiano-Bertolin Sep 4, 2024
cbceedf
chore: add changeset
Sebastiano-Bertolin Sep 4, 2024
0ce6832
Merge branch 'main' into feature/chatbot/CAI-65-chatobot-history-list
Sebastiano-Bertolin Sep 4, 2024
23de1d0
Fix story
Sebastiano-Bertolin Sep 4, 2024
d668e9d
Merge branch 'feature/chatbot/CAI-65-chatobot-history-list' of https:…
Sebastiano-Bertolin Sep 4, 2024
ad6a465
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 4, 2024
dfc69ac
Merge branch 'feature/chatbot/CAI-65-chatobot-history-list' into feat…
Sebastiano-Bertolin Sep 4, 2024
37864ea
Apply suggestions from code review
Sebastiano-Bertolin Sep 6, 2024
845bd12
Create fixture file for chatbot Stories
Sebastiano-Bertolin Sep 9, 2024
14488e1
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 9, 2024
8609819
Remove placeholder
Sebastiano-Bertolin Sep 9, 2024
0e612c4
Merge branch 'feature/chatbot/CAI-65-chatbot-history-layout' of https…
Sebastiano-Bertolin Sep 9, 2024
a3cb7af
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 16, 2024
82a523e
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 18, 2024
7e07612
Fix as per MR
Sebastiano-Bertolin Sep 18, 2024
798514d
Fix layout story
Sebastiano-Bertolin Sep 18, 2024
eb1ba93
Fix story list item overflow
Sebastiano-Bertolin Sep 18, 2024
f0277b4
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 18, 2024
4b87064
Hide menu voice if chatbot is not active
Sebastiano-Bertolin Sep 18, 2024
2eda9b9
Merge branch 'feature/chatbot/CAI-65-chatbot-history-layout' of https…
Sebastiano-Bertolin Sep 18, 2024
c68c694
Add mobile view as per mock
Sebastiano-Bertolin Sep 18, 2024
98fbdfc
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 18, 2024
a957226
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 19, 2024
e581d38
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 19, 2024
84e9642
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
Sebastiano-Bertolin Sep 19, 2024
d9c1795
Manage loading and empty history
Sebastiano-Bertolin Sep 19, 2024
d17ae26
add translation
Sebastiano-Bertolin Sep 19, 2024
b61bd7c
Fix linting
Sebastiano-Bertolin Sep 19, 2024
a8e9568
Revert change
Sebastiano-Bertolin Sep 19, 2024
4b48194
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
MarcoPonchia Sep 23, 2024
c95e10a
Add rerouting if chatbot not active
Sebastiano-Bertolin Sep 23, 2024
e3d4807
Merge branch 'feature/chatbot/CAI-65-chatbot-history-layout' of https…
Sebastiano-Bertolin Sep 23, 2024
6c44ab6
Merge branch 'main' into feature/chatbot/CAI-65-chatbot-history-layout
MarcoPonchia Sep 24, 2024
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
6 changes: 6 additions & 0 deletions .changeset/happy-stingrays-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs-website": minor
"storybook-app": minor
---

Add chatbot history list component
6 changes: 6 additions & 0 deletions .changeset/quick-buckets-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs-website": minor
"storybook-app": minor
---

Add chatobot layout component
58 changes: 58 additions & 0 deletions apps/nextjs-website/src/app/profile/chatbot-history/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use client';

import { useTranslations } from 'next-intl';
import { Stack, Typography } from '@mui/material';
import React, { useEffect } from 'react';
import ChatbotHistoryLayout from '@/components/organisms/ChatbotHistoryLayout/ChatbotHistoryLayout';
import { useChatbot } from '@/helpers/chatbot.helper';
import { useUser } from '@/helpers/user.helper';
import { isChatbotActive } from '@/config';
import Spinner from '@/components/atoms/Spinner/Spinner';
import { useRouter } from 'next/navigation';

const ChatbotHistory = () => {
const t = useTranslations();
const { user, loading } = useUser();
const { paginatedSessions, paginatedSessionsLoading, getSessionsByPage } =
useChatbot(true);
const router = useRouter();

useEffect(() => {
getSessionsByPage(1);
}, [getSessionsByPage]);

if (!isChatbotActive) {
router.replace('/not-found');
return null;
}

if (!user) {
return null;
}

return (
<Stack
sx={{
padding: { xs: '40px 24px', md: '80px 40px' },
width: '100%',
maxWidth: '694px',
}}
>
<Typography variant='h4' sx={{ marginBottom: '40px' }}>
{t('profile.chatbot.title')}
</Typography>
{(loading || paginatedSessionsLoading) && <Spinner />}
{!loading && !paginatedSessionsLoading && !paginatedSessions && (
<Typography>{t('profile.chatbot.noSessions')}</Typography>
)}
{!loading && !paginatedSessionsLoading && paginatedSessions && (
<ChatbotHistoryLayout
paginatedSessions={paginatedSessions}
getSessionsByPage={getSessionsByPage}
/>
)}
</Stack>
);
};

export default ChatbotHistory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { defaultLocale } from '@/config';
import { Session } from '@/lib/chatbot/queries';
import {
ListItem,
ListItemButton,
Stack,
Typography,
useTheme,
} from '@mui/material';

type DateFormatOptions = {
locale?: string;
options?: Intl.DateTimeFormatOptions;
};

const DEFAULT_DATE_FORMAT = {
locale: defaultLocale,
options: {
day: 'numeric',
month: 'numeric',
year: 'numeric',
},
} satisfies DateFormatOptions;

type ChatbotHistoryListItemProps = {
session: Session;
};

const ChatbotHistoryListItem = ({ session }: ChatbotHistoryListItemProps) => {
const { palette } = useTheme();
const formattedDate = new Intl.DateTimeFormat(
DEFAULT_DATE_FORMAT.locale,
DEFAULT_DATE_FORMAT.options
).format(new Date(session.createdAt));

return (
<ListItem>
<ListItemButton
sx={{ display: 'block', width: '100%' }}
href={`/profile/${session.id}/session-history`}
>
<Stack direction='column' spacing={3}>
<Typography
color={palette.text.secondary}
fontSize='0.875rem'
fontWeight='600'
>
{formattedDate}
</Typography>
<Typography
color={palette.text.primary}
fontSize='1rem'
fontWeight='600'
noWrap
component='span'
display='block'
textOverflow='ellipsis'
>
{session.title}
</Typography>
</Stack>
</ListItemButton>
</ListItem>
);
};

export default ChatbotHistoryListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {
capitalize,
Divider,
List,
ListItem,
Palette,
Typography,
useTheme,
} from '@mui/material';
import { defaultLocale } from '@/config';
import ChatbotHistoryListItem from '@/components/atoms/ChatbotHistoryListItem/ChatbotHistoryListItem';
import { Session } from '@/lib/chatbot/queries';

type DateFormatOptions = {
locale?: string;
options?: Intl.DateTimeFormatOptions;
};

const DEFAULT_DATE_FORMAT = {
locale: defaultLocale,
options: {
month: 'long',
year: 'numeric',
},
} satisfies DateFormatOptions;

type ChatbotHistoryList = {
sessionsList: Session[];
};

const ChatbotHistoryList = ({ sessionsList }: ChatbotHistoryList) => {
const { palette } = useTheme();
const uniqueDates = Array.from(
new Set(
sessionsList.map((session) =>
new Intl.DateTimeFormat(
DEFAULT_DATE_FORMAT.locale,
DEFAULT_DATE_FORMAT.options
).format(new Date(session.createdAt))
)
)
);

return (
<List>
{dateDividerSessionsItemsInterpolation(
uniqueDates,
sessionsList,
palette
)}
</List>
);
};

export default ChatbotHistoryList;

function dateDividerSessionsItemsInterpolation(
dateDividers: string[],
sessionsList: Session[],
palette: Palette
) {
const items = dateDividers.map((date) => {
const sessions = sessionsList.filter(
(session: Session) =>
new Intl.DateTimeFormat(
DEFAULT_DATE_FORMAT.locale,
DEFAULT_DATE_FORMAT.options
).format(new Date(session.createdAt)) === date
);
return sessions.map((session: Session) => session);
});
return items.flatMap((sameMonthItems) => (
<>
<ListItem>
<Typography
key={sameMonthItems[0].createdAt}
color={palette.text.primary}
fontSize='1.5rem'
fontWeight='700'
sx={{ padding: '1rem' }}
>
{capitalize(
new Intl.DateTimeFormat(
DEFAULT_DATE_FORMAT.locale,
DEFAULT_DATE_FORMAT.options
).format(new Date(sameMonthItems[0].createdAt))
)}
</Typography>
</ListItem>
{sameMonthItems.map((item, index) => [
<ChatbotHistoryListItem key={item.id} session={item} />,
<>
{sameMonthItems.length - 1 !== index && (
<Divider component='li' sx={{ marginX: '32px' }} />
)}
</>,
])}
</>
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ChatbotHistoryList from '@/components/molecules/ChatbotHistoryList/ChatbotHistoryList';
import { PaginatedSessions } from '@/lib/chatbot/queries';
import { Box, Pagination, Stack } from '@mui/material';
import { useEffect } from 'react';

type ChatbotHistoryLayoutProps = {
paginatedSessions: PaginatedSessions;
getSessionsByPage: (page: number) => null;
};

const ChatbotHistoryLayout = ({
paginatedSessions,
getSessionsByPage,
}: ChatbotHistoryLayoutProps) => {
useEffect(() => {
getSessionsByPage(1);
});

return (
<Stack direction='column' display='block'>
<ChatbotHistoryList sessionsList={paginatedSessions.items} />
<Box display='flex' marginY='1rem' width='100%' justifyContent='center'>
<Pagination
count={paginatedSessions.pages}
page={paginatedSessions.page}
onChange={(_, page) => getSessionsByPage(page)}
hidePrevButton={paginatedSessions.page === 1}
hideNextButton={paginatedSessions.page === paginatedSessions.pages}
/>
</Box>
</Stack>
);
};

export default ChatbotHistoryLayout;
15 changes: 11 additions & 4 deletions apps/nextjs-website/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ export const amplifyConfig = {
authenticationFlowType: 'CUSTOM_AUTH',
};

export const profileMenuItems: readonly {
readonly label: string;
readonly href: string;
}[] = [
const defaultItems = [
{ label: 'personalData.title', href: '/profile/personal-data' },
{ label: 'agreements.title', href: '/profile/agreements' },
];

export const profileMenuItems: readonly {
readonly label: string;
readonly href: string;
}[] = isChatbotActive
? [
...defaultItems,
{ label: 'chatbot.title', href: '/profile/chatbot-history' },
]
: defaultItems;

export const snackbarAutoHideDurationMs = 10_000;

export const baseUrl = isProduction
Expand Down
35 changes: 30 additions & 5 deletions apps/nextjs-website/src/helpers/chatbot.helper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
'use client';
import { useEffect, useState } from 'react';
import { sendChatbotQuery, sendChatbotFeedback } from '@/lib/chatbot';
import { Query } from '@/lib/chatbot/queries';
import {
sendChatbotQuery,
sendChatbotFeedback,
getChatbotQueries,
getChatbotHistory,
} from '@/lib/chatbot';
import { PaginatedSessions, Query } from '@/lib/chatbot/queries';

const HISTORY_PAGE_SIZE = 10;

export type ChatbotErrorsType =
| 'serviceDown'
Expand All @@ -13,12 +20,16 @@ export const useChatbot = (isUserAuthenticated: boolean) => {
const [isAwaitingResponse, setIsAwaitingResponse] = useState(false);
const [sessionId, setSessionId] = useState<string | null>(null);
const [queries, setQueries] = useState<Query[]>([]);
const [paginatedSessionsLoading, setPaginatedSessionsLoading] =
useState(true);
const [paginatedSessions, setPaginatedSessions] =
useState<PaginatedSessions | null>(null);
const [chatbotError, setChatbotError] = useState<ChatbotErrorsType | null>(
null
);

useEffect(() => {
if (sessionId || !isUserAuthenticated) {
if (!isUserAuthenticated) {
return;
}

Expand All @@ -42,8 +53,8 @@ export const useChatbot = (isUserAuthenticated: boolean) => {
setQueries([
...queries,
{
id: '',
sessionId: '',
id: '0',
sessionId: '0',
question: queryMessage,
queriedAt: queriedAt,
badAnswer: false,
Expand Down Expand Up @@ -82,12 +93,26 @@ export const useChatbot = (isUserAuthenticated: boolean) => {
return null;
};

const getSessionsByPage = (page: number) => {
getChatbotHistory(page, HISTORY_PAGE_SIZE)
.then((response) => setPaginatedSessions(response))
.finally(() => setPaginatedSessionsLoading(false));

return null;
};

const getSession = (sessionId: string) => getChatbotQueries(sessionId);

return {
isLoaded,
isAwaitingResponse,
queries,
sendQuery,
sendFeedback,
paginatedSessions,
getSessionsByPage,
getSession,
chatbotError,
paginatedSessionsLoading,
};
};
Loading
Loading