Skip to content

Commit fcf8b05

Browse files
authored
Merge pull request #1368 from OpenBeta/test-area
Add Test Area Banner
2 parents 0ca24b2 + 072132e commit fcf8b05

File tree

3 files changed

+75
-39
lines changed

3 files changed

+75
-39
lines changed
Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
1+
'use client'
2+
import { useSession } from 'next-auth/react'
3+
import Link from 'next/link'
14
import { AppAlert } from '@/components/broadcast/AppAlert'
25
import { SignupButton } from './DesktopHeader'
36

7+
const STORAGE_KEY_JOIN_US = 'suppress-join-us-banner'
8+
const STORAGE_KEY_TEST_AREA = 'suppress-test-area-banner'
9+
10+
const TEST_AREA_ID = process.env.NEXT_PUBLIC_TEST_AREA_ID ?? '18c5dd5c-8186-50b6-8a60-ae2948c548d1'
11+
const TEST_AREA_URL = `/area/${TEST_AREA_ID}/test-area`
12+
413
export const LandingHero: React.FC = () => {
5-
return (
6-
<section className='mt-4'>
14+
const { status } = useSession()
15+
16+
if (status === 'authenticated') {
17+
return (
718
<AppAlert
19+
cookieStorageKey={STORAGE_KEY_TEST_AREA}
820
message={
921
<>
10-
<h1 className='text-xl tracking-tighter font-bold'>Share your climbing route knowledge!</h1>
22+
<h1 className='text-xl tracking-tighter font-bold'>Try out adding a route!</h1>
1123
<div className='font-medium text-neutral/80'>
12-
<p>Join us to help improve this comprehensive <br /> climbing resource for the community.</p>
24+
<p>
25+
You're in the test area — perfect for exploring how everything works.
26+
<br />Add a route and see it in action!
27+
</p>
1328
</div>
14-
<SignupButton />
29+
<Link href={TEST_AREA_URL} className='btn btn-accent border-b-2 border-b-neutral'>
30+
Test Area
31+
</Link>
1532
</>
1633
}
1734
/>
18-
</section>
35+
)
36+
}
37+
38+
return (
39+
<AppAlert
40+
cookieStorageKey={STORAGE_KEY_JOIN_US}
41+
message={
42+
<>
43+
<h1 className='text-xl tracking-tighter font-bold'>Share your climbing route knowledge!</h1>
44+
<div className='font-medium text-neutral/80'>
45+
<p>Join us to help improve this comprehensive <br /> climbing resource for the community.</p>
46+
</div>
47+
<SignupButton />
48+
</>
49+
}
50+
/>
1951
)
2052
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
'use client'
22
import Cookies from 'js-cookie'
33
import { useState, useEffect } from 'react'
4-
import { useSession } from 'next-auth/react'
54
import { SuppressButton } from './SuppressButton'
65

7-
const STORAGE_KEY = 'suppress-main-banner'
8-
96
export interface AppAlertProps {
107
message: JSX.Element
8+
cookieStorageKey: string
119
}
1210

1311
/**
1412
* Main alert to be displayed under the nav bar. Users can snooze the alert.
1513
* @param message alert content
1614
*/
17-
export const AppAlert: React.FC<AppAlertProps> = ({ message }) => {
18-
const { status } = useSession()
15+
export const AppAlert: React.FC<AppAlertProps> = ({
16+
message,
17+
cookieStorageKey
18+
}) => {
1919
const [showAlert, setShowAlert] = useState(false)
20+
2021
useEffect(() => {
21-
const suppressed = Cookies.get(STORAGE_KEY)
22+
const suppressed = Cookies.get(cookieStorageKey)
23+
2224
setShowAlert(suppressed == null)
23-
}, [])
25+
}, [cookieStorageKey])
2426

25-
// Hide alert if user is logged in
26-
return showAlert && status !== 'authenticated'
27-
? (
27+
return (
28+
showAlert && (
2829
<div className='z-40 w-fit alert alert-info flex flex-wrap justify-center xl:p-4 gap-4'>
29-
<div className='flex flex-col gap-2 items-start'>
30-
{message}
31-
</div>
30+
<div className='flex flex-col gap-2 items-start'>{message}</div>
3231
<div className='inline-flex w-[210px] grow-1'>
3332
<SuppressButton
3433
onClick={() => {
3534
setShowAlert(false)
36-
Cookies.set(STORAGE_KEY, '1', { strict: true, expires: 30 })
35+
Cookies.set(cookieStorageKey, '1', { strict: true, expires: 30 })
3736
}}
3837
/>
3938
</div>
4039
</div>
41-
)
42-
: null
40+
)
41+
)
4342
}

src/components/broadcast/__tests__/AppAlert.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,52 @@ jest.mock('next-auth/react', () => ({
2323

2424
let AppAlertComponent: React.FC<AppAlertProps>
2525

26-
describe('Banner suppression', () => {
26+
describe('AppAlert', () => {
2727
beforeAll(async () => {
2828
// why async import? see https://github.com/facebook/jest/issues/10025#issuecomment-716789840
2929
const module = await import('../AppAlert')
3030
AppAlertComponent = module.AppAlert
3131
})
3232

33-
it('doesn\'t show alert when cookie exists', async () => {
34-
// cookie exists
35-
cookieGetter.mockReturnValueOnce('foo')
33+
beforeEach(() => {
34+
cookieGetter.mockClear()
35+
cookieSetter.mockClear()
36+
})
37+
38+
it('renders alert with message', () => {
3639
render(
3740
<AppAlertComponent
41+
cookieStorageKey='test'
3842
message={
3943
<div>
4044
important message
4145
</div>
42-
}
43-
/>)
46+
}
47+
/>
48+
)
4449

45-
expect(screen.queryAllByRole('button').length).toEqual(0)
46-
cookieGetter.mockClear()
50+
expect(screen.getByText('important message')).toBeInTheDocument()
51+
expect(screen.getByRole('button', { name: /Don't show this again/i })).toBeInTheDocument()
4752
})
4853

49-
it('shows alert', async () => {
50-
// Clear previous cookie setting if any
51-
// cookieGetter.mockClear()
52-
// cookieGetter.mockRejectedValueOnce(null)
54+
it('sets cookie when suppress button is clicked', async () => {
5355
const user = userEvent.setup({ skipHover: true })
56+
5457
render(
5558
<AppAlertComponent
59+
cookieStorageKey='test'
5660
message={
5761
<div>
5862
important message 2
5963
</div>
60-
}
61-
/>)
62-
screen.debug()
64+
}
65+
/>
66+
)
67+
6368
// click the Suppress button
6469
await user.click(screen.getByRole('button', { name: /Don't show this again/i }))
6570

66-
// alert dismissed
67-
expect(screen.queryAllByRole('button')).toHaveLength(0)
71+
// verify cookie was set
72+
expect(cookieSetter).toHaveBeenCalledWith('test', '1', { strict: true, expires: 30 })
6873
})
6974
})

0 commit comments

Comments
 (0)