Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from jspaine/reactify/mod_packing
Browse files Browse the repository at this point in the history
packing list and volunteer components
  • Loading branch information
kenjiO committed Apr 4, 2017
2 parents 16f913e + 3289062 commit 70951b0
Show file tree
Hide file tree
Showing 26 changed files with 1,215 additions and 682 deletions.
11 changes: 6 additions & 5 deletions app/controllers/packing.server.controller.js
Expand Up @@ -8,13 +8,14 @@ const beginWeek = moment.utc().startOf('isoWeek');

export default {
pack: async function(req, res, next) {
const {customerIds, items} = req.body;

const {customers, items} = req.body;
try {
const updatedCustomers = await Promise.all(
customerIds.map(async id =>
Customer.findByIdAndUpdate(id,
{lastPacked: beginWeek}, {new: true})
customers.map(async customer =>
Customer.findByIdAndUpdate(Number(customer.id), {
lastPacked: beginWeek,
packingList: customer.packingList.map(item => item._id)
}, {new: true})
)
);

Expand Down
18 changes: 18 additions & 0 deletions public/modules/common/components/ClientStatusLabel.js
@@ -0,0 +1,18 @@
import React from 'react'

const labelMap = {
'Accepted': 'success',
'Active': 'success',
'Rejected': 'danger',
'Pending': 'info',
'Inactive': 'warning'
}

const ClientStatusLabel = ({client}) =>
<span
className={`label label-${client.driver ? 'info' : labelMap[client.status]}`}
>
{client.driver ? 'Driver' : client.status}
</span>

export default ClientStatusLabel
15 changes: 15 additions & 0 deletions public/modules/common/components/FoodbankLogo.js
@@ -0,0 +1,15 @@
import React from 'react'
import {connect} from 'react-redux'

const mapStateToProps = state => ({
settings: state.settings.data,
media: state.media.data
})

const FoodbankLogo = ({settings, media}) =>
<img
alt={settings && settings.organization}
src={media && media.logoPath + media.logoFile}
/>

export default connect(mapStateToProps)(FoodbankLogo)
2 changes: 1 addition & 1 deletion public/modules/core/components/home.js
Expand Up @@ -4,7 +4,7 @@ import {Provider} from 'react-redux'
import {AppContainer} from 'react-hot-loader'
import angular from 'angular';

import FoodbankLogo from '../../media/components/foodbank-logo'
import FoodbankLogo from '../../common/components/FoodbankLogo'

const Home = () =>
<section className="content-header">
Expand Down
8 changes: 4 additions & 4 deletions public/modules/customer/components/CustomerCreate.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import {connect} from 'react-redux'
import {stateGo} from 'redux-ui-router'
import {fill, get, set, take} from 'lodash'
import set from 'lodash/set'
import {utc} from 'moment'

import {Form} from '../../common/services/form'
Expand All @@ -14,7 +14,7 @@ import {loadSections} from '../../../store/section';
import Page from '../../common/components/Page'
import DynamicForm from '../../common/components/DynamicForm'
import Household from './Household'
import FoodbankLogo from '../../media/components/foodbank-logo'
import FoodbankLogo from '../../common/components/FoodbankLogo'

const mapStateToProps = state => ({
user: state.auth.user,
Expand Down Expand Up @@ -55,15 +55,15 @@ class CustomerCreate extends Component {
componentWillReceiveProps(nextProps) {
const {
savingCustomers,
savingCustomerError,
saveCustomersError,
loadingFormData,
loadFormDataError,
getCustomer
} = nextProps

// Tried to save customer
if (this.props.savingCustomers && !savingCustomers) {
this.setState({error: savingCustomerError})
this.setState({error: saveCustomersError})
}

// Tried to load form data
Expand Down
8 changes: 4 additions & 4 deletions public/modules/customer/components/CustomerCreateSuccess.js
@@ -1,17 +1,17 @@
import React from 'react'
import {connect} from 'react-redux'

import FoodbankLogo from '../../media/components/foodbank-logo'
import FoodbankLogo from '../../common/components/FoodbankLogo'

const mapStateToProps = state => ({
settings: state.settings.data
});

const CustomerCreateSuccess = ({settings}) =>
<section class="row text-center">
<section className="row text-center">
<FoodbankLogo />
<h3 class="col-md-12">Successfully submited. Thank you!</h3>
<a href="/#!/" class="col-md-12">Go to {settings.organization}'s Homepage</a>
<h3 className="col-md-12">Successfully submited. Thank you!</h3>
<a href="/#!/" className="col-md-12">Go to {settings && settings.organization}'s Homepage</a>
</section>

export default connect(mapStateToProps)(CustomerCreateSuccess)
6 changes: 3 additions & 3 deletions public/modules/customer/components/CustomerEdit.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import {connect} from 'react-redux'
import {stateGo} from 'redux-ui-router'
import {get, set} from 'lodash'
import set from 'lodash/set'
import {utc} from 'moment'

import {Form} from '../../common/services/form'
Expand Down Expand Up @@ -59,7 +59,7 @@ class CustomerEdit extends Component {
componentWillReceiveProps(nextProps) {
const {
savingCustomers,
savingCustomerError,
saveCustomersError,
loadingCustomers,
loadCustomersError,
loadingFormData,
Expand All @@ -69,7 +69,7 @@ class CustomerEdit extends Component {

// Tried to save customer
if (this.props.savingCustomers && !savingCustomers) {
this.setState({error: savingCustomerError})
this.setState({error: saveCustomersError})
}

// Tried to load customer
Expand Down
4 changes: 2 additions & 2 deletions public/modules/customer/components/CustomerList.js
Expand Up @@ -5,7 +5,7 @@ import {Table} from 'react-bootstrap'
import {selectors} from '../../../store';
import {loadCustomers} from '../../../store/customer';

import CustomerStatusLabel from './CustomerStatusLabel'
import ClientStatusLabel from '../../common/components/ClientStatusLabel'
import Page from '../../common/components/Page'

const mapStateToProps = state => ({
Expand Down Expand Up @@ -59,7 +59,7 @@ class CustomerList extends Component {
<td><span>{customer.deliveryInstructions}</span></td>
<td><span>{customer.householdSummary}</span></td>
<td><span>{customer.assignedTo && customer.assignedTo.fullName}</span></td>
<td><CustomerStatusLabel customer={customer} /></td>
<td><ClientStatusLabel client={customer} /></td>
<td>
<a
href={`/#!/admin/customers/${customer.id}`}
Expand Down
15 changes: 0 additions & 15 deletions public/modules/customer/components/CustomerStatusLabel.js

This file was deleted.

10 changes: 4 additions & 6 deletions public/modules/customer/components/CustomerView.js
Expand Up @@ -17,8 +17,8 @@ import Page from '../../common/components/Page'

const mapStateToProps = state => ({
user: state.auth.user,
savingCustomer: state.customer.saving,
savingCustomerError: state.customer.saveError,
savingCustomers: selectors.savingCustomers(state),
saveCustomersError: selectors.saveCustomersError(state),
loadingCustomers: selectors.loadingCustomers(state),
loadCustomersError: selectors.loadCustomersError(state),
getCustomer: selectors.getOneCustomer(state),
Expand Down Expand Up @@ -59,18 +59,17 @@ class CustomerView extends Component {
componentWillReceiveProps(nextProps) {
const {
savingCustomers,
savingCustomerError,
saveCustomersError,
loadingCustomers,
loadCustomersError,
loadingFormData,
loadFormDataError,
getCustomer
} = nextProps

// try setstate((prevState, prevProps) => ...)
// Tried to save customer
if (this.props.savingCustomers && !savingCustomers) {
this.setState({error: savingCustomerError})
this.setState({error: saveCustomersError})
}

// Tried to load customer
Expand All @@ -91,7 +90,6 @@ class CustomerView extends Component {
...customer,
foodPreferences: this.getFoodPreferences(customer)
}
// console.log('customerView', View.methods.generate(customerModel, this.formData, 'qClients'))

this.setState({
customerModel,
Expand Down

0 comments on commit 70951b0

Please sign in to comment.