File size: 1,243 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import * as React from 'react';
import FormattedHeader from 'calypso/components/formatted-header';
import { useLocalizedMoment } from 'calypso/components/localized-moment';
import { useSelector } from 'calypso/state';
import { getJetpackSaleCoupon } from 'calypso/state/marketing/selectors';

import './style.scss';

const useHasSaleBanner = () => {
	const moment = useLocalizedMoment();
	const coupon = useSelector( getJetpackSaleCoupon );

	const now = moment.utc().unix();
	const expiryDate = moment.utc( coupon?.expiry_date ).unix();
	const isBeforeExpiry = coupon && now <= expiryDate;

	return isBeforeExpiry;
};

const Header: React.FC< Props > = ( { title } ) => {
	const translate = useTranslate();
	const hasSaleBanner = useHasSaleBanner();

	return (
		<>
			<div className={ clsx( 'header', { 'has-sale-banner': hasSaleBanner } ) }>
				<FormattedHeader
					className="header__main-title"
					headerText={
						title ?? translate( 'Security, performance, and marketing tools made for WordPress' )
					}
					align="center"
				/>
			</div>
		</>
	);
};

type Props = {
	urlQueryArgs: { [ key: string ]: string };
	title?: string;
};

export default Header;