From a75632bbbdbdb2317042419bded9b1cc46f8dfcb Mon Sep 17 00:00:00 2001 From: J Caso Date: Mon, 29 Jul 2024 10:18:55 +0200 Subject: [PATCH] feat: using Layout for User Guide --- ui/summit-2024/src/__fixtures__/userGuide.ts | 5 + .../src/components/Layout/Layout.tsx | 29 +- .../src/pages/UserGuide/UserGuide.tsx | 488 ++++++------------ .../src/pages/UserGuide2/UserGuide2.tsx | 364 ------------- .../UserGuide2/components/UserGuideCard.tsx | 115 ----- .../components/UserGuideCard.type.ts | 13 - ui/summit-2024/src/routes/index.tsx | 5 +- 7 files changed, 182 insertions(+), 837 deletions(-) delete mode 100644 ui/summit-2024/src/pages/UserGuide2/UserGuide2.tsx delete mode 100644 ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.tsx delete mode 100644 ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.type.ts diff --git a/ui/summit-2024/src/__fixtures__/userGuide.ts b/ui/summit-2024/src/__fixtures__/userGuide.ts index 213b9fa3a..fb1e708a4 100644 --- a/ui/summit-2024/src/__fixtures__/userGuide.ts +++ b/ui/summit-2024/src/__fixtures__/userGuide.ts @@ -12,12 +12,14 @@ interface UserGuideSection { interface UserGuideMenuEntry { label: string; + title: string; sections: UserGuideSection[]; } const userGuideMenu: UserGuideMenuEntry[] = [ { label: "What You’ll Need", + title: "To Submit Votes, You’ll Need:", sections: [ { number: 1, @@ -39,6 +41,7 @@ const userGuideMenu: UserGuideMenuEntry[] = [ }, { label: "Creating an Account", + title: "Create and Verify Your Account:", sections: [ { number: 1, @@ -58,6 +61,7 @@ const userGuideMenu: UserGuideMenuEntry[] = [ }, { label: "How to Vote", + title: "How to Submit a Vote:", sections: [ { number: 1, @@ -99,4 +103,5 @@ const userGuideMenu: UserGuideMenuEntry[] = [ }, ]; +export type { UserGuideMenuEntry } export { userGuideMenu }; diff --git a/ui/summit-2024/src/components/Layout/Layout.tsx b/ui/summit-2024/src/components/Layout/Layout.tsx index d962ac2e9..5281f6360 100644 --- a/ui/summit-2024/src/components/Layout/Layout.tsx +++ b/ui/summit-2024/src/components/Layout/Layout.tsx @@ -10,12 +10,16 @@ type MenuItem = { type LayoutProps = { menuOptions: MenuItem[]; + title: string; + bottom?: ReactNode; mode?: "scroll" | "change"; defaultOption?: number; }; const Layout: React.FC = ({ menuOptions, + title, + bottom, mode = "scroll", defaultOption = 0, }) => { @@ -192,7 +196,27 @@ const Layout: React.FC = ({ )} - + + + {title} + {mode === "change" ? menuOptions.find((option) => option.label === selectedOption) ?.content @@ -208,6 +232,9 @@ const Layout: React.FC = ({ {option.content} ))} + { + bottom + } diff --git a/ui/summit-2024/src/pages/UserGuide/UserGuide.tsx b/ui/summit-2024/src/pages/UserGuide/UserGuide.tsx index 5d1b1388d..8b2d7eaa2 100644 --- a/ui/summit-2024/src/pages/UserGuide/UserGuide.tsx +++ b/ui/summit-2024/src/pages/UserGuide/UserGuide.tsx @@ -1,364 +1,170 @@ -import React, { useRef, useState } from "react"; -import { Box, Grid, Typography, List, ListItem } from "@mui/material"; -import theme from "../../common/styles/theme"; -import Ellipses from "../../assets/ellipse.svg"; -import { useIsPortrait } from "../../common/hooks/useIsPortrait"; +import Layout from "../../components/Layout/Layout"; +import { Typography, Grid } from "@mui/material"; import { UserGuideCard } from "./components/UserGuideCard"; import { userGuideMenu } from "../../__fixtures__/userGuide"; -import { CustomButton } from "../../components/common/CustomButton/CustomButton"; -import { ROUTES } from "../../routes"; -import { useNavigate } from "react-router-dom"; -import { PageBase } from "../BasePage"; - -const UserGuide: React.FC = () => { - const navigate = useNavigate(); - const userGuideMenuOptions = userGuideMenu; - const [selectedCategory, setSelectedCategory] = useState( - userGuideMenuOptions[0].label, - ); - - const isMobile = useIsPortrait(); - - const createAccountsRef = useRef(null); - const submitVotesRef = useRef(null); - const howVoteRef = useRef(null); +import theme from "../../common/styles/theme"; +import {PageBase} from "../BasePage"; +import {CustomButton} from "../../components/common/CustomButton/CustomButton"; +import {ROUTES} from "../../routes"; +import {useNavigate} from "react-router-dom"; - const handleNavigate = (pathname: string) => { - navigate(pathname); - }; +const UserGuide = () => { + const navigate = useNavigate(); - const handleClickMenuItem = (option: string) => { - setSelectedCategory(option); - if (option === userGuideMenu[0].label) { - submitVotesRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } else if (option === userGuideMenu[1].label) { - createAccountsRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } else if (option === userGuideMenu[2].label) { - howVoteRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } - }; + const handleNavigate = (pathname: string) => { + navigate(pathname); + }; - return ( - <> - - <> - - - - - {isMobile ? ( - <> - + - + + {userGuideMenu[0].sections.map((section) => { + return ( + + + + ); + })} + + + ) + }, + { + label: userGuideMenu[1].label, + content: ( + <> + - {userGuideMenuOptions.map((category, index) => ( - handleClickMenuItem(category.label)} - key={index} - sx={{ - display: "flex", - marginRight: "8px", - whiteSpace: "nowrap", - }} - > - - {category.label} - - - ))} - - - - ) : ( - <> - - {userGuideMenuOptions.map((option, index) => ( - handleClickMenuItem(option.label)} - key={index} - > - {option.label === selectedCategory ? ( - <> - - - {option.label} - - - - ) : ( - <> - - {option.label} - - - )} - - ))} - - - )} - - - - User Guide - - - To Submit Votes, You’ll Need: - - - {userGuideMenuOptions[0].sections.map((section) => { - return ( - - - - ); - })} - - - Create and Verify Your Account: - - - {userGuideMenuOptions[1].sections.map((section) => { - return ( - - - - ); - })} - + {userGuideMenu[1].title} + + + {userGuideMenu[1].sections.map((section) => { + return ( + + + + ); + })} + + + ) + }, + { + label: userGuideMenu[2].label, + content: ( + <> + + {userGuideMenu[2].title} + + + {userGuideMenu[2].sections.map((section) => { + return ( + + + + ); + })} + + + ) + } + ]; - + - How to Submit a Vote: - - - {userGuideMenuOptions[2].sections.map((section) => { - return ( - - - - ); - })} - + }} + > - - handleNavigate(ROUTES.CATEGORIES)} - colorVariant="primary" - sx={{ width: { - xs: "100%", - md: "auto", + xs: "100%", + md: "auto", }, - }} + }} + > + handleNavigate(ROUTES.CATEGORIES)} + colorVariant="primary" + sx={{ + width: { + xs: "100%", + md: "auto", + }, + }} > - Vote Now + Vote Now - - - - - - - ); + ) + return ( + <> + + + + + ); }; -export { UserGuide }; +export default UserGuide; diff --git a/ui/summit-2024/src/pages/UserGuide2/UserGuide2.tsx b/ui/summit-2024/src/pages/UserGuide2/UserGuide2.tsx deleted file mode 100644 index c917ddafc..000000000 --- a/ui/summit-2024/src/pages/UserGuide2/UserGuide2.tsx +++ /dev/null @@ -1,364 +0,0 @@ -import React, { useRef, useState } from "react"; -import { Box, Grid, Typography, List, ListItem } from "@mui/material"; -import theme from "../../common/styles/theme"; -import Ellipses from "../../assets/ellipse.svg"; -import { useIsPortrait } from "../../common/hooks/useIsPortrait"; -import { UserGuideCard } from "./components/UserGuideCard"; -import { userGuideMenu } from "../../__fixtures__/userGuide"; -import { CustomButton } from "../../components/common/CustomButton/CustomButton"; -import { ROUTES } from "../../routes"; -import { useNavigate } from "react-router-dom"; -import { PageBase } from "../BasePage"; - -const UserGuide2: React.FC = () => { - const navigate = useNavigate(); - const userGuideMenuOptions = userGuideMenu; - const [selectedCategory, setSelectedCategory] = useState( - userGuideMenuOptions[0].label, - ); - - const isMobile = useIsPortrait(); - - const createAccountsRef = useRef(null); - const submitVotesRef = useRef(null); - const howVoteRef = useRef(null); - - const handleNavigate = (pathname: string) => { - navigate(pathname); - }; - - const handleClickMenuItem = (option: string) => { - setSelectedCategory(option); - if (option === userGuideMenu[0].label) { - submitVotesRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } else if (option === userGuideMenu[1].label) { - createAccountsRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } else if (option === userGuideMenu[2].label) { - howVoteRef.current?.scrollIntoView({ - behavior: "smooth", - block: "start", - }); - } - }; - - return ( - <> - - <> - - - - - {isMobile ? ( - <> - - - {userGuideMenuOptions.map((category, index) => ( - handleClickMenuItem(category.label)} - key={index} - sx={{ - display: "flex", - marginRight: "8px", - whiteSpace: "nowrap", - }} - > - - {category.label} - - - ))} - - - - ) : ( - <> - - {userGuideMenuOptions.map((option, index) => ( - handleClickMenuItem(option.label)} - key={index} - > - {option.label === selectedCategory ? ( - <> - - - {option.label} - - - - ) : ( - <> - - {option.label} - - - )} - - ))} - - - )} - - - - User Guide - - - To Submit Votes, You’ll Need: - - - {userGuideMenuOptions[0].sections.map((section) => { - return ( - - - - ); - })} - - - Create and Verify Your Account: - - - {userGuideMenuOptions[1].sections.map((section) => { - return ( - - - - ); - })} - - - - How to Submit a Vote: - - - {userGuideMenuOptions[2].sections.map((section) => { - return ( - - - - ); - })} - - - - handleNavigate(ROUTES.CATEGORIES)} - colorVariant="primary" - sx={{ - width: { - xs: "100%", - md: "auto", - }, - }} - > - Vote Now - - - - - - - - - - - ); -}; - -export { UserGuide2 }; diff --git a/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.tsx b/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.tsx deleted file mode 100644 index d7db891dc..000000000 --- a/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { Paper, Typography, Box, Link } from "@mui/material"; -import theme from "../../../common/styles/theme"; -import guideBg from "../../../assets/bg/guideCard.svg"; -import { CustomCardProps } from "./UserGuideCard.type"; - -const UserGuideCard = ({ - number, - title, - description, - link, -}: CustomCardProps) => { - return ( - - - - - {number} - - - - {title} - - - {description} - - {link && ( - - - {link.label} - - - )} - - - ); -}; - -export { UserGuideCard }; diff --git a/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.type.ts b/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.type.ts deleted file mode 100644 index 2f8b4a9a3..000000000 --- a/ui/summit-2024/src/pages/UserGuide2/components/UserGuideCard.type.ts +++ /dev/null @@ -1,13 +0,0 @@ -interface CustomCardProps { - number: number; - title: string; - description: string; - link?: - | { - label: string; - url: string; - } - | undefined; -} - -export { CustomCardProps }; diff --git a/ui/summit-2024/src/routes/index.tsx b/ui/summit-2024/src/routes/index.tsx index 271ba9341..1ea1c0a73 100644 --- a/ui/summit-2024/src/routes/index.tsx +++ b/ui/summit-2024/src/routes/index.tsx @@ -2,13 +2,12 @@ import { useEffect } from "react"; import { Route, Routes, useLocation } from "react-router-dom"; import { Home } from "../pages/Home"; import { Categories } from "../pages/Categories"; -import { UserGuide } from "../pages/UserGuide/UserGuide"; import { Leaderboard } from "../pages/Leaderboard/Leaderboard"; import { ReceiptHistory } from "../pages/ReceiptHistory/ReceiptHistory"; import { NotFound } from "../pages/NotFound/NotFound"; import { TermsAndConditions } from "../pages/TermsAndPolicy/TermsAndConditions"; import TermsAndConditions2 from "../pages/TermsAndPolicy2/TermsAndConditions2"; -import {UserGuide2} from "../pages/UserGuide2/UserGuide2"; +import UserGuide from "../pages/UserGuide/UserGuide"; export const PAGE_PATH = "/"; @@ -38,7 +37,7 @@ const PageRouter = () => { } /> } /> } /> - } /> + } /> }