Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as React from 'react'
- import { RouteComponentProps } from 'react-router'
- import { Redirect } from 'react-router-dom'
- import { observable, action } from 'mobx'
- import { observer, inject } from 'mobx-react'
- import { bind } from 'pik-react-utils'
- import styled from 'styled-components'
- import MediaQuery from 'react-responsive'
- import { Layout, Wrapper as Wrapper_, PublicFooter } from '~/components/common'
- import NewAccountForm from './NewAccountForm'
- import { STORE_AUTH, STORE_ENTITIES } from '~/constants/stores'
- import { NEW_ACCOUNT, SELECT_ACCOUNT } from '~/constants/links'
- import { account } from '~/types'
- import { MEDIA } from '~/constants/media-queries'
- import {
- MAIN_TEXT,
- BLUE,
- PLACEHOLDER,
- DARK_LINES,
- EXTRA_TEXT,
- PAGE_BG
- } from '~/components/pru/ui-colors'
- import {
- SecondaryBtn,
- SecondaryBtnIcon,
- SecondaryBtnSize
- } from '~/components/pru'
- const Fragment = React.Fragment
- const PageLayout = styled(Layout)`
- display: flex;
- min-width: 1024px;
- flex: 1;
- flex-direction: column;
- background: url(${require('./icons/bg-pattern.svg')}) no-repeat bottom center;
- background-size: contain;
- @media ${MEDIA.untilTablet} {
- min-width: 320px;
- background: none;
- }
- `
- const Wrapper = Wrapper_.extend`
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- min-height: auto;
- background-color: transparent;
- padding: 0;
- @media ${MEDIA.untilTablet} {
- display: flex;
- padding-top: 0;
- justify-content: start;
- }
- `
- const Content = styled.section`
- width: 436px;
- // margin-top: -48px;
- // padding-top: 48px;
- padding-bottom: 80px;
- @media ${MEDIA.untilTablet} {
- width: 100%;
- padding-left: 20px;
- padding-right: 20px;
- margin-top: 0;
- padding-top: 24px;
- padding-bottom: 0;
- }
- `
- const Heading = styled.h1`
- color: ${MAIN_TEXT};
- font-size: 30px;
- font-weight: normal;
- margin: 0;
- margin-bottom: 17px;
- margin-top: 48px;
- text-align: center;
- @media ${MEDIA.untilTablet} {
- font-size: 26px;
- margin-top: 0;
- text-align: left;
- margin-bottom: 10px;
- }
- `
- const Account = styled.button`
- width: 100%;
- padding: 12px 50px 12px 15px;
- background-color: #fff;
- border: none;
- border-left: 4px solid ${DARK_LINES};
- position: relative;
- box-shadow: 0 2px 15px 0 rgba(51, 51, 51, 0.08);
- cursor: pointer;
- text-align: left;
- margin-bottom: 12px;
- &:hover {
- border-left: 4px solid ${BLUE};
- }
- &::after {
- position: absolute;
- top: calc(50% - 6px);
- right: 20px;
- width: 8px;
- height: 8px;
- margin: 0 0 0 15px;
- content: '';
- border-top: 1px solid;
- border-right: 1px solid;
- transition: transform 0.2s ease-in-out;
- transform: translate3d(0, 2px, 0) rotate(45deg);
- }
- @media ${MEDIA.untilTablet} {
- padding: 14px 49px 15px 14px;
- background-image: none;
- box-shadow: none;
- &::after {
- transform: translate3d(0, 2px, 0) rotate(45deg);
- top: calc(50% - 6px);
- right: 21px;
- }
- }
- `
- const City = styled.div`
- font-size: 14px;
- line-height: 1.29;
- color: ${PLACEHOLDER};
- `
- const Address = styled.div`
- font-size: 20px;
- line-height: 1.1;
- color: ${MAIN_TEXT};
- margin-bottom: 8px;
- margin-top: 2px;
- `
- const AccountNumber = City.extend`
- text-transform: uppercase;
- `
- const Footer = styled(PublicFooter)`
- background-color: transparent;
- color: ${EXTRA_TEXT};
- opacity: 0.7;
- /* width: 200px;
- margin-bottom: 20px;
- margin-top: 80px; */
- `
- const AddAddressBtn = styled(SecondaryBtn)`
- background-color: ${PAGE_BG};
- &:hover{
- background-color: ${PAGE_BG};
- }
- &::before{
- width: 11px;
- height: 11px;
- margin-right: 7px;
- margin-left: 19px;
- margin-top: 3px;
- }
- @media ${MEDIA.untilTablet} {
- min-height: 46px;
- padding: 0;
- &::before{
- margin-right: 9px;
- margin-left: -10px;
- }
- }
- `
- @inject(STORE_AUTH, STORE_ENTITIES)
- @observer
- export default class PageSelectAccount extends React.Component<
- RouteComponentProps<{}>
- > {
- @observable creating = false
- constructor(props: RouteComponentProps<{}>) {
- super(props)
- this.setCreatingState(this.props.match.path)
- }
- @action
- setCreatingState(currentMatch: string) {
- this.creating = currentMatch === NEW_ACCOUNT
- }
- componentWillUpdate(nextProps: RouteComponentProps<{}>) {
- this.setCreatingState(nextProps.match.path)
- }
- handleSelectAccount(uid: string) {
- this.props[STORE_AUTH].setAccount(uid)
- this.props.history.push('/')
- }
- renderAccountSelection(accounts: any) {
- return (
- <Fragment>
- <Heading>Личный кабинет</Heading>
- {accounts.entities.map((acc: account) => {
- return (
- <Account
- key={acc._uid}
- onClick={bind(this, this.handleSelectAccount, acc._uid)}
- >
- <City>г. Москва</City>
- <Address>{acc.address}</Address>
- <AccountNumber>ЛС №112451753</AccountNumber>
- </Account>
- )
- })}
- <AddAddressBtn
- link={NEW_ACCOUNT}
- size={SecondaryBtnSize.LARGE}
- icon={SecondaryBtnIcon.ADD}
- >
- <MediaQuery query={MEDIA.fromTablet}>
- Добавить новый адрес
- </MediaQuery>
- <MediaQuery query={MEDIA.untilTablet}>
- Добавить адрес
- </MediaQuery>
- </AddAddressBtn>
- </Fragment>
- )
- }
- render() {
- const { [STORE_ENTITIES]: store } = this.props
- const accounts = store.getList('account')
- const hasAccounts = accounts && accounts.entities.length
- return (
- <PageLayout footer={false} header={false}>
- {!accounts ? (
- 'загрузка...'
- ) : this.creating ? (
- <Fragment>
- <Wrapper>
- <NewAccountForm firstAccount={!hasAccounts}/>
- </Wrapper>
- <MediaQuery query={MEDIA.fromTablet}>
- <Footer />
- </MediaQuery>
- </Fragment>
- ) : hasAccounts ? (
- <Fragment>
- <Wrapper>
- <Content>{this.renderAccountSelection(accounts)}</Content>
- </Wrapper>
- <Footer />
- </Fragment>
- ) : (
- <Redirect from={SELECT_ACCOUNT} to={NEW_ACCOUNT} />
- )}
- </PageLayout>
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement