-
Notifications
You must be signed in to change notification settings - Fork 4
feat/forward-search-params #676
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import Button from "../../../../components/UI/Button"; | |
| import styled from "styled-components"; | ||
| import { BIG_BREAKPOINT } from "../../../../constants/BreakPoints"; | ||
| import { gaEventTracker } from "../../../../components/analytics/Analytics"; | ||
| import { useDateInterval } from "../../../../hooks/useDateInterval"; | ||
| import { useUrlBuilder } from "../../../../services/urlBuilder"; | ||
|
|
||
| const StyledActionDiv = styled.div` | ||
| display: flex; | ||
|
|
@@ -16,16 +18,8 @@ const StyledActionDiv = styled.div` | |
| `; | ||
|
|
||
| const ActionButtons: FC<React.PropsWithChildren<unknown>> = () => { | ||
| const ticketStartDay = new Date(data.tickets.startDay); | ||
| const ticketEndDay = new Date(data.tickets.endDay); | ||
| const CFPStartDay = new Date(data.cfp.startDay); | ||
| const CFPEndDay = new Date(data.cfp.endDay); | ||
| const sponsorshipStartDay = new Date(data.tickets.startDay); | ||
| const sponsorshipEndDay = new Date(data.tickets.endDay); | ||
| const today = new Date(); | ||
|
|
||
| const isBetween = (startDay: Date, endDay: Date): boolean => | ||
| startDay < new Date() && endDay > today; | ||
| const { isTicketsDisabled, isSponsorDisabled, isCfpDisabled } = | ||
| useDateInterval(new Date(), data); | ||
|
|
||
| const trackSponsorshipInfo = useCallback(() => { | ||
| gaEventTracker("sponsorship", "sponsorship"); | ||
|
|
@@ -41,27 +35,24 @@ const ActionButtons: FC<React.PropsWithChildren<unknown>> = () => { | |
|
|
||
| return ( | ||
| <StyledActionDiv> | ||
| {isBetween(ticketStartDay, ticketEndDay) && ( | ||
| <Button | ||
| onClick={trackTickets} | ||
| text="🎟️ Buy Tickets" | ||
| link="https://tickets.devbcn.com/event/devbcn-2023" | ||
| /> | ||
| )} | ||
| {isBetween(CFPStartDay, CFPEndDay) && ( | ||
| <Button | ||
| onClick={trackCFP} | ||
| text="📢 Call For Papers" | ||
| link={data.cfp.link} | ||
| /> | ||
| )} | ||
| {isBetween(sponsorshipStartDay, sponsorshipEndDay) && ( | ||
| <Button | ||
| onClick={trackSponsorshipInfo} | ||
| text="🤝 Sponsorship" | ||
| link="mailto:[email protected]?subject=devBcn sponsorship" | ||
| /> | ||
| )} | ||
| <Button | ||
| onClick={trackTickets} | ||
| text="🎟️ Buy Tickets" | ||
| link={useUrlBuilder("https://tickets.devbcn.com/event/devbcn-2023")} | ||
| disabled={isTicketsDisabled} | ||
| /> | ||
| <Button | ||
| onClick={trackCFP} | ||
| text="📢 Call For Papers" | ||
| link={data.cfp.link} | ||
| disabled={isCfpDisabled} | ||
| /> | ||
| <Button | ||
| onClick={trackSponsorshipInfo} | ||
| text="🤝 Sponsorship" | ||
| link="mailto:[email protected]?subject=devBcn sponsorship" | ||
| disabled={isSponsorDisabled} | ||
| /> | ||
| </StyledActionDiv> | ||
| ); | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,59 @@ | ||
| import {FC, useCallback} from "react"; | ||
| import { FC, useCallback } from "react"; | ||
| import data from "../../../data/2024.json"; | ||
| import styled from "styled-components"; | ||
| import {BIG_BREAKPOINT} from "../../../constants/BreakPoints"; | ||
| import {gaEventTracker} from "../../../components/analytics/Analytics"; | ||
| import { BIG_BREAKPOINT } from "../../../constants/BreakPoints"; | ||
| import { gaEventTracker } from "../../../components/analytics/Analytics"; | ||
| import Button from "../../../components/UI/Button"; | ||
| import { useDateInterval } from "../../../hooks/useDateInterval"; | ||
| import {useUrlBuilder} from "../../../services/urlBuilder"; | ||
|
|
||
| const StyledActionDiv = styled.div` | ||
| display: flex; | ||
| text-align: center; | ||
| display: flex; | ||
| text-align: center; | ||
|
|
||
| @media (max-width: ${BIG_BREAKPOINT}px) { | ||
| flex-direction: column; | ||
| width: 75%; | ||
| } | ||
| @media (max-width: ${BIG_BREAKPOINT}px) { | ||
| flex-direction: column; | ||
| width: 75%; | ||
| } | ||
| `; | ||
|
|
||
| const ActionButtons: FC<React.PropsWithChildren<unknown>> = () => { | ||
| const ticketStartDay = new Date(data.tickets.startDay); | ||
| const ticketEndDay = new Date(data.tickets.endDay); | ||
| const CFPStartDay = new Date(data.cfp.startDay); | ||
| const CFPEndDay = new Date(data.cfp.endDay); | ||
| const sponsorshipStartDay = new Date(data.sponsors.startDate); | ||
| const sponsorshipEndDay = new Date(data.sponsors.endDate); | ||
| const today = new Date(); | ||
|
|
||
| const isBetween = (startDay: Date, endDay: Date): boolean => | ||
| startDay < new Date() && endDay > today; | ||
|
|
||
| const trackSponsorshipInfo = useCallback(() => { | ||
| gaEventTracker("sponsorship", "sponsorship"); | ||
| }, []); | ||
|
|
||
| const trackTickets = useCallback(() => { | ||
| gaEventTracker("ticket", "tickets"); | ||
| }, []); | ||
|
|
||
| const trackCFP = useCallback(() => { | ||
| gaEventTracker("CFP", "CFP"); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <StyledActionDiv> | ||
| <Button | ||
| onClick={trackTickets} | ||
| text="🎟️ Buy Tickets" | ||
| link="https://tickets.devbcn.com/event/devbcn-2024" | ||
| disabled={!isBetween(ticketStartDay, ticketEndDay)} | ||
| /> | ||
| {isBetween(CFPStartDay, CFPEndDay) && ( | ||
| <Button | ||
| onClick={trackCFP} | ||
| text="📢 Call For Papers" | ||
| link={data.cfp.link} | ||
| /> | ||
| )} | ||
| {isBetween(sponsorshipStartDay, sponsorshipEndDay) && ( | ||
| <Button | ||
| onClick={trackSponsorshipInfo} | ||
| text="🤝 Sponsorship" | ||
| link="https://www.devbcn.com/sponsorship" | ||
| /> | ||
| )} | ||
| </StyledActionDiv> | ||
| ); | ||
| const { isSponsorDisabled, isCfpDisabled, isTicketsDisabled } = | ||
| useDateInterval(new Date(), data); | ||
|
|
||
| const trackSponsorshipInfo = useCallback(() => { | ||
| gaEventTracker("sponsorship", "sponsorship"); | ||
| }, []); | ||
|
|
||
| const trackTickets = useCallback(() => { | ||
| gaEventTracker("ticket", "tickets"); | ||
| }, []); | ||
|
|
||
| const trackCFP = useCallback(() => { | ||
| gaEventTracker("CFP", "CFP"); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <StyledActionDiv> | ||
| <Button | ||
| onClick={trackTickets} | ||
| text="🎟️ Buy Tickets" | ||
| link={useUrlBuilder("https://tickets.devbcn.com/event/devbcn-2024")} | ||
| disabled={isTicketsDisabled} | ||
| /> | ||
| <Button | ||
| onClick={trackCFP} | ||
| text="📢 Call For Papers" | ||
| link={data.cfp.link} | ||
| disabled={isCfpDisabled} | ||
| /> | ||
| <Button | ||
| onClick={trackSponsorshipInfo} | ||
| text="🤝 Sponsorship" | ||
| link="https://www.devbcn.com/sponsorship" | ||
| disabled={isSponsorDisabled} | ||
| /> | ||
| </StyledActionDiv> | ||
| ); | ||
| }; | ||
| export default ActionButtons; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useDateInterval } from './useDateInterval'; | ||
|
|
||
| const today = new Date('2023-10-10'); | ||
|
|
||
| const edition = { | ||
| tickets: { | ||
| startDay: '2023-10-01', | ||
| endDay: '2023-10-15', | ||
| }, | ||
| cfp: { | ||
| startDay: '2023-09-01', | ||
| endDay: '2023-09-30', | ||
| }, | ||
| sponsors: { | ||
| startDate: '2023-10-05', | ||
| endDate: '2023-10-20', | ||
| }, | ||
| }; | ||
|
|
||
| describe('useDateInterval', () => { | ||
| it('should return correct disabled states for tickets, cfp, and sponsors', () => { | ||
| const { result } = renderHook(() => useDateInterval(today, edition)); | ||
|
|
||
| expect(result.current.isTicketsDisabled).toBe(false); | ||
| expect(result.current.isCfpDisabled).toBe(true); | ||
| expect(result.current.isSponsorDisabled).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { isWithinInterval } from "date-fns"; | ||
|
|
||
| type DateInterval = { | ||
| tickets:{ | ||
| startDay: string, | ||
| endDay: string, | ||
| }, | ||
| cfp:{ | ||
| startDay: string, | ||
| endDay: string, | ||
| }, | ||
| sponsors:{ | ||
| startDate: string, | ||
| endDate: string, | ||
| } | ||
| } | ||
|
|
||
| export const useDateInterval = (today: Date, edition: DateInterval) => { | ||
| const ticketStartDay = new Date(edition.tickets.startDay); | ||
| const ticketEndDay = new Date(edition.tickets.endDay); | ||
| const CFPStartDay = new Date(edition.cfp.startDay); | ||
| const CFPEndDay = new Date(edition.cfp.endDay); | ||
| const sponsorStartDay = new Date(edition.sponsors.startDate); | ||
| const sponsorEndDay = new Date(edition.sponsors.endDate); | ||
|
|
||
| return { | ||
| isTicketsDisabled: !isWithinInterval(today, { | ||
| start: ticketStartDay, | ||
| end: ticketEndDay, | ||
| }), | ||
| isCfpDisabled: !isWithinInterval(today, { | ||
| start: CFPStartDay, | ||
| end: CFPEndDay, | ||
| }), | ||
| isSponsorDisabled: !isWithinInterval(today, { | ||
| start: sponsorStartDay, | ||
| end: sponsorEndDay, | ||
| }), | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { useUrlBuilder } from './urlBuilder'; | ||
|
|
||
| // Mock window.location for the test | ||
| const originalLocation = window.location; | ||
| delete window.location; | ||
| window.location = { | ||
| origin: 'http://localhost', | ||
| search: '?query=123', | ||
| } as any; | ||
|
|
||
| describe('useUrlBuilder', () => { | ||
| afterAll(() => { | ||
| // Restore original window.location after tests | ||
| window.location = originalLocation; | ||
| }); | ||
|
|
||
| it('should append the current search params to the URL', () => { | ||
| const url = 'http://example.com/path'; | ||
| const result = useUrlBuilder(url); | ||
| expect(result).toBe('http://example.com/path?query=123'); | ||
| }); | ||
|
|
||
| it('should handle URLs without a path', () => { | ||
| const url = 'http://example.com'; | ||
| const result = useUrlBuilder(url); | ||
| expect(result).toBe('http://example.com/?query=123'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const useUrlBuilder = (url: string) => { | ||
| const returnUrl = new URL(url, window.location.origin); | ||
| returnUrl.search = window.location.search; | ||
| return returnUrl.toString(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.