-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathJobOpportunityButton.tsx
More file actions
83 lines (75 loc) · 2.67 KB
/
JobOpportunityButton.tsx
File metadata and controls
83 lines (75 loc) · 2.67 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, { useEffect, useRef } from 'react';
import type { ReactElement } from 'react';
import classNames from 'classnames';
import { Button } from '../../../components/buttons/Button';
import { JobIcon } from '../../../components/icons';
import { ButtonSize, ButtonVariant } from '../../../components/buttons/common';
import { briefButtonBg } from '../../../styles/custom';
import { Tooltip } from '../../../components/tooltip/Tooltip';
import { opportunityUrl } from '../../../lib/constants';
import Link from '../../../components/utilities/Link';
import { useViewSize, ViewSize } from '../../../hooks';
import { useAlertsContext } from '../../../contexts/AlertContext';
import { useLogContext } from '../../../contexts/LogContext';
import { LogEvent, TargetId } from '../../../lib/log';
import { useFeaturesReadyContext } from '../../../components/GrowthBookProvider';
import { opportunityButtonCopy } from '../../../lib/featureManagement';
type JobOpportunityButtonProps = {
className?: string;
};
export const JobOpportunityButton = ({
className,
}: JobOpportunityButtonProps): ReactElement => {
const isMobile = useViewSize(ViewSize.MobileL);
const { alerts } = useAlertsContext();
const { getFeatureValue } = useFeaturesReadyContext();
const { logEvent } = useLogContext();
const buttonCopy = getFeatureValue(opportunityButtonCopy);
const logRef = useRef<typeof logEvent>();
const hasLoggedRef = useRef(false);
logRef.current = logEvent;
const { opportunityId } = alerts;
const logExtraPayload = JSON.stringify({
count: 1, // always 1 for now
});
const handleClick = (): void => {
logRef.current({
event_name: LogEvent.ClickOpportunityNudge,
target_id: TargetId.HomepageButton,
extra: logExtraPayload,
});
};
useEffect(() => {
if (hasLoggedRef.current) {
return;
}
logRef.current({
event_name: LogEvent.ImpressionOpportunityNudge,
target_id: TargetId.HomepageButton,
extra: logExtraPayload,
});
hasLoggedRef.current = true;
}, [logExtraPayload]);
return (
<Tooltip
content="A personalized job was matched to your profile. Click to review it privately"
className="!max-w-80 text-center"
>
<Link href={`${opportunityUrl}/${opportunityId}`} passHref>
<Button
tag="a"
icon={<JobIcon />}
variant={ButtonVariant.Float}
size={isMobile ? ButtonSize.Small : ButtonSize.Medium}
style={{
background: briefButtonBg,
}}
className={classNames(className, 'border-none text-black')}
onClick={handleClick}
>
{buttonCopy}
</Button>
</Link>
</Tooltip>
);
};