From 9a5119ccf3e15faa07a9ee0fab87d1cd8800a176 Mon Sep 17 00:00:00 2001 From: eagle Date: Tue, 11 Jun 2024 21:09:05 +0530 Subject: [PATCH] feat: add to cart functionality in project page --- .../src/features/projects/ViewProject.tsx | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/packages/grant-explorer/src/features/projects/ViewProject.tsx b/packages/grant-explorer/src/features/projects/ViewProject.tsx index 79aaf8b88..c44c95d64 100644 --- a/packages/grant-explorer/src/features/projects/ViewProject.tsx +++ b/packages/grant-explorer/src/features/projects/ViewProject.tsx @@ -21,6 +21,7 @@ import { ReactComponent as GithubIcon } from "../../assets/github-logo.svg"; import { ReactComponent as TwitterIcon } from "../../assets/twitter-logo.svg"; import { ReactComponent as GlobeIcon } from "../../assets/icons/globe-icon.svg"; import { ReactComponent as CartCircleIcon } from "../../assets/icons/cart-circle.svg"; +import { ReactComponent as CheckedCircleIcon } from "../../assets/icons/checked-circle.svg"; import { ProjectBanner } from "../common/ProjectBanner"; import Breadcrumb, { BreadcrumbItem } from "../common/Breadcrumb"; import { Box, Skeleton, SkeletonText, Tab, Tabs } from "@chakra-ui/react"; @@ -33,6 +34,7 @@ import { DefaultLayout } from "../common/DefaultLayout"; import { useProject, useProjectApplications } from "./hooks/useProject"; import NotFoundPage from "../common/NotFoundPage"; import { useCartStorage } from "../../store"; +import { CartProject } from "../api/types"; const CalendarIcon = (props: React.SVGProps) => { return ( @@ -97,7 +99,7 @@ export default function ViewProject() { }, { name: "Projects", - path: `/projects/`, + path: `/`, }, { name: project?.metadata.title, @@ -386,24 +388,29 @@ function ProjectLogo({ logoImg }: { logoImg?: string }) { function Sidebar(props: { projectApplications?: ProjectApplicationWithRoundAndProgram[]; }) { - const activeRoundApplications = props.projectApplications?.filter( + const activeQFRoundApplications = props.projectApplications?.filter( (projectApplication) => - new Date(projectApplication.round.donationsEndTime) > new Date() + new Date(projectApplication.round.donationsEndTime) > new Date() && + projectApplication.round.strategyName === + "allov2.DonationVotingMerkleDistributionDirectTransferStrategy" ); - // const { add } = useCartStorage(); + const { projects, add, remove } = useCartStorage(); return (
- {activeRoundApplications && activeRoundApplications?.length > 0 && ( + {activeQFRoundApplications && activeQFRoundApplications?.length > 0 && (

Active rounds

)}
- {activeRoundApplications?.map((projectApplication) => ( + {activeQFRoundApplications?.map((projectApplication) => ( ))}
@@ -531,6 +538,9 @@ export function RoundListItem({ export function ActiveRoundComponent(props: { projectApplication: ProjectApplicationWithRoundAndProgram; + addToCart: (project: CartProject) => void; + removeFromCart: (project: CartProject) => void; + projectsInCart: CartProject[]; }) { const roundName = props.projectApplication.round.roundMetadata.name; const roundStartDate = new Date( @@ -547,8 +557,24 @@ export function ActiveRoundComponent(props: { month: "short", day: "numeric", }); + const cartProject: CartProject = { + grantApplicationId: props.projectApplication.id, + projectRegistryId: props.projectApplication.projectId, + anchorAddress: props.projectApplication.anchorAddress, + recipient: props.projectApplication.metadata.application.recipient, + projectMetadata: props.projectApplication.metadata.application.project, + grantApplicationFormAnswers: [], + status: props.projectApplication.status, + applicationIndex: 0, + roundId: props.projectApplication.roundId, + chainId: props.projectApplication.chainId, + amount: "0", + }; const roundLink = `https://explorer.gitcoin.co/#/round/${props.projectApplication.chainId}/${props.projectApplication.roundId}`; const roundChain = getChainById(props.projectApplication.chainId); + const isProjectInCart = props.projectsInCart.some( + (project) => project.projectRegistryId === cartProject.projectRegistryId + ); return (
@@ -570,16 +596,26 @@ export function ActiveRoundComponent(props: {
View round - - - + {isProjectInCart ? ( +
props.removeFromCart(cartProject)} + className="flex text-black-500 w-1/4 justify-center cursor-pointer" + > + +
+ ) : ( +
props.addToCart(cartProject)} + className="flex text-black-500 w-1/4 justify-center cursor-pointer" + > + +
+ )}
);