Skip to content

Commit

Permalink
call to action button
Browse files Browse the repository at this point in the history
  • Loading branch information
damarizz committed Nov 29, 2024
1 parent 6a1fef4 commit 3eec9a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
29 changes: 14 additions & 15 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { Switch, Route } from 'wouter';
import { routes } from '@/pages';
import { PopupProvider } from './pages/Home/components/PopUpContext';

const App = () => {
return (
<div style={{ height: '100vh' }}>
<Switch>
{
routes.map((route, i) => {
return (
<Route
key={i}
path={route.href}
component={route.component as any}
/>
)
})
}
</Switch>
</div>
<PopupProvider>
<div style={{ height: '100vh' }}>
<Switch>
{routes.map((route, i) => (
<Route
key={i}
path={route.href}
component={route.component as any}
/>
))}
</Switch>
</div>
</PopupProvider>
);
};

Expand Down
4 changes: 3 additions & 1 deletion app/src/pages/Home/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { useMetagalleryStore } from '@/providers/MetagalleryProvider';
import { useTranslation, Trans } from 'react-i18next';
import { Grab } from 'lucide-react';
import ThemeSwitcher from '@/components/DarkerMode/themeSwitcher';
import { usePopupContext } from './PopUpContext';

export const Header = () => {
const { isRegisterPopupOpen, closeRegisterPopup } = usePopupContext();
const { t } = useTranslation();
const [loginPopup, setLoginPopup] = useState(false);
const [registerPopup, setRegisterPopup] = useState(false);
Expand Down Expand Up @@ -159,7 +161,7 @@ export const Header = () => {
{t('call_to_action')}
</Button>

<Popup trigger={registerPopup} setTrigger={resetRegisterFlow}>
<Popup trigger={isRegisterPopupOpen} setTrigger={closeRegisterPopup}>
{registerStep === 1 ? (
<>
<h3 className={popupStyles.title}>Registro de usuario</h3>
Expand Down
30 changes: 30 additions & 0 deletions app/src/pages/Home/components/PopUpContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createContext, useContext, useState, ReactNode } from 'react';

interface PopupContextProps {
isRegisterPopupOpen: boolean;
openRegisterPopup: () => void;
closeRegisterPopup: () => void;
}

const PopupContext = createContext<PopupContextProps | undefined>(undefined);

export const PopupProvider = ({ children }: { children: ReactNode }) => {
const [isRegisterPopupOpen, setIsRegisterPopupOpen] = useState(false);

const openRegisterPopup = () => setIsRegisterPopupOpen(true);
const closeRegisterPopup = () => setIsRegisterPopupOpen(false);

return (
<PopupContext.Provider value={{ isRegisterPopupOpen, openRegisterPopup, closeRegisterPopup }}>
{children}
</PopupContext.Provider>
);
};

export const usePopupContext = () => {
const context = useContext(PopupContext);
if (!context) {
throw new Error('usePopupContext must be used within a PopupProvider');
}
return context;
};
5 changes: 4 additions & 1 deletion app/src/pages/Home/components/PricingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Button from './Button';
import { usePopupContext } from './PopUpContext';
import styles from './PricingCard.module.css';
import { useTranslation, Trans } from 'react-i18next';

Expand All @@ -9,7 +10,9 @@ interface PricingCardProps {
}

const PricingCard = ({ title, price, features }: PricingCardProps) => {
const { openRegisterPopup } = usePopupContext();
const { t } = useTranslation();

return (
<div className={styles.card}>
<h3 className={styles.title}>{title}</h3>
Expand All @@ -19,7 +22,7 @@ const PricingCard = ({ title, price, features }: PricingCardProps) => {
<li key={index} className={styles.feature}>{feature}</li>
))}
</ul>
<Button variant="primary" className={styles.button}>
<Button variant="primary" className={styles.button} onClick={openRegisterPopup}>
{t('call_to_action')}
</Button>
</div>
Expand Down

0 comments on commit 3eec9a7

Please sign in to comment.