Skip to content

Commit

Permalink
Merge pull request #2138 from graphcommerce-org/fix/GCOM-1164
Browse files Browse the repository at this point in the history
Wrap the logo in a div on the homepage to prevent redirection. (GCOM-1164)
  • Loading branch information
paales authored Jan 15, 2024
2 parents 4b299dd + 6edcf27 commit e9324c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-bees-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/next-ui': patch
---

Wrap the logo in a div on the homepage to prevent redirection.
40 changes: 20 additions & 20 deletions packages/next-ui/LayoutParts/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SxProps,
Theme,
unstable_composeClasses as composeClasses,
Box,
} from '@mui/material'
import { useRouter } from 'next/router'
import { forwardRef } from 'react'
Expand All @@ -22,25 +23,21 @@ const getLogoUtilityClass = (slot: string) => generateUtilityClass(name, slot)
const useUtilityClasses = ({ classes }: LogoClassProps) =>
composeClasses({ logo: ['logo'], parent: ['parent'] }, getLogoUtilityClass, classes)

/** Creating styled components */
const LogoContainer = styled(NextLink, {
name,
slot: 'parent',
overridesResolver: (_props, styles) => styles.parent,
})(({ theme }) => ({
const commonLogoStyles: SxProps<Theme> = {
height: '100%',
width: 'max-content',
display: 'flex',
alignItems: 'center',
margin: '0 auto',
justifyContent: 'center',
pointerEvents: 'all',
[theme.breakpoints.up('md')]: {
display: 'flex',
margin: 'unset',
justifyContent: 'left',
},
}))
}

const LogoContainer = styled(NextLink, {
name,
slot: 'parent',
overridesResolver: (_props, styles) => styles.parent,
})()

export type LogoProps = {
href?: `/${string}`
Expand All @@ -51,7 +48,6 @@ export type LogoProps = {
export const Logo = forwardRef<HTMLAnchorElement, LogoProps>((props, ref) => {
const { href = '/', image, sx } = props
const router = useRouter()

const classes = useUtilityClasses(props)

const img = (
Expand All @@ -63,13 +59,17 @@ export const Logo = forwardRef<HTMLAnchorElement, LogoProps>((props, ref) => {
/>
)

return router.asPath.split('?')[0] === '/' ? (
<LogoContainer ref={ref} sx={sx} className={classes.parent}>
{img}
</LogoContainer>
) : (
<LogoContainer href={href} ref={ref} sx={sx} className={classes.parent}>
const shouldRedirect = router.asPath.split('?')[0] !== href

return (
<Box
component={shouldRedirect ? LogoContainer : 'div'}
href={shouldRedirect ? href : undefined}
ref={ref}
sx={[...(Array.isArray(sx) ? sx : [sx]), commonLogoStyles]}
className={classes.parent}
>
{img}
</LogoContainer>
</Box>
)
})

1 comment on commit e9324c1

@vercel
Copy link

@vercel vercel bot commented on e9324c1 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

graphcommerce-hygraph-dynamic-rows-ui – ./packages/hygraph-dynamic-rows-ui

graphcommerce-hygraph-dynamic-rows-ui-git-canary-graphcommerce.vercel.app
graphcommerce-hygraph-dynamic-rows-ui.vercel.app
graphcommerce-hygraph-dynamic-rows-ui-graphcommerce.vercel.app

Please sign in to comment.