|
| 1 | +declare var window: any |
| 2 | + |
| 3 | +import React, { useState, useEffect } from 'react' |
| 4 | +import styled from 'styled-components' |
| 5 | +import { GetGlobalColor, Text, Container } from '@titicaca/triple-design-system' |
| 6 | + |
| 7 | +const MIN_DESKTOP_WIDTH = 1142 |
| 8 | +const CLOSE_INSTALL_BUTTON_KEY = 'close_install_button' |
| 9 | + |
| 10 | +const FloatingButton = styled.div` |
| 11 | + position: fixed; |
| 12 | + height: 84px; |
| 13 | + border-radius: 42px; |
| 14 | + box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.07); |
| 15 | + background-color: rgba(${GetGlobalColor('blue')}, 0.98); |
| 16 | + bottom: 0; |
| 17 | + left: 10px; |
| 18 | + right: 10px; |
| 19 | + margin-bottom: 30px; |
| 20 | + overflow: hidden; |
| 21 | +
|
| 22 | + @media (min-width: ${MIN_DESKTOP_WIDTH}px) { |
| 23 | + display: none; |
| 24 | + } |
| 25 | +` |
| 26 | + |
| 27 | +const InstallDescription = styled(Text)` |
| 28 | + height: 21px; |
| 29 | + font-size: 18px; |
| 30 | + font-weight: bold; |
| 31 | + margin: 23px 0px 0px 32px; |
| 32 | + color: rgb(${GetGlobalColor('white')}); |
| 33 | +` |
| 34 | + |
| 35 | +const Description = styled(Text)` |
| 36 | + width: 200px; |
| 37 | + height: 15px; |
| 38 | + font-size: 12px; |
| 39 | + font-weight: 500; |
| 40 | + color: rgba(${GetGlobalColor('white')}, 0.6); |
| 41 | + margin: 3px 0px 22px 32px; |
| 42 | +` |
| 43 | + |
| 44 | +const GoAppButton = styled.img` |
| 45 | + width: 20px; |
| 46 | + height: 20px; |
| 47 | +` |
| 48 | + |
| 49 | +const CloseButton = styled.img` |
| 50 | + width: 30px; |
| 51 | + height: 30px; |
| 52 | + margin: 27px 16px 27px 0; |
| 53 | +` |
| 54 | + |
| 55 | +export default function FloatingInstallButton({ |
| 56 | + appInstallLink, |
| 57 | + isPublic, |
| 58 | + trackEvent, |
| 59 | + trackEventParams, |
| 60 | +}: { |
| 61 | + appInstallLink?: string |
| 62 | + isPublic?: boolean |
| 63 | + trackEvent?: any |
| 64 | + trackEventParams?: { |
| 65 | + onShow?: any |
| 66 | + onSelect?: any |
| 67 | + onClose?: any |
| 68 | + } |
| 69 | +}) { |
| 70 | + const [buttonVisibility, setButtonVisibility] = useState(false) |
| 71 | + |
| 72 | + const sendTrackEventRequest = (param) => { |
| 73 | + trackEvent && param && trackEvent(param) |
| 74 | + } |
| 75 | + |
| 76 | + useEffect(() => { |
| 77 | + const visitedPages = window.sessionStorage.getItem(CLOSE_INSTALL_BUTTON_KEY) |
| 78 | + if (!visitedPages) { |
| 79 | + setButtonVisibility(true) |
| 80 | + sendTrackEventRequest(trackEventParams && trackEventParams.onShow) |
| 81 | + } |
| 82 | + }) |
| 83 | + |
| 84 | + const onClose = () => { |
| 85 | + setButtonVisibility(false) |
| 86 | + window.sessionStorage.setItem(CLOSE_INSTALL_BUTTON_KEY, 'true') |
| 87 | + sendTrackEventRequest(trackEventParams && trackEventParams.onClose) |
| 88 | + } |
| 89 | + |
| 90 | + const onSelect = () => { |
| 91 | + sendTrackEventRequest(trackEventParams && trackEventParams.onSelect) |
| 92 | + } |
| 93 | + |
| 94 | + return buttonVisibility && isPublic ? ( |
| 95 | + <FloatingButton> |
| 96 | + <Container floated="left"> |
| 97 | + <InstallDescription> |
| 98 | + <a href={appInstallLink} onClick={onSelect}> |
| 99 | + <Container floated="left">트리플 앱 설치하기</Container> |
| 100 | + <GoAppButton src="https://assets.triple.guide/images/[email protected]" /> |
| 101 | + </a> |
| 102 | + </InstallDescription> |
| 103 | + <Description>가이드북, 일정짜기, 길찾기, 맛집</Description> |
| 104 | + </Container> |
| 105 | + <Container floated="right" onClick={onClose}> |
| 106 | + <CloseButton src="https://assets.triple.guide/images/[email protected]" /> |
| 107 | + </Container> |
| 108 | + </FloatingButton> |
| 109 | + ) : null |
| 110 | +} |
0 commit comments