How to use the redux/selectors.users function in redux

To help you get started, we’ve selected a few redux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChingStore / ching / src / components / routes / index.js View on Github external
{/* With NavBar */}
              
              
              
              {/* Redirect if no match */}
              
            
          
        
      
    )
  }
}

const mapStateToProps = Reselect.createStructuredSelector({
  currentUserId: selectors.users.currentId,
})

export default ReactRedux.connect(
  mapStateToProps
)(Routes)
github ChingStore / ching / src / components / shopping-cart / container / index.js View on Github external
// @flow

import type { DispatchType } from 'constants/redux'

import * as ReactRedux from 'react-redux'
import * as Reselect from 'reselect'

import selectors from 'redux/selectors'
import shoppingCartAction from 'redux/actions/shopping-cart'

import * as ShoppingCart from '../index'

const mapStateToProps = Reselect.createStructuredSelector({
  order: selectors.orders.shoppingCart,
  orderId: selectors.users.shoppingCartOrderId,
  walletAddress: selectors.wallet.address,
})

const mapDispatchToProps = (dispatch: DispatchType) => ({
  onResetShoppingCart: () => {
    dispatch(shoppingCartAction.reset())
  },
})

export default ReactRedux.connect(
  mapStateToProps,
  mapDispatchToProps
)(ShoppingCart.default)
github ChingStore / ching / src / redux / actions / order.js View on Github external
): ThunkActionType<{ order: ?OrderType, orderId: ?IdType }> => (
  dispatch,
  getState
) => {
  const state = getState()
  const shoppingCartOrderId = selector.users.shoppingCartOrderId(state)

  let order = null
  let orderId = null
  if (inputOrderId) {
    orderId = inputOrderId
    order = selector.orders.order(state, { orderId })
  } else if (shoppingCartOrderId) {
    order = selector.orders.shoppingCart(state)
    orderId = shoppingCartOrderId
  }

  console.log({ orderId, shoppingCartOrderId, order })

  return { order, orderId }
}
github ChingStore / ching / src / components / inventory / index.js View on Github external
const mapStateToProps = state => ({
  auth: selectors.getAuthState(state),
  items: selectors.getItemsState(state),
  orders: selectors.orders.all(state),
  shoppingCartOrderId: selectors.users.shoppingCartOrderId(state),
})
github ChingStore / ching / src / redux / actions / current-user.js View on Github external
): ThunkActionType> => async (
  dispatch,
  getState,
  { getFirebase }
) => {
  const state = getState()
  const currentUserId = selectors.users.currentId(state)
  await getFirebase()
    .collection('users')
    .doc(currentUserId)
    .update({
      shoppingCartOrderId: orderId,
    })
}
github ChingStore / ching / src / components / onboarding / sign-up-oauth / container / index.js View on Github external
import * as ReactRedux from 'react-redux'
import * as Reselect from 'reselect'
import currentUser from 'redux/actions/current-user'
import selectors from 'redux/selectors'
import SignInOAuth from '..'

const mapStateToProps = Reselect.createStructuredSelector({
  userId: selectors.users.currentId,
  storeId: selectors.users.currentStoreId,
})

const mapDispatchToProps = dispatch => ({
  signInWithOAuth: service => dispatch(currentUser.signInWithOAuth(service)),
})

export default ReactRedux.connect(
  mapStateToProps,
  mapDispatchToProps
)(SignInOAuth)
github ChingStore / ching / src / components / profile / container / index.js View on Github external
import * as ReactRedux from 'react-redux'
import * as ReactRouter from 'react-router'
import * as Reselect from 'reselect'

import selectors from 'redux/selectors'
import currentUserAction from 'redux/actions/current-user'
import shopAction from 'redux/actions/shop'

import * as Profile from '../index'

type OwnPropsType = ReactRouter.ContextRouter

const mapStateToProp = Reselect.createStructuredSelector({
  authError: selectors.getAuthError,
  email: selectors.users.current,
  walletAddress: selectors.wallet.address,
  store: selectors.shop.current,
  storeId: selectors.users.currentStoreId,
})

const mapDispatchToProps = (dispatch: DispatchType) => ({
  signOut: () => dispatch(currentUserAction.signOut()),

  onUpdateAddress: async ({
    walletAddress,
    storeId,
  }: {
    walletAddress: string,
    storeId: IdType,
  }) => {
    const data = { walletAddress }
github ChingStore / ching / src / redux / actions / shop.js View on Github external
}: $Shape): ThunkActionType> => async (
  dispatch,
  getState,
  { getFirestore }
) => {
  const state = getState()
  const uid = selectors.users.currentId(state)
  if (!uid) {
    dispatch({
      type: ACTIONS.SHOP_SIGNUP_ERROR,
      payload: 'First, you should login or signup user account',
    })
    return false
  }

  if (!storeName) {
    dispatch({
      type: ACTIONS.SHOP_SIGNUP_ERROR,
      payload: 'Store name is empty. Please type it in.',
    })
    return false
  }
github ChingStore / ching / src / redux / actions / shopping-cart.js View on Github external
const resetTransaction = (): ThunkActionType> => async (
  dispatch,
  getState,
  { getFirestore }
) => {
  const state = getState()
  const orderId = selectors.users.shoppingCartOrderId(state)

  await getFirestore()
    .collection('orders')
    .doc(orderId)
    .update({
      txHash: null,
      txConfirmed: null,
    })
}
github ChingStore / ching / src / components / store / container / item-card.js View on Github external
import orderAction from 'redux/actions/order'
import selectors from 'redux/selectors'

import ItemCard from '../item-card'

type OwnPropsType = {
  item: ItemType,
  itemId: IdType,
  isFirstInRow: boolean,
  isEditing: boolean,
}

const mapStateToProps = Reselect.createStructuredSelector({
  item: selectors.items.item,
  orderId: selectors.users.shoppingCartOrderId,
  shoppingCartOrderItem: selectors.items.shoppingCartOrderItem,
})

const mapDispatchToProps = (
  dispatch: DispatchType,
  ownProps: OwnPropsType
) => ({
  onBadgeClick: async () => {
    const { itemId } = ownProps
    await dispatch(orderAction.removeItem({ itemId }))
  },
  onPhotoClick: async () => {
    const { itemId } = ownProps
    await dispatch(orderAction.addItem({ itemId }))
  },
})