Skip to content

Commit a10a003

Browse files
committed
Latest Update.
1 parent f4deee8 commit a10a003

File tree

10 files changed

+51
-38
lines changed

10 files changed

+51
-38
lines changed

AI/GenAI-ChatBot-application-sample/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AI/GenAI-ChatBot-application-sample/src/app/ErrorBoundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ErrorBoundary extends Component<Props, State> {
2727
public render() {
2828
if (this.state.hasError) {
2929
//TODO: Rout to aiChat home page
30-
return <h1>Sorry.. there was an error</h1>;
30+
return <div>Sorry.. there was an error</div>;
3131
}
3232

3333
return this.props.children;

AI/GenAI-ChatBot-application-sample/src/app/components/chatbot/chatbot.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import EnterpriseChatIcon from "@/app/svgs/chatbot/enterpriseChat.svg";
77
import EmptyPromptIcon from '@/app/svgs/chatbot/emptyPrompt.svg';
88
import LoadingIcon from '@/app/svgs/loaderMain.svg';
99
import Prompt, { PromptItem, UserType } from './prompt/prompt';
10-
import { useGetMessagesQuery, useSendMessageMutation } from '@/lib/api/chatApi.slice';
10+
import { closeSocket, useGetMessagesQuery, useSendMessageMutation } from '@/lib/api/chatApi.slice';
1111
import { skip } from '@/lib/api/api.slice';
1212
import rootSelector from '@/lib/selectors/root.selector';
1313
import { ChatMessage } from '@/lib/store.types';
@@ -191,6 +191,7 @@ const Chatbot = () => {
191191
}, [isFetching, dispatch]);
192192

193193
useEffect(() => {
194+
closeSocket();
194195
resetQuestion();
195196
dispatch(resetMessages());
196197
}, [dispatch, chatId])
@@ -234,7 +235,7 @@ const Chatbot = () => {
234235

235236
const isSendMessageDisabled = useMemo(() => {
236237
const isWriting = promptList[promptList.length - 1]?.isWriting;
237-
const isDisabled = !knowledgebase || isLoading || !chatId || isWriting;
238+
const isDisabled = !knowledgebase || !chatId || isWriting;
238239

239240
if (!isDisabled) {
240241
setTimeout(() => {
@@ -246,11 +247,11 @@ const Chatbot = () => {
246247
}
247248

248249
return isDisabled;
249-
}, [knowledgebase, isLoading, chatId, promptList])
250+
}, [knowledgebase, chatId, promptList])
250251

251252
const setNewChatId = (chatId: string) => {
252-
refetch();
253253
dispatch(setChatId(chatId));
254+
refetch();
254255
}
255256

256257
const ConversationStarterPrompts = () => {

AI/GenAI-ChatBot-application-sample/src/app/components/loginForm/loginForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { NOTIFICATION_CONSTS } from '../NotificationGroup/notification.consts';
1616
import { setAuth } from '@/lib/slices/auth.slice';
1717
import { ClerkSignIn } from '@/app/services/clerk.service';
1818
import { SignInResult, LoginProvider } from '@/lib/api/api.types';
19-
import useRunOnce from '@/app/hooks/useRunOnce';
2019
import useRunUntil from '@/app/hooks/useRunUntil';
2120

2221
const LoginForm = () => {

AI/GenAI-ChatBot-application-sample/src/app/components/panels/historyPanel/historyPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const HistoryPanel = ({ isExpanded, isLoading, promptList, historyList, toggleEx
2727
<div className={_Classes(styles.chatHistory, panelStyles.panel, { [panelStyles.expanded]: isExpanded })}>
2828
<PanelHeader title='History' isLoading={isLoading} panelType='history' toggleExpanded={toggleExpanded} />
2929
<div className={_Classes(styles.historyList, { [styles.emptyHistory]: promptList.length === 0 && historyList.size === 0 })}>
30-
{promptList.length > 0 || (historyList.size > 0 && !isLoading) ? Array.from(historyList.keys()).sort((hist1, hist2) => hist2 - hist1).map(id => {
30+
{promptList.length > 0 || historyList.size > 0 ? Array.from(historyList.keys()).sort((hist1, hist2) => hist2 - hist1).map(id => {
3131
return (
3232
<HistoryItem key={id}
3333
history={{

AI/GenAI-ChatBot-application-sample/src/app/home.tsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1+
'use client';
2+
13
import styles from './global.module.scss';
24
import LoginForm from "./components/loginForm/loginForm";
35
import ChatBot from '@/app/svgs/login/chatBot.png'
46
import Cloud from '@/app/svgs/login/cloud.png'
57
import Image from 'next/image';
68
import { _Classes } from '@/utils/cssHelper.util';
9+
import { useAppSelector } from '@/lib/hooks';
10+
import rootSelector from '@/lib/selectors/root.selector';
711

812
const Home = () => {
13+
const { accessToken, isSuccess } = useAppSelector(rootSelector.auth);
14+
915
return (
1016
<div className={styles.genAi}>
11-
<LoginForm />
12-
<div className={styles.welcomeContent}>
13-
<Image
14-
src={ChatBot}
15-
alt="chatBot"
16-
width={1124}
17-
height={794}
18-
priority
19-
className={styles.chatBotImage} />
20-
<span className={_Classes(styles.Semibold_43, styles.title)}>Welcome to Workload factory GenAI sample chatbot</span>
21-
<span className={`${styles.Regular_20} ${styles.subTitle}`}>By incorporating your enterprise data, GenAI Studio chatbot will understand industry-specific language, generate tailored responses, provide insights, and assist with documentation.</span>
22-
<Image
23-
src={Cloud}
24-
alt="clouds"
25-
width={982}
26-
height={284}
27-
priority
28-
className={styles.cloudsImage} />
29-
</div>
17+
{!accessToken && isSuccess && <>
18+
<LoginForm />
19+
<div className={styles.welcomeContent}>
20+
<Image
21+
src={ChatBot}
22+
alt="chatBot"
23+
width={1124}
24+
height={794}
25+
priority
26+
className={styles.chatBotImage} />
27+
<span className={_Classes(styles.Semibold_43, styles.title)}>Welcome to Workload factory GenAI sample chatbot</span>
28+
<span className={`${styles.Regular_20} ${styles.subTitle}`}>By incorporating your enterprise data, GenAI Studio chatbot will understand industry-specific language, generate tailored responses, provide insights, and assist with documentation.</span>
29+
<Image
30+
src={Cloud}
31+
alt="clouds"
32+
width={982}
33+
height={284}
34+
priority
35+
className={styles.cloudsImage} />
36+
</div>
37+
</>}
3038
</div>
3139
)
3240
}

AI/GenAI-ChatBot-application-sample/src/app/layout.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ export default function RootLayout({
2424
<html lang="en">
2525
<GenAiClerkProvider>
2626
<StoreProvider>
27-
<ErrorBoundary>
28-
<body className={`${styles.genAi} ${styles['font-variants']} light-theme`} style={{ margin: 0 }}>
29-
<DialogContextProvider>
27+
<body className={`${styles.genAi} ${styles['font-variants']} light-theme`} style={{ margin: 0 }}>
28+
<DialogContextProvider>
29+
<ErrorBoundary>
3030
<RedirectProvider>
3131
{children}
3232
</RedirectProvider>
33-
</DialogContextProvider>
34-
<NotificationGroup />
35-
</body>
36-
</ErrorBoundary>
33+
<NotificationGroup />
34+
</ErrorBoundary>
35+
</DialogContextProvider>
36+
</body>
3737
</StoreProvider>
3838
</GenAiClerkProvider>
3939
</html>

AI/GenAI-ChatBot-application-sample/src/app/providers/redirectProvider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const RedirectProvider = ({ children }: RedirectProviderProps) => {
2525
const authFromStorage = localStorage.getItem('genAi');
2626
const auth = authFromStorage ? JSON.parse(authFromStorage) as Auth : authInitialState;
2727

28-
if (!auth.isSuccess) {
28+
if (!auth.accessToken) {
2929
router.replace(ROUTES.BASE)
3030
} else {
3131
dispatch(setAuth(auth))
@@ -34,6 +34,8 @@ const RedirectProvider = ({ children }: RedirectProviderProps) => {
3434
router.push(`${ROUTES.BASE}${ROUTES.CHAT}`)
3535
}
3636
}
37+
38+
dispatch(setAuth({ ...auth, isSuccess: true }));
3739
}, [router, pathname, dispatch])
3840

3941
return children;

AI/GenAI-ChatBot-application-sample/src/lib/api/api.slice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const paginationApiMockResponseInitial: PaginationApiResponse<any> = {
2020
isSuccess: false,
2121
}
2222

23-
export const BASE_URL = 'staging.api.workloads.netapp.com';
23+
export const BASE_URL = 'api.workloads.netapp.com';
2424

2525
export const selfHandleErrors = (args: ApiRequest, api: any) => {
2626
if (args.isSelfHandleErrors) {

AI/GenAI-ChatBot-application-sample/src/lib/slices/chat.slice.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ const chatSlice = createSlice({
2828
state.messages = [];
2929
},
3030
resetChat(state) {
31-
return initialState
31+
return {
32+
...initialState,
33+
chatId: Date.now().toString()
34+
}
3235
}
3336
}
3437
})

0 commit comments

Comments
 (0)