|
| 1 | +import React, { useState, useEffect } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'; |
| 4 | +import { browserHistory } from 'react-router'; |
| 5 | +import styled from 'styled-components'; |
| 6 | +import PrivacyPolicy from './PrivacyPolicy'; |
| 7 | +import TermsOfUse from './TermsOfUse'; |
| 8 | +import RootPage from '../../../components/RootPage'; |
| 9 | +import Nav from '../../../components/Nav'; |
| 10 | +import { remSize, prop } from '../../../theme'; |
| 11 | + |
| 12 | +const StyledTabList = styled(TabList)` |
| 13 | + display: flex; |
| 14 | + max-width: ${remSize(680)}; |
| 15 | + padding-top: ${remSize(10)}; |
| 16 | + margin: 0 auto; |
| 17 | + border-bottom: 1px solid ${prop('Modal.separator')}; |
| 18 | +`; |
| 19 | + |
| 20 | +const StyledTab = styled(Tab)` |
| 21 | + cursor: pointer; |
| 22 | + & p { |
| 23 | + padding: 0 ${remSize(5)} ${remSize(5)} ${remSize(5)}; |
| 24 | + } |
| 25 | +`; |
| 26 | + |
| 27 | +function Legal({ location }) { |
| 28 | + const [selectedIndex, setSelectedIndex] = useState(0); |
| 29 | + useEffect(() => { |
| 30 | + if (location.pathname === '/privacy-policy') { |
| 31 | + setSelectedIndex(0); |
| 32 | + } else { |
| 33 | + setSelectedIndex(1); |
| 34 | + } |
| 35 | + }, [location]); |
| 36 | + |
| 37 | + function onSelect(index, lastIndex, event) { |
| 38 | + if (index === lastIndex) return; |
| 39 | + if (index === 0) { |
| 40 | + setSelectedIndex(0); |
| 41 | + browserHistory.push('/privacy-policy'); |
| 42 | + } else if (index === 1) { |
| 43 | + setSelectedIndex(1); |
| 44 | + browserHistory.push('/terms-of-use'); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return ( |
| 49 | + <RootPage> |
| 50 | + <Nav layout="dashboard" /> |
| 51 | + <Tabs selectedIndex={selectedIndex} onSelect={onSelect}> |
| 52 | + <StyledTabList> |
| 53 | + <StyledTab className="react-tabs__tab"> |
| 54 | + <p>Privacy Policy</p> |
| 55 | + </StyledTab> |
| 56 | + <StyledTab className="react-tabs__tab"> |
| 57 | + <p>Terms of Use</p> |
| 58 | + </StyledTab> |
| 59 | + </StyledTabList> |
| 60 | + <TabPanel> |
| 61 | + <PrivacyPolicy /> |
| 62 | + </TabPanel> |
| 63 | + <TabPanel> |
| 64 | + <TermsOfUse /> |
| 65 | + </TabPanel> |
| 66 | + </Tabs> |
| 67 | + </RootPage> |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +Legal.propTypes = { |
| 72 | + location: PropTypes.shape({ |
| 73 | + pathname: PropTypes.string |
| 74 | + }).isRequired |
| 75 | +}; |
| 76 | + |
| 77 | +export default Legal; |
0 commit comments