Commit 41ad8058 authored by Denis Sedura's avatar Denis Sedura

[RNA-774] Wrap Login

parent 0d53087f
......@@ -4,6 +4,7 @@ import { connect } from 'react-redux'
import { denormalize } from 'normalizr'
import { createSelector } from 'reselect'
import { isEqual } from 'lodash'
import { Router } from 'tipsi-router'
import {
entitiesSelector,
paginationsSelector,
......@@ -72,8 +73,9 @@ export function enhanceAddToCartView(ComposedComponent) {
const { storeId, inventoryId, isAddingToCart, user } = this.props
if (!user) {
// this.props.navigation.showModal('Login')
console.log('No user')
Router.showModal(null, Router.routes.login, {
config: { navigationBar: { visible: false } },
})
return
}
......@@ -136,10 +138,11 @@ export function enhanceAddToCartView(ComposedComponent) {
}
render() {
console.log('props', this.props)
return (
<ComposedComponent
{...this.props}
addToCart={this.addToCart}
loadStoreCart={this.loadStoreCart}
countForOrder={this.countForOrder}
countForOrderProduct={this.countForOrderProduct}
handleCartButtonOnPress={this.handleCartButtonOnPress}
......@@ -161,6 +164,7 @@ export function enhanceAddToCartView(ComposedComponent) {
(order = {}, paginations, entities) => {
const { ids = [] } = paginations.orderProducts[order.id] || {}
const orderProducts = denormalize(ids, Schemas.ORDER_PRODUCT_ARRAY, entities)
console.log(orderProducts)
return { order, orderProducts }
}
)
......
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import { Router } from 'tipsi-router'
import {
loginEmail,
loginTwitter,
loginFacebook,
loadUserProfile,
register,
linkSocialAccount,
} from 'tipsi_api/actions'
import { authSelector, userSelector } from 'tipsi_api/selectors'
function enhanceLogin(ComposedComponent) {
class Wrapper extends Component {
static propTypes = {
loginEmail: PropTypes.func.isRequired,
loginTwitter: PropTypes.func.isRequired,
loginFacebook: PropTypes.func.isRequired,
loadUserProfile: PropTypes.func.isRequired,
navigation: PropTypes.object.isRequired,
isLoading: PropTypes.bool.isRequired,
isTwitterLoading: PropTypes.bool.isRequired,
isFacebookLoading: PropTypes.bool.isRequired,
route: PropTypes.object.isRequired,
user: PropTypes.object,
}
static defaultProps = {
user: null,
}
state = {
username: '',
password: '',
}
componentWillReceiveProps(nextProps) {
const { route, user } = nextProps
if (!this.props.user && user && user.username) {
Router.dismissModal()
if (route.params.redirect) {
// navigation.getNavigator('app').push(route.params.redirect, { user })
console.log('Redirect to');
}
}
}
handleDismissLogin = () => {
Router.dismissModal()
}
handleChangeUsername = (username) => {
this.setState({ username })
}
handleChangePassword = (password) => {
this.setState({ password: password.replace(/\s+/g, '') })
}
render() {
return (
<ComposedComponent
{...this.props}
{...this.state}
handleDismissLogin={this.handleDismissLogin}
handleChangeUsername={this.handleChangeUsername}
handleChangePassword={this.handleChangePassword}
/>
)
}
}
const mapStateToProps = createSelector(
[authSelector, userSelector],
({ isLoading, isTwitterLoading, isFacebookLoading }, user) => ({
...user,
isLoading,
isTwitterLoading,
isFacebookLoading,
})
)
const mapDispatchToProps = {
loginEmail,
loginTwitter,
loginFacebook,
loadUserProfile,
register,
linkSocialAccount,
}
return connect(mapStateToProps, mapDispatchToProps)(Wrapper)
}
export default enhanceLogin
export { default as enhanceLogin } from './Login'
......@@ -12,7 +12,6 @@
"date-fns": "^1.28.1",
"decimal.js-light": "^2.2.4",
"lodash": "^4.17.4",
"normalizr": "^3.2.2",
"prop-types": "^15.5.10",
"react": "16.0.0-alpha.12",
"react-dom": "^16.1.1",
......@@ -28,6 +27,7 @@
"tipsi-stripe": "4.0.0"
},
"peerDependencies": {
"normalizr": "^3.2.2",
"@expo/ex-navigation": "3.1.0",
"react-native-firebase-analytics": "3.0.2",
"tipsi_api": "git+ssh://git@git.gettipsi.com/tipsi_frontend/tipsi_api.git#1.30.0"
......
import { reduce, keys } from 'lodash'
import { enhanceAppComponent, enhanceItemDetails } from './Screens'
import { enhanceSearch } from './Screens/Search'
import { enhanceLogin } from './Screens/Login'
const routesMap = {
home: {
......@@ -15,6 +16,10 @@ const routesMap = {
path: 'itemDetails',
component: enhanceItemDetails,
},
login: {
path: 'login',
component: enhanceLogin,
},
}
export function createRoutes(routes = {}) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment