Skip to content

Commit 255e9cd

Browse files
authored
show CTA notification based on build config
1 parent d09f8d9 commit 255e9cd

4 files changed

Lines changed: 45 additions & 13 deletions

File tree

hack/publish-content.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cd $SCRIPT_DIR/..
88

99
export ENABLE_INDEX="1"
1010
export MANIFESTS_REF="$BRANCH"
11+
export SHOW_NOTIFICATION="1"
1112

1213
yarn install
1314
yarn workspace website clear

website/docusaurus.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const config = {
3737
onBrokenMarkdownLinks: "warn",
3838
favicon: "img/favicon.png",
3939
noIndex: process.env.ENABLE_INDEX !== "1",
40+
customFields: {
41+
showNotification: process.env.SHOW_NOTIFICATION === "1",
42+
},
4043

4144
organizationName: "aws-samples",
4245
projectName: "eks-workshop-v2",

website/src/components/GlobalNotification/index.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,47 @@ import React, { useState, useEffect } from 'react';
22
import styles from './styles.module.css';
33
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
44
import { faArrowUpRightFromSquare, faTimes } from "@fortawesome/free-solid-svg-icons";
5-
import notificationConfig from '../../config/notification.json';
5+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
6+
7+
const notificationConfig = {
8+
prefix: "Live:",
9+
text: "Hands-on EKS Workshop Series -",
10+
linkText: "Register",
11+
linkUrl: "https://aws-experience.com/emea/smb/events/series/get-hands-on-with-amazon-eks?trk=d42ffbaa-d60a-4513-8a79-0bf36b9f33ce&sc_channel=el"
12+
};
613

714
const GlobalNotification = () => {
815
const [isVisible, setIsVisible] = useState(false);
916
const [isAnimating, setIsAnimating] = useState(false);
17+
const { siteConfig } = useDocusaurusContext();
1018

11-
// Don't render if notification is disabled in config
12-
if (!notificationConfig.enabled) return null;
19+
// Don't render if notification is disabled via customFields
20+
if (!siteConfig.customFields.showNotification) return null;
1321

1422
useEffect(() => {
15-
const dismissed = localStorage.getItem('eks-workshop-notification-dismissed');
16-
if (!dismissed) {
23+
const dismissedData = localStorage.getItem('eks-workshop-notification-dismissed');
24+
25+
if (!dismissedData) {
26+
// Not dismissed yet
27+
setIsVisible(true);
28+
setTimeout(() => setIsAnimating(true), 100);
29+
return;
30+
}
31+
32+
try {
33+
const { timestamp } = JSON.parse(dismissedData);
34+
const now = new Date().getTime();
35+
const daysSinceDismissed = (now - timestamp) / (1000 * 60 * 60 * 24);
36+
37+
if (daysSinceDismissed > 7) {
38+
// Expired, show notification again
39+
localStorage.removeItem('eks-workshop-notification-dismissed');
40+
setIsVisible(true);
41+
setTimeout(() => setIsAnimating(true), 100);
42+
}
43+
} catch (e) {
44+
// If there's any error parsing (old format), show notification
45+
localStorage.removeItem('eks-workshop-notification-dismissed');
1746
setIsVisible(true);
1847
setTimeout(() => setIsAnimating(true), 100);
1948
}
@@ -23,7 +52,13 @@ const GlobalNotification = () => {
2352
setIsAnimating(false);
2453
setTimeout(() => {
2554
setIsVisible(false);
26-
localStorage.setItem('eks-workshop-notification-dismissed', 'true');
55+
56+
// Store dismissal with timestamp
57+
const dismissalData = {
58+
timestamp: new Date().getTime()
59+
};
60+
61+
localStorage.setItem('eks-workshop-notification-dismissed', JSON.stringify(dismissalData));
2762
}, 300);
2863
};
2964

website/src/config/notification.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)