Skip to content

Commit

Permalink
fix: Use router state to track page source
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Sep 28, 2023
1 parent 490db3e commit 983d562
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/common/components/CardActionRouterLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { Button, CardActions } from '@mui/material';

const CardActionRouterLink = ({ label, to }) => {
const CardActionRouterLink = ({ label, to, state }) => {
return (
<CardActions
sx={{
Expand All @@ -29,6 +29,7 @@ const CardActionRouterLink = ({ label, to }) => {
<Button
component={Link}
to={to}
state={state}
sx={{
fontWeight: 200,
width: '100%',
Expand Down
7 changes: 6 additions & 1 deletion src/home/components/HomeCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,19 @@ const HomeCard = ({
size="medium"
sx={{ color: 'white' }}
to={action.to}
state={action.pathState}
>
{action.label}
</RouterButton>
</CardActions>
) : (
<>
<Divider aria-hidden="false" />
<CardActionRouterLink label={action.label} to={action.to} />
<CardActionRouterLink
label={action.label}
to={action.to}
state={action.pathState}
/>
</>
))}
</Card>
Expand Down
8 changes: 4 additions & 4 deletions src/storyMap/components/StoryMapNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import _ from 'lodash/fp';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { Paper, useMediaQuery } from '@mui/material';

import { useDocumentTitle } from 'common/document';
Expand Down Expand Up @@ -93,21 +93,21 @@ const StoryMapNew = () => {
const dispatch = useDispatch();
const { t } = useTranslation();
const navigate = useNavigate();
const { state: locationState } = useLocation();
const { trackEvent } = useAnalytics();
const [searchParams] = useSearchParams();
const [saved, setSaved] = useState();

useDocumentTitle(t('storyMap.new_document_title'));

useEffect(() => {
const source = searchParams.get('source') || 'direct';
const source = locationState?.source || 'direct';
trackEvent('storymap.start', {
props: {
[ILM_OUTPUT_PROP]: LANDSCAPE_NARRATIVES,
source,
},
});
}, [trackEvent, searchParams]);
}, [trackEvent, locationState]);

useEffect(() => {
if (!saved) {
Expand Down
3 changes: 2 additions & 1 deletion src/storyMap/components/StoryMapsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ const StoryMapsCard = ({ title, storyMaps, showCreate = true }) => {
() =>
showCreate && {
label: t('storyMap.home_create'),
to: 'tools/story-maps/new?source=home_page',
to: 'tools/story-maps/new',
pathState: { source: 'home_page' },
},
[t, showCreate]
);
Expand Down
3 changes: 2 additions & 1 deletion src/storyMap/components/StoryMapsHomeCardDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const StoryMapsHomeCardDefault = () => {
titleId="story-maps-default-title"
action={{
label: t('storyMap.home_create'),
to: 'tools/story-maps/new?source=home_page',
to: 'tools/story-maps/new',
pathState: { source: 'home_page' },
}}
image={{
src: storyMapImage,
Expand Down
3 changes: 2 additions & 1 deletion src/storyMap/components/StoryMapsToolHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ const StoryMapsToolsHome = () => {
<Button
variant="contained"
component={Link}
to="/tools/story-maps/new?source=story_maps_page"
to="/tools/story-maps/new"
state={{ source: 'story_maps_page' }}
sx={{ mt: 2, mb: 3 }}
>
{t('storyMap.tool_home_create_button')}
Expand Down

0 comments on commit 983d562

Please sign in to comment.