110 lines
3.2 KiB
TypeScript
Raw Normal View History

2024-07-29 15:27:20 +02:00
import { Button, IconButton, Modal as ModalMui } from '@mui/material'
import {
Link,
matchPath,
Outlet,
useLocation,
useNavigate
} from 'react-router-dom'
import styles from './style.module.scss'
import { appPublicRoutes } from '../../routes'
2024-07-31 14:37:10 +02:00
import { faClose } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import nostrImage from '../../assets/images/nostr.gif'
function useRouteMatch(patterns: readonly string[]) {
const { pathname } = useLocation()
for (let i = 0; i < patterns.length; i += 1) {
const pattern = patterns[i]
const possibleMatch = matchPath(pattern, pathname)
if (possibleMatch !== null) {
return possibleMatch
}
}
return null
}
export const Modal = () => {
const navigate = useNavigate()
const tabs = [
{ to: appPublicRoutes.login, title: 'Login', label: 'Login' },
{ to: appPublicRoutes.register, title: 'Register', label: 'Register' },
2024-07-29 15:27:20 +02:00
{
to: appPublicRoutes.nostr,
title: 'Login',
sx: { padding: '10px' },
label: <img src={nostrImage} width="25" alt="nostr logo" height="25" />
2024-07-29 15:27:20 +02:00
}
]
const routeMatch = useRouteMatch(tabs.map((t) => t.to))
const activeTab = routeMatch?.pattern?.path
const handleClose = () => {
navigate(appPublicRoutes.landingPage)
}
return (
2024-07-29 15:27:20 +02:00
<ModalMui open={true} onClose={handleClose} aria-labelledby="modal-title">
<div className={styles.modal}>
<header className={styles.header}>
<h2 className={styles.title} id="modal-title">
{tabs.find((t) => activeTab === t.to)?.title}
</h2>
<IconButton
onClick={handleClose}
sx={{
fontSize: '18px',
color: 'rgba(0, 0, 0, 0.5)',
padding: '8px 15px',
borderRadius: '4px',
':hover': {
background: 'var(--primary-light)',
color: 'white'
}
2024-07-29 15:27:20 +02:00
}}
>
2024-07-31 14:37:10 +02:00
<FontAwesomeIcon icon={faClose} />
2024-07-29 15:27:20 +02:00
</IconButton>
</header>
2024-07-29 15:27:20 +02:00
<main className={styles.body}>
<ul>
{tabs.map((t) => {
return (
2024-07-29 15:28:19 +02:00
<li key={t.to}>
2024-07-29 15:27:20 +02:00
<Button
component={Link}
to={t.to}
sx={{
width: '100%',
height: '100%',
...(t?.sx ? t.sx : {})
}}
variant={
activeTab === t.to || t.to === appPublicRoutes.nostr
? 'contained'
: 'text'
}
>
{t.label}
</Button>
</li>
)
})}
</ul>
{activeTab === appPublicRoutes.login ||
activeTab === appPublicRoutes.register ? (
<div className={styles.comingSoon}>Coming soon!</div>
) : null}
2024-07-29 17:12:47 +02:00
<div className={styles.tabContent}>
<Outlet />
</div>
2024-07-29 15:27:20 +02:00
</main>
2024-07-29 15:27:20 +02:00
<footer className={styles.footer}>Welcome to SIGit!</footer>
</div>
</ModalMui>
)
}