Skip to content

Commit

Permalink
Extract CTA to separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed May 3, 2024
1 parent bae6653 commit 8dbb4d7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 59 deletions.
61 changes: 61 additions & 0 deletions src/components/pages/AppHome/CTABox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Box, Flex, Text } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { ReactNode } from 'react';

Check failure on line 4 in src/components/pages/AppHome/CTABox.tsx

View workflow job for this annotation

GitHub Actions / lint

`react` import should occur before import of `react-i18next`

export default function CTABox({
Icon,
titleKey,
descKey,
titleColor = 'white-0',
descColor = 'neutral-7',
bg = 'neutral-3',
to,
target,
pr,
iconContainerJustify,
}: {
Icon: ReactNode;
titleKey: string;
descKey: string;
titleColor?: string;
descColor?: string;
bg?: string;
to: string;
target?: string;
pr?: string | number;
iconContainerJustify?: string;
}) {
const { t } = useTranslation('home');
return (
<Flex
gap="3rem"
px="1.5rem"
w={{ base: '100%', lg: 'calc(50% - 0.75rem)' }}
h="10rem"
bg={bg}
alignItems="center"
borderRadius={8}
as={Link}
pr={pr}
to={to}
target={target}
>
<Box width="50%">
<Text
textStyle="display-2xl"
color={titleColor}
>
{t(titleKey)}
</Text>
<Text color={descColor}>{t(descKey)}</Text>
</Box>
<Flex
width="50%"
justifyContent={iconContainerJustify}
>
{Icon}
</Flex>
</Flex>
);
}
23 changes: 10 additions & 13 deletions src/components/pages/AppHome/FeaturedDAOCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ export interface FeaturedDAO {
votingStrategy: string;
address: string;
}
interface FeaturedDAOCardProps {
item: FeaturedDAO;
}

interface FeaturedDAOCardProps extends FeaturedDAO {}

export default function FeaturedDAOCard({
item: {
iconSrc,
iconBg = 'lilac-0',
iconRounded = false,
titleKey,
network,
address,
networkName,
votingStrategy,
},
iconSrc,
iconBg = 'lilac-0',
iconRounded = false,
titleKey,
network,
address,
networkName,
votingStrategy,
}: FeaturedDAOCardProps) {
const { t } = useTranslation('home');
return (
Expand Down
64 changes: 18 additions & 46 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { VStack, Text, Flex, Box, Button } from '@chakra-ui/react';
import { VStack, Text, Flex, Button } from '@chakra-ui/react';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { mainnet, sepolia } from 'wagmi/chains';
import { AppFooter } from '../components/pages/AppHome/AppFooter';
import CTABox from '../components/pages/AppHome/CTABox';
import FeaturedDAOCard, { FeaturedDAO } from '../components/pages/AppHome/FeaturedDAOCard';
import { CreateDAOIllustration, DocsIllustration } from '../components/ui/proposal/Icons';
import { BASE_ROUTES } from '../constants/routes';
Expand Down Expand Up @@ -76,16 +76,6 @@ export default function HomePage() {

const { chain } = useNetworkConfig();
const featuredDaos = FEATURED_DAOS.get(chain.id);
const ctaBaseProps = {
gap: '3rem',
px: '1.5rem',
w: { base: '100%', lg: 'calc(50% - 0.75rem)' },
h: '10rem',
alignItems: 'center',
overflow: 'hidden',
borderRadius: 8,
as: Link,
};
return (
<Flex flexWrap="wrap">
<VStack
Expand All @@ -101,42 +91,24 @@ export default function HomePage() {
w="full"
flexWrap="wrap"
>
<Flex
{...ctaBaseProps}
bg="lilac-0"
<CTABox
titleKey="createCTA"
descKey="createDesc"
to={BASE_ROUTES.create}
>
<Box width="50%">
<Text
textStyle="display-2xl"
color="cosmic-nebula-0"
>
{t('createCTA')}
</Text>
<Text color="cosmic-nebula-0">{t('createDesc')}</Text>
</Box>
<Box width="50%">
<CreateDAOIllustration />
</Box>
</Flex>
<Flex
{...ctaBaseProps}
pr={0}
bg="neutral-3"
Icon={<CreateDAOIllustration />}
titleColor="cosmic-nebula-0"
descColor="cosmic-nebula-0"
bg="lilac-0"
/>
<CTABox
to={URL_DOCS}
target="_blank"
>
<Box width="50%">
<Text textStyle="display-2xl">{t('docsCTA')}</Text>
<Text color="neutral-7">{t('docsDesc')}</Text>
</Box>
<Flex
width="50%"
justifyContent="flex-end"
>
<DocsIllustration />
</Flex>
</Flex>
titleKey="docsCTA"
descKey="docsDesc"
Icon={<DocsIllustration />}
pr={0}
iconContainerJustify="flex-end"
/>
</Flex>
{featuredDaos && featuredDaos.length > 0 ? (
<VStack
Expand All @@ -154,7 +126,7 @@ export default function HomePage() {
{featuredDaos.slice(0, shownItemsCount).map(dao => (
<FeaturedDAOCard
key={dao.titleKey}
item={dao}
{...dao}
/>
))}
</Flex>
Expand Down

0 comments on commit 8dbb4d7

Please sign in to comment.