From b1f33d3d18767c1de3373bc75fe6cb5b80c90ea3 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 2 Jan 2024 23:57:28 +0700 Subject: [PATCH] feat: revamp new thread setting panel flow --- web/containers/Layout/Ribbon/index.tsx | 94 +++++++++++++++++++++++--- web/screens/Chat/Sidebar/index.tsx | 3 +- 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/web/containers/Layout/Ribbon/index.tsx b/web/containers/Layout/Ribbon/index.tsx index 2342ceaee..dc238b213 100644 --- a/web/containers/Layout/Ribbon/index.tsx +++ b/web/containers/Layout/Ribbon/index.tsx @@ -1,10 +1,18 @@ -import { useEffect } from 'react' +import { useEffect, useState } from 'react' import { Tooltip, TooltipContent, TooltipTrigger, TooltipArrow, + Modal, + ModalTitle, + ModalContent, + ModalHeader, + ModalFooter, + ModalDescription, + ModalClose, + Button, } from '@janhq/uikit' import { motion as m } from 'framer-motion' @@ -31,6 +39,8 @@ import { threadSettingFormUpdateAtom } from '@/helpers/atoms/Thread.atom' export default function RibbonNav() { const { mainViewState, setMainViewState } = useMainViewState() const threadSettingFormUpdate = useAtomValue(threadSettingFormUpdateAtom) + const [showModalUpdateThreadSetting, setshowModalUpdateThreadSetting] = + useState({ show: false, view: mainViewState }) const onMenuClick = (state: MainViewState) => { if (mainViewState === state) return @@ -100,10 +110,6 @@ export default function RibbonNav() { }, ] - // useEffect(() => { - // console.log(threadSettingFormUpdate) - // }, [threadSettingFormUpdate]) - return (
@@ -127,9 +133,19 @@ export default function RibbonNav() { isActive && 'z-10' )} onClick={() => { - if (threadSettingFormUpdate) { - console.log('hahah') + if ( + threadSettingFormUpdate && + mainViewState === MainViewState.Thread + ) { + setshowModalUpdateThreadSetting({ + show: true, + view: primary.state, + }) } else { + setshowModalUpdateThreadSetting({ + show: false, + view: mainViewState, + }) onMenuClick(primary.state) } }} @@ -194,7 +210,23 @@ export default function RibbonNav() { 'relative flex w-full flex-shrink-0 cursor-pointer items-center justify-center', isActive && 'z-10' )} - onClick={() => onMenuClick(secondary.state)} + onClick={() => { + if ( + threadSettingFormUpdate && + mainViewState === MainViewState.Thread + ) { + setshowModalUpdateThreadSetting({ + show: true, + view: secondary.state, + }) + } else { + setshowModalUpdateThreadSetting({ + show: false, + view: mainViewState, + }) + onMenuClick(secondary.state) + } + }} > {secondary.icon}
@@ -216,6 +248,52 @@ export default function RibbonNav() {
+ + + setshowModalUpdateThreadSetting({ + show: false, + view: mainViewState, + }) + } + > + + + +
Unsave changes
+
+ +

+ You have unsave changes. Are you sure you want to leave this + page? +

+
+
+ +
+ + + + +
+
+
+
) } diff --git a/web/screens/Chat/Sidebar/index.tsx b/web/screens/Chat/Sidebar/index.tsx index b6f330216..3fca796f1 100644 --- a/web/screens/Chat/Sidebar/index.tsx +++ b/web/screens/Chat/Sidebar/index.tsx @@ -221,8 +221,7 @@ const Sidebar: React.FC = () => { } else { setThreadSettingFormUpdate(false) } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [form.formState.dirtyFields]) + }, [form.formState, setThreadSettingFormUpdate]) return (