|
| 1 | +import type { MouseEvent, ReactElement } from 'react'; |
| 2 | +import React, { useEffect, useRef } from 'react'; |
| 3 | +import type { ModalProps } from './common/Modal'; |
| 4 | +import { Modal } from './common/Modal'; |
| 5 | +import { Button, ButtonVariant } from '../buttons/Button'; |
| 6 | +import { Image } from '../image/Image'; |
| 7 | +import Link from '../utilities/Link'; |
| 8 | +import { opportunityUrl } from '../../lib/constants'; |
| 9 | +import { useViewSize, ViewSize } from '../../hooks'; |
| 10 | +import { useThemedAsset } from '../../hooks/utils'; |
| 11 | +import { Typography, TypographyType } from '../typography/Typography'; |
| 12 | +import { MoveToIcon } from '../icons'; |
| 13 | +import { useLogContext } from '../../contexts/LogContext'; |
| 14 | +import { LogEvent, TargetId } from '../../lib/log'; |
| 15 | + |
| 16 | +export interface JobOpportunityModalProps extends ModalProps { |
| 17 | + opportunityId: string; |
| 18 | +} |
| 19 | + |
| 20 | +export const JobOpportunityModal = ({ |
| 21 | + opportunityId, |
| 22 | + onRequestClose, |
| 23 | + ...modalProps |
| 24 | +}: JobOpportunityModalProps): ReactElement => { |
| 25 | + const isMobile = useViewSize(ViewSize.MobileL); |
| 26 | + const { jobOfferDesktop, jobOfferMobile } = useThemedAsset(); |
| 27 | + const { logEvent } = useLogContext(); |
| 28 | + const logRef = useRef<typeof logEvent>(); |
| 29 | + const hasLoggedRef = useRef(false); |
| 30 | + logRef.current = logEvent; |
| 31 | + |
| 32 | + const logExtraPayload = JSON.stringify({ |
| 33 | + count: 1, // always 1 for now |
| 34 | + }); |
| 35 | + |
| 36 | + const onClick = (event: MouseEvent) => { |
| 37 | + logRef.current({ |
| 38 | + event_name: LogEvent.ClickOpportunityNudge, |
| 39 | + target_id: TargetId.Fullscreen, |
| 40 | + extra: logExtraPayload, |
| 41 | + }); |
| 42 | + onRequestClose(event); |
| 43 | + }; |
| 44 | + |
| 45 | + useEffect(() => { |
| 46 | + if (hasLoggedRef.current) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + logRef.current({ |
| 51 | + event_name: LogEvent.ImpressionOpportunityNudge, |
| 52 | + target_id: TargetId.Fullscreen, |
| 53 | + extra: logExtraPayload, |
| 54 | + }); |
| 55 | + hasLoggedRef.current = true; |
| 56 | + }, [logExtraPayload]); |
| 57 | + |
| 58 | + return ( |
| 59 | + <> |
| 60 | + <div className="fixed z-header size-full rounded-[63.75rem] bg-background-default blur-[6.875rem]"> |
| 61 | + test |
| 62 | + </div> |
| 63 | + <Modal |
| 64 | + {...modalProps} |
| 65 | + kind={Modal.Kind.FlexibleCenter} |
| 66 | + size={Modal.Size.Medium} |
| 67 | + onRequestClose={onRequestClose} |
| 68 | + className="!border-transparent !bg-transparent !shadow-none" |
| 69 | + overlayClassName="!bg-transparent" |
| 70 | + isDrawerOnMobile |
| 71 | + > |
| 72 | + <Modal.Body className="items-center overflow-hidden !p-0"> |
| 73 | + <div className="flex h-full flex-col items-start justify-center gap-6 px-6 py-10 tablet:items-center tablet:px-10 tablet:py-14"> |
| 74 | + <div className="relative flex items-center justify-center"> |
| 75 | + <Image |
| 76 | + src={isMobile ? jobOfferMobile : jobOfferDesktop} |
| 77 | + alt="Job offer for you" |
| 78 | + className="h-72 w-auto tablet:h-64" |
| 79 | + /> |
| 80 | + </div> |
| 81 | + <Typography type={TypographyType.Title3}> |
| 82 | + We think this role deserves your attention, but your decision is |
| 83 | + private. If it’s a fit, we’ll handle it quietly. If not, it’s gone |
| 84 | + for good. |
| 85 | + </Typography> |
| 86 | + <div className="flex w-full flex-col gap-3"> |
| 87 | + <Link href={`${opportunityUrl}/${opportunityId}`} passHref> |
| 88 | + <Button |
| 89 | + tag="a" |
| 90 | + className="w-full gap-2" |
| 91 | + variant={ButtonVariant.Primary} |
| 92 | + onClick={onClick} |
| 93 | + > |
| 94 | + Show me now <MoveToIcon /> |
| 95 | + </Button> |
| 96 | + </Link> |
| 97 | + <Button |
| 98 | + className="w-full" |
| 99 | + variant={ButtonVariant.Float} |
| 100 | + onClick={onClick} |
| 101 | + > |
| 102 | + Maybe later |
| 103 | + </Button> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </Modal.Body> |
| 107 | + </Modal> |
| 108 | + </> |
| 109 | + ); |
| 110 | +}; |
| 111 | + |
| 112 | +export default JobOpportunityModal; |
0 commit comments