Skip to content

Commit

Permalink
306 sign in and modal (new) (#351)
Browse files Browse the repository at this point in the history
* Modal working, test modal opens closes successfully

* Modal handleClickOutisde still not working, otherwise removed paths to login/signup page and now all pages show modal correctly

* finalized css of the modal, added handleClose function on URL change or when the X on the top right is used

* resolved comments, removed google and facebook buttons, changed colors to theme.palette

* fixed merge conflicts and typescritp conflicts
  • Loading branch information
EtoKruto authored Jul 21, 2023
1 parent ac55a93 commit cc54d36
Show file tree
Hide file tree
Showing 12 changed files with 482 additions and 64 deletions.
44 changes: 25 additions & 19 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { BrowserRouter } from 'react-router-dom';
import { Grid, ThemeProvider, StyledEngineProvider } from '@mui/material';

import theme from './theme';
import Footer from './components/Footer';
import Header from './components/Header';
import Main from './views/Main';
import { UserProvider } from './providers';
import Footer from './components/Footer';
import Modal from './components/Modal';

import { UserProvider } from './providers';
import { ModalProvider } from './providers/ModalProvider';
import { QueryClient, QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';

Expand All @@ -28,24 +30,28 @@ function App(): JSX.Element {
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools />
<UserProvider>
<BrowserRouter
getUserConfirmation={() => {
// intentionally left empty callback to block the default browser prompt.
}}
>
<Grid
className="App"
display="flex"
flexDirection="column"
height="100vh"
width="100vw"
justifyContent="space-between"
<ModalProvider>
<BrowserRouter
getUserConfirmation={() => {
// intentionally left empty callback to block the default browser prompt.
}}
>
<Header />
<Main />
<Footer />
</Grid>
</BrowserRouter>
<Grid
className="App"
display="flex"
flexDirection="column"
height="100vh"
width="100vw"
justifyContent="space-between"
>
{/* move modal to below footer after troubleshooting */}
<Modal />
<Header />
<Main />
<Footer />
</Grid>
</BrowserRouter>
</ModalProvider>
</UserProvider>
</QueryClientProvider>
</ThemeProvider>
Expand Down
74 changes: 42 additions & 32 deletions client/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import React, { useContext } from 'react';
import { NavLink, useHistory } from 'react-router-dom';

import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Button from '@mui/material/Button';
import { makeStyles } from 'tss-react/mui';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import Divider from '@mui/material/Divider';

import IconButton from '@mui/material/IconButton';
import AppsIcon from '@mui/icons-material/Apps';
import ListItemAvatar from '@mui/material/ListItemAvatar';
Expand All @@ -29,6 +29,7 @@ import Logo from '../assets/GivingfulLogo.png';
import routes from '../routes/routes';
import { APP_API_BASE_URL } from '../configs';
import { UserAvatar } from './Users/UserAvatar';
import { ModalContext } from './../providers/ModalProvider';

const useStyles = makeStyles()((theme: Theme) => ({
home: {
Expand Down Expand Up @@ -73,6 +74,27 @@ const useStyles = makeStyles()((theme: Theme) => ({
logo: {
height: '30px',
},
signUpButton: {
textTransform: 'capitalize',
backgroundColor: theme.palette.primary.main,
color: `${theme.palette.primary.contrastText}`,
borderRadius: '10px',
border: `1px solid ${theme.palette.primary.main}`,
marginLeft: '0px',
width: '100px',
'&:hover': {
color: `${theme.palette.text.primary}`,
},
},
signInButton: {
textTransform: 'capitalize',
backgroundColor: `${theme.palette.primary.contrastText}`,
color: `${theme.palette.text.primary}`,
borderRadius: '10px',
border: `1px solid ${theme.palette.black.light}`,
marginLeft: '10px',
width: '100px',
},
}));

function Header() {
Expand All @@ -91,6 +113,17 @@ function Header() {
const isAboutMenuOpen = Boolean(aboutAnchorEl);
const isExchangeMenuOpen = Boolean(exchangeAnchorEl);

const modalContext = useContext(ModalContext);
const { openModal } = modalContext;

const handleoOpenModal = (modalType: 'SignIn' | 'SignUp') => {
if (modalType === 'SignIn') {
openModal('SignIn');
} else if (modalType === 'SignUp') {
openModal('SignUp');
}
};

const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
switch (event?.currentTarget?.id) {
case 'navigation-button': {
Expand Down Expand Up @@ -149,6 +182,7 @@ function Header() {
sx={{
textTransform: 'capitalize',
color: '#323232',
marginRight: '10px',
}}
>
Exchange
Expand Down Expand Up @@ -442,36 +476,12 @@ function Header() {
</>
) : (
<>
<NavLink className={classes.navLink} to={routes.Signup.path}>
<Button
sx={{
textTransform: 'capitalize',
backgroundColor: '#EF6A60',
color: 'white',
borderRadius: '10px',
border: '1px solid #EF6A60',
marginRight: '10px',
width: '100px',
}}
>
Join Now
</Button>
</NavLink>
<NavLink className={classes.navLink} to={routes.Login.path}>
<Button
sx={{
textTransform: 'capitalize',
backgroundColor: 'white',
color: '#323232',
borderRadius: '10px',
border: '1px solid #323232',
marginLeft: '5px',
width: '100px',
}}
>
Sign In
</Button>
</NavLink>
<Button className={classes.signUpButton} onClick={() => handleoOpenModal('SignUp')}>
Join Now
</Button>
<Button className={classes.signInButton} onClick={() => handleoOpenModal('SignIn')}>
Sign In
</Button>
</>
)}
</div>
Expand Down
115 changes: 115 additions & 0 deletions client/src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React, { useContext, useEffect, useRef } from 'react';
import { ModalContext } from './../providers/ModalProvider';
import { makeStyles } from 'tss-react/mui';
import type { Theme } from '@mui/material/styles';
import SignIn from './Modals/SignInModal';
import SignUp from './Modals/SignUpModal';

const useStyles = makeStyles()((theme: Theme) => {
const xPadding = 6;
const yPadding = 6;

return {
outerShell: {
borderRadius: 20,
minWidth: 600,
minHeight: 600,
maxWidth: 732 - theme.spacing(xPadding),
maxHeight: 732 - theme.spacing(yPadding),
},
paper: {
marginTop: theme.spacing(yPadding),
marginBottom: theme.spacing(yPadding),
width: '80%',
},
content: {
padding: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
header: {
fontWeight: 'normal',
marginTop: 50,
display: 'flex',
justifyContent: 'center',
},
loginButton: {
borderRadius: 10,
fontSize: 17,
width: 180,
height: 50,
textTransform: 'none',
color: 'white',
backgroundColor: theme.palette.primary.main,
fontFamily: 'Poppins',
fontWeight: 'semi-bold',
border: 'none',
'&:hover': {
cursor: 'pointer',
},
},
buttonContainer: {
marginBottom: theme.spacing(1),
width: '65%',
display: 'flex',
justifyContent: 'center',
},
closeButton: {
position: 'absolute',
right: 40,
top: 28,
transition: 'background-color 0.3s',
'&:hover': {
backgroundColor: theme.palette.grey[700],
},
},
};
});

const Modal = () => {
const modalContext = useContext(ModalContext);
const modalRef = useRef<HTMLDivElement | null>(null);
const { classes } = useStyles();
const { modal, closeModal } = modalContext;

useEffect(() => {
if (!modalContext || !modalContext.modal || !closeModal) return;

const handleClickOutside = (event: any) => {
// console.log('event.target', event.target); //uncomment to event.target clicked html
// console.log('modalRef.current', modalRef.current); //uncomment to modalRef.current reference html aka the Modal itself

if (modalRef.current && !modalRef.current.contains(event.target)) {
closeModal();
}
};

// Bind the event listener
document.addEventListener('mousedown', handleClickOutside);

return () => {
// Unbind the event listener on clean up
document.removeEventListener('mousedown', handleClickOutside);
};
}, [modalContext, closeModal]);

if (!modalContext || !modalContext.modal) return null;

let SpecificModal;
if (modal && modal.type === 'SignIn') {
SpecificModal = SignIn;
} else if (modal && modal.type === 'SignUp') {
SpecificModal = SignUp;
} else {
return null;
}

return (
<div id="mango">
<SpecificModal ref={modalRef} closeModal={closeModal} className={classes} />
</div>
);
};

export default Modal;
Loading

0 comments on commit cc54d36

Please sign in to comment.