Skip to content

Commit

Permalink
chore: Auto dismiss if a user is logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Feb 10, 2023
1 parent 6104b16 commit 61bb9b9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/templates/docPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from 'react';
import React, { useMemo, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { graphql } from 'gatsby';
Expand All @@ -13,7 +13,7 @@ import {
RelatedResources,
ComplexFeedback,
TableOfContents,
useHasMounted,
useLoggedIn,
} from '@newrelic/gatsby-theme-newrelic';
import MachineTranslationCallout from '../components/MachineTranslationCallout';
import SEO from '../components/SEO';
Expand Down Expand Up @@ -88,6 +88,8 @@ const BasicDoc = ({ data, location, pageContext }) => {
`docBannerDismissed-${title}`
);

const { loggedIn } = useLoggedIn();

const [bannerDismissed, setBannerDismissed] = useBannerDismissed(null);
const [bannerVisible, setBannerVisible] = useState(bannerDismissed !== true);

Expand All @@ -96,7 +98,15 @@ const BasicDoc = ({ data, location, pageContext }) => {
setBannerDismissed(true);
};

const hasMounted = useHasMounted();
const [hasMounted, setHasMounted] = useState(false);

useEffect(() => {
if (loggedIn) {
setBannerVisible(false);
setBannerDismissed(true);
}
setHasMounted(true);
}, [loggedIn, setBannerDismissed]);

if (!hasMounted) {
return null;
Expand Down

0 comments on commit 61bb9b9

Please sign in to comment.