From bd462d7fb7ccb0425acea4c4d3aa711e4f993b19 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Sun, 28 May 2023 16:31:53 +0100 Subject: [PATCH] Fix initial project loading for client --- src/components/Sidebar/index.tsx | 10 ++-- .../index.tsx | 6 +-- .../styles.ts | 0 src/components/index.tsx | 4 +- src/pages/Project/index.tsx | 49 ++----------------- 5 files changed, 14 insertions(+), 55 deletions(-) rename src/components/{MessagingSidebar => SupportSidebar}/index.tsx (95%) rename src/components/{MessagingSidebar => SupportSidebar}/styles.ts (100%) diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index eac3106..db07a7a 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -6,7 +6,7 @@ import { Box, ContextMenu, IconButton, - MessagingSidebar, + SupportSidebar, SidebarItem, } from '..'; import { Add, Messaging } from '../../assets'; @@ -44,7 +44,7 @@ const Sidebar = () => { const [templates, setTemplates] = useState>(); const [features, setFeatures] = useState>(); const [categories, setCategories] = useState>(); - const [messagingSidebarOpen, setMessagingSidebarOpen] = + const [supportSideBarOpen, setSupportSideBarOpen] = useState(false); const [getProjectsByClientId] = useLazyQuery< @@ -268,7 +268,7 @@ const Sidebar = () => { icon={} color={role} onClick={() => - setMessagingSidebarOpen(!messagingSidebarOpen) + setSupportSideBarOpen(!supportSideBarOpen) } /> @@ -276,8 +276,8 @@ const Sidebar = () => { )} - {messagingSidebarOpen && ( - setMessagingSidebarOpen(false)} /> + {supportSideBarOpen && ( + setSupportSideBarOpen(false)} /> )} ); diff --git a/src/components/MessagingSidebar/index.tsx b/src/components/SupportSidebar/index.tsx similarity index 95% rename from src/components/MessagingSidebar/index.tsx rename to src/components/SupportSidebar/index.tsx index 961ab19..81abd7a 100644 --- a/src/components/MessagingSidebar/index.tsx +++ b/src/components/SupportSidebar/index.tsx @@ -13,11 +13,11 @@ import { GET_PROJECT_THREADS } from '../../graphql/chat.api.support'; import { Add, Empty } from '../../assets'; import { clientSupport } from '../..'; -type MessagingSidebarProps = { +type SupportSideBarProps = { onClose: () => void; }; -const MessagingSidebar = ({ onClose }: MessagingSidebarProps) => { +const SupportSidebar = ({ onClose }: SupportSideBarProps) => { const role = useReactiveVar(roleVar); const location = useLocation(); const navigate = useNavigate(); @@ -110,4 +110,4 @@ const MessagingSidebar = ({ onClose }: MessagingSidebarProps) => { ); }; -export default MessagingSidebar; +export default SupportSidebar; diff --git a/src/components/MessagingSidebar/styles.ts b/src/components/SupportSidebar/styles.ts similarity index 100% rename from src/components/MessagingSidebar/styles.ts rename to src/components/SupportSidebar/styles.ts diff --git a/src/components/index.tsx b/src/components/index.tsx index bb8929c..ed61ee0 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -28,7 +28,7 @@ import Specification from './Specification'; import Chip from './Chip'; import CategoryCard from './CategoryCard'; import TemplateCard from './TemplateCard'; -import MessagingSidebar from './MessagingSidebar'; +import SupportSidebar from './SupportSidebar'; export { Button, @@ -61,5 +61,5 @@ export { Chip, CategoryCard, TemplateCard, - MessagingSidebar, + SupportSidebar, }; diff --git a/src/pages/Project/index.tsx b/src/pages/Project/index.tsx index c936c0c..375981b 100644 --- a/src/pages/Project/index.tsx +++ b/src/pages/Project/index.tsx @@ -55,23 +55,6 @@ import { GET_PROJECT_BY_ID, } from '../../graphql/project.api'; -type Transaction = { - amount: number; - created: boolean; - selectedOption: number; - _id: string; -}; - -type TransactionData = { - transactions: Array; - remaining_amount: number; - amount: number; - project_id: string; - status: boolean; - total_amount: number; - _id: string; -}; - const Project = () => { const role = useReactiveVar(roleVar); const currentUser = useReactiveVar(userVar); @@ -83,7 +66,6 @@ const Project = () => { const [designModal, setDesignModal] = useState(false); const [mvpModal, setMvpModal] = useState(false); const [fullBuildModal, setFullBuildModal] = useState(false); - const [transactionsData, setTransactionsData] = useState(); const [ getProjectsByClientId, @@ -96,8 +78,10 @@ const Project = () => { id: currentUser?.id!, }, onCompleted({ getAllProjectsByClientId }) { - if (getAllProjectsByClientId.length > 0) + if (getAllProjectsByClientId.length > 0) { setProject(getAllProjectsByClientId[0]); + navigate(`/project/${getAllProjectsByClientId[0]?.id}`, { replace: true }) + } }, }); @@ -182,7 +166,7 @@ const Project = () => { useEffect(() => { if (id) { getProject({ variables: { id } }); - } else if (role === 'client') { + } else if (role === 'client' && currentUser?.id) { getProjectsByClientId({ variables: { id: currentUser?.id!, @@ -195,31 +179,6 @@ const Project = () => { }; }, [id, role]); - useEffect(() => { - (async () => { - if (project) { - try { - const transactionsResult = await ( - await fetch(`${import.meta.env.VITE_PAYMENT_API}/transactions`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ project_id: project.id }), - }) - ).json(); - if (transactionsResult) setTransactionsData(transactionsResult); - } catch (err) { - console.error(err); - } - } - })(); - - return () => { - setTransactionsData(undefined); - }; - }, [project]); - const handlePrint = useReactToPrint({ content: () => printRef.current, });