Skip to content

Commit

Permalink
[docs-infra] Automatically hide Black Friday banner (mui#44630)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Dec 2, 2024
1 parent 1d5ee97 commit 11cf1ba
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions docs/src/components/banner/AppFrameBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import FEATURE_TOGGLE from 'docs/src/featureToggle';
import PageContext from 'docs/src/modules/components/PageContext';
import { convertProductIdToName } from 'docs/src/modules/components/AppSearch';

const showSurveyMessage = false;

function isBlackFriday() {
const today = Date.now();
const start = new Date('2024-11-25').getTime();
const end = new Date('2024-12-07T23:59:59Z').getTime();
return today > start && today < end;
}

export default function AppFrameBanner() {
if (!FEATURE_TOGGLE.enable_docsnav_banner) {
return null;
Expand All @@ -14,11 +23,17 @@ export default function AppFrameBanner() {
// eslint-disable-next-line react-hooks/rules-of-hooks -- FEATURE_TOGGLE never changes
const pageContext = React.useContext(PageContext);
const productName = convertProductIdToName(pageContext) || 'MUI';
const surveyMessage = `Influence ${productName}'s 2024 roadmap! Participate in the latest Developer Survey`;
const blackFridayMessage = `Black Friday is here! Don't miss out on the best offers of the year.`;

const showSurveyMessage = false;
const message = showSurveyMessage ? surveyMessage : blackFridayMessage;
let message = '';
let href = '';

if (showSurveyMessage) {
message = `Influence ${productName}'s 2024 roadmap! Participate in the latest Developer Survey`;
href = 'https://tally.so/r/3Ex4PN?source=website';
} else if (isBlackFriday()) {
message = `Black Friday is here! Don't miss out on the best offers of the year.`;
href = 'https://mui.com/store/bundles/?deal=black-friday&from=docs';
}

if (process.env.NODE_ENV !== 'production') {
if (message.length > 100) {
Expand All @@ -28,18 +43,18 @@ export default function AppFrameBanner() {
}
}

if (message === '' || href === '') {
return null;
}

return (
<Link
href={
showSurveyMessage
? 'https://tally.so/r/3Ex4PN?source=website'
: 'https://mui.com/store/bundles/?deal=black-friday&from=docs'
}
href={href}
target="_blank"
variant="caption"
sx={[
(theme) => ({
padding: theme.spacing('7px', 1.5, '8px', 1.5),
padding: theme.spacing('6px', 1.5),
display: { xs: 'none', md: 'block' },
fontWeight: 'medium',
textWrap: 'nowrap',
Expand Down

0 comments on commit 11cf1ba

Please sign in to comment.