Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed links to external websites in menu items #426

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/PageLayout/MenuMain/MenuMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ export const MenuMain: FC = () => {
const lg = useMediaQuery<Theme>((theme) => theme.breakpoints.up('lg'))
const iconSize = lg ? 34 : 24

const constructUrl = (url: string) => {
// `url` z databazy z menu item
// je vo formate `/vysledky/` alebo `/akcie/matboj/`
// kedy sa odkazuje na podstranku v ramci daneho seminara
// alebo https://domain.com alebo www.domain.com
// v pripade externeho linku kedy presmerujeme priamo na dany link.
if (url.startsWith('http') || url.startsWith('www')) {
return url
}

if (!url.startsWith('/')) {
url = `/${url}`
}

return `/${seminar}${url}`
}

return (
<>
{!isVisible && (
Expand Down Expand Up @@ -90,8 +107,7 @@ export const MenuMain: FC = () => {
)}
<Stack sx={{mt: {xs: 10, md: '164px', lg: '185px', xl: '221px'}}}>
{menuItems.map(({id, caption, url}) => (
// `url` je vo formate `/vysledky/` alebo `/akcie/matboj/`
<MenuMainItem key={id} caption={caption} url={`/${seminar}${url}`} />
<MenuMainItem key={id} caption={caption} url={constructUrl(url)} />
))}
</Stack>
{hasPermissions && (
Expand Down
Loading