Skip to content

Commit c3f0b01

Browse files
committed
add support for expiration date
1 parent bb25cd2 commit c3f0b01

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/components/banner/index.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@ import {useEffect, useState} from 'react';
55
import styles from './banner.module.scss';
66

77
type BannerType = {
8+
/** This is an array of strings or RegExps to feed into new RegExp() */
89
appearsOn: (string | RegExp)[];
10+
/** String that is the label for the call to action button */
911
linkText: string;
12+
/** String that is the destination url of the call to action button */
1013
linkURL: string;
14+
/** String for the text of the banner */
1115
text: string;
16+
/** Optional ISO Date string that will hide the banner after this date without the need for a rebuild */
17+
expiresOn?: string;
1218
};
1319

1420
// BANNERS is an array of banner objects. You can add as many as you like. If
1521
// you need to disable all banners, set BANNERS to an empty array. Each banner
1622
// is evaluated in order, and the first one that matches will be shown.
1723
//
18-
// Banner Object Properties:
19-
//
20-
// - appearsOn: An array of RegExps or strings to feed into new RegExp()
21-
// - text: String for the text of the banner
22-
// - linkURL: String that is the destination url of the call to action button
23-
// - linkText: String that is the label for the call to action button
24-
//
2524
// Example:
2625
//
2726
// Examples:
@@ -68,6 +67,14 @@ const BANNERS: BannerType[] = [
6867
linkURL: 'https://sentry.io/thought-leadership',
6968
linkText: 'Get webinarly',
7069
},
70+
// example with an expiration date
71+
{
72+
appearsOn: ['^/platforms/javascript/guides/aws-lambda/'],
73+
text: "This banner should appear on the AWS Lambda guide, but won't because it's expired",
74+
linkURL: 'https://sentry.io/thought-leadership',
75+
linkText: 'Get webinarly',
76+
expiresOn: '2024-01-01T00:00:00Z',
77+
},
7178
// generic javascript example
7279
{
7380
// we can constrain it to the javascript platform page only
@@ -120,8 +127,12 @@ export function Banner() {
120127
);
121128
});
122129

123-
// Bail if no banner matches this page
124-
if (!matchingBanner) {
130+
// Bail if no banner matches this page or if the banner has expired
131+
if (
132+
!matchingBanner ||
133+
(matchingBanner.expiresOn &&
134+
new Date() > new Date(matchingBanner.expiresOn ?? null))
135+
) {
125136
return;
126137
}
127138

0 commit comments

Comments
 (0)