Fix initial project loading for client

This commit is contained in:
Hazem Krimi
2023-05-28 16:31:53 +01:00
parent d4f75aa8c8
commit bd462d7fb7
5 changed files with 14 additions and 55 deletions
+5 -5
View File
@@ -6,7 +6,7 @@ import {
Box, Box,
ContextMenu, ContextMenu,
IconButton, IconButton,
MessagingSidebar, SupportSidebar,
SidebarItem, SidebarItem,
} from '..'; } from '..';
import { Add, Messaging } from '../../assets'; import { Add, Messaging } from '../../assets';
@@ -44,7 +44,7 @@ const Sidebar = () => {
const [templates, setTemplates] = useState<Array<TemplateOutput>>(); const [templates, setTemplates] = useState<Array<TemplateOutput>>();
const [features, setFeatures] = useState<Array<FeatureOutput>>(); const [features, setFeatures] = useState<Array<FeatureOutput>>();
const [categories, setCategories] = useState<Array<CategoryOutput>>(); const [categories, setCategories] = useState<Array<CategoryOutput>>();
const [messagingSidebarOpen, setMessagingSidebarOpen] = const [supportSideBarOpen, setSupportSideBarOpen] =
useState<boolean>(false); useState<boolean>(false);
const [getProjectsByClientId] = useLazyQuery< const [getProjectsByClientId] = useLazyQuery<
@@ -268,7 +268,7 @@ const Sidebar = () => {
icon={<Messaging />} icon={<Messaging />}
color={role} color={role}
onClick={() => onClick={() =>
setMessagingSidebarOpen(!messagingSidebarOpen) setSupportSideBarOpen(!supportSideBarOpen)
} }
/> />
</Box> </Box>
@@ -276,8 +276,8 @@ const Sidebar = () => {
</Box> </Box>
</> </>
)} )}
{messagingSidebarOpen && ( {supportSideBarOpen && (
<MessagingSidebar onClose={() => setMessagingSidebarOpen(false)} /> <SupportSidebar onClose={() => setSupportSideBarOpen(false)} />
)} )}
</Wrapper> </Wrapper>
); );
@@ -13,11 +13,11 @@ import { GET_PROJECT_THREADS } from '../../graphql/chat.api.support';
import { Add, Empty } from '../../assets'; import { Add, Empty } from '../../assets';
import { clientSupport } from '../..'; import { clientSupport } from '../..';
type MessagingSidebarProps = { type SupportSideBarProps = {
onClose: () => void; onClose: () => void;
}; };
const MessagingSidebar = ({ onClose }: MessagingSidebarProps) => { const SupportSidebar = ({ onClose }: SupportSideBarProps) => {
const role = useReactiveVar(roleVar); const role = useReactiveVar(roleVar);
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
@@ -110,4 +110,4 @@ const MessagingSidebar = ({ onClose }: MessagingSidebarProps) => {
); );
}; };
export default MessagingSidebar; export default SupportSidebar;
+2 -2
View File
@@ -28,7 +28,7 @@ import Specification from './Specification';
import Chip from './Chip'; import Chip from './Chip';
import CategoryCard from './CategoryCard'; import CategoryCard from './CategoryCard';
import TemplateCard from './TemplateCard'; import TemplateCard from './TemplateCard';
import MessagingSidebar from './MessagingSidebar'; import SupportSidebar from './SupportSidebar';
export { export {
Button, Button,
@@ -61,5 +61,5 @@ export {
Chip, Chip,
CategoryCard, CategoryCard,
TemplateCard, TemplateCard,
MessagingSidebar, SupportSidebar,
}; };
+4 -45
View File
@@ -55,23 +55,6 @@ import {
GET_PROJECT_BY_ID, GET_PROJECT_BY_ID,
} from '../../graphql/project.api'; } from '../../graphql/project.api';
type Transaction = {
amount: number;
created: boolean;
selectedOption: number;
_id: string;
};
type TransactionData = {
transactions: Array<Transaction>;
remaining_amount: number;
amount: number;
project_id: string;
status: boolean;
total_amount: number;
_id: string;
};
const Project = () => { const Project = () => {
const role = useReactiveVar(roleVar); const role = useReactiveVar(roleVar);
const currentUser = useReactiveVar(userVar); const currentUser = useReactiveVar(userVar);
@@ -83,7 +66,6 @@ const Project = () => {
const [designModal, setDesignModal] = useState<boolean>(false); const [designModal, setDesignModal] = useState<boolean>(false);
const [mvpModal, setMvpModal] = useState<boolean>(false); const [mvpModal, setMvpModal] = useState<boolean>(false);
const [fullBuildModal, setFullBuildModal] = useState<boolean>(false); const [fullBuildModal, setFullBuildModal] = useState<boolean>(false);
const [transactionsData, setTransactionsData] = useState<TransactionData>();
const [ const [
getProjectsByClientId, getProjectsByClientId,
@@ -96,8 +78,10 @@ const Project = () => {
id: currentUser?.id!, id: currentUser?.id!,
}, },
onCompleted({ getAllProjectsByClientId }) { onCompleted({ getAllProjectsByClientId }) {
if (getAllProjectsByClientId.length > 0) if (getAllProjectsByClientId.length > 0) {
setProject(getAllProjectsByClientId[0]); setProject(getAllProjectsByClientId[0]);
navigate(`/project/${getAllProjectsByClientId[0]?.id}`, { replace: true })
}
}, },
}); });
@@ -182,7 +166,7 @@ const Project = () => {
useEffect(() => { useEffect(() => {
if (id) { if (id) {
getProject({ variables: { id } }); getProject({ variables: { id } });
} else if (role === 'client') { } else if (role === 'client' && currentUser?.id) {
getProjectsByClientId({ getProjectsByClientId({
variables: { variables: {
id: currentUser?.id!, id: currentUser?.id!,
@@ -195,31 +179,6 @@ const Project = () => {
}; };
}, [id, role]); }, [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({ const handlePrint = useReactToPrint({
content: () => printRef.current, content: () => printRef.current,
}); });