This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John O'Malley
committed
Oct 23, 2016
1 parent
11ff2bd
commit f8d36d2
Showing
19 changed files
with
301 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
[ | ||
{ | ||
"name": "alice" | ||
"_id": "city-seeds", | ||
"name": "City Seeds", | ||
"type": "training", | ||
"location": "St. Patrick's Center" | ||
}, | ||
{ | ||
"name": "bob" | ||
"_id": "mcmurphys", | ||
"name": "McMurphy’s Cafe", | ||
"type": "training", | ||
"location": "St. Patrick's Center" | ||
}, | ||
{ | ||
"_id": "homeless-employment", | ||
"name": "Homeless Employment", | ||
"type": "training", | ||
"location": "St. Patrick's Center" | ||
}, | ||
{ | ||
"_id": "labre-center", | ||
"name": "Labre Center", | ||
"type": "training", | ||
"location": "Peter and Paul" | ||
}, | ||
{ | ||
"_id": "community-collaborative", | ||
"name": "Community CollabARTive", | ||
"type": "training", | ||
"location": "Peter and Paul" | ||
}, | ||
{ | ||
"_id": "skills-4-success", | ||
"name": "Skills 4 Success", | ||
"type": "training", | ||
"location": "Gateway 180" | ||
}, | ||
{ | ||
"_id": "twice-blessed", | ||
"name": "Twice Blessed", | ||
"type": "training", | ||
"location": "Our Lady's Inn" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const agent = require('../../src/agent') | ||
const { couchUrl } = require('../config') | ||
const mango = require('../mango') | ||
|
||
const db = 'programs' | ||
|
||
const findByType = (type) => | ||
mango(db, { selector: { type } }) | ||
|
||
const findAll = () => | ||
agent.get(`${couchUrl}/${db}/_all_docs?include_docs=true`) | ||
.then(({ body: { rows } }) => rows.filter(row => row.id[0] !== '_').map(({ doc }) => doc)) | ||
|
||
module.exports = (type) => type ? findByType(type) : findAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const findPrograms = require('./findPrograms') | ||
|
||
module.exports = ({ query: { type } }, res, next) => | ||
findPrograms(type) | ||
.then(programs => res.json(programs)) | ||
.catch(next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const express = require('express') | ||
const router = express.Router() | ||
|
||
router.get('/', require('./getPrograms')) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const _ = require('underscore') | ||
const findPrograms = require('./findPrograms') | ||
|
||
module.exports = (req, res, next) => | ||
findPrograms() | ||
.then( | ||
programs => res.json(_(programs).chain().map(p => [p.type, true]).object().keys().compact().value()) | ||
) | ||
.catch(next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar' | ||
import ButtonGroup from 'react-bootstrap/lib/ButtonGroup' | ||
|
||
const Toolbar = ({ children }) => { | ||
let key = 0 | ||
return ( | ||
<ButtonToolbar> | ||
{[].concat(children).map(child => ( | ||
<ButtonGroup key={key++}> | ||
{child} | ||
</ButtonGroup> | ||
))} | ||
</ButtonToolbar> | ||
) | ||
} | ||
|
||
Toolbar.displayName = 'Toolbar' | ||
|
||
export default Toolbar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react' | ||
import agent from '../agent' | ||
import { Link } from 'react-router' | ||
import Button from 'react-bootstrap/lib/Button' | ||
import Alert from 'react-bootstrap/lib/Alert' | ||
import ReferralTable from './ReferralTable' | ||
import Toolbar from '../Toolbar' | ||
import FadeIn from '../FadeIn' | ||
|
||
export default class ReferClient extends React.Component { | ||
update(params = this.props.params) { | ||
Promise.all([ | ||
agent.get(`/services/clients/${encodeURIComponent(params.clientId)}`).then(({ body }) => body), | ||
agent.get('/services/programs').then(({ body }) => body) | ||
]) | ||
.then(([client, programs]) => this.setState({ client, programs })) | ||
} | ||
|
||
componentWillReceiveProps({ params }) { | ||
this.update(params) | ||
} | ||
|
||
componentWillMount() { | ||
this.update() | ||
} | ||
|
||
render() { | ||
const { client, programs, selectedId, result } = this.state || {} | ||
const { clientId, shelterId } = this.props.params | ||
const clientName = client && `${client.first_name} ${client.last_name} ` | ||
|
||
const setResult = (result) => this.setState({ result }) | ||
|
||
const onSend = () => | ||
agent.patch(`/services/clients/${encodeURIComponent(clientId)}/tags`) | ||
.send({ | ||
add: [selectedId] | ||
}) | ||
.then(({ body }) => setResult(body)) | ||
.catch(e => setResult({ error: e.message || e.toString() })) | ||
|
||
const cancelButton = (label = 'Cancel', bsStyle = 'default') => ( | ||
<Link to={`/admin/${encodeURIComponent(shelterId)}`} className={`btn btn-${bsStyle}`}> | ||
{label} | ||
</Link> | ||
) | ||
|
||
const renderResult = () => | ||
result.ok ? ( | ||
<FadeIn className='check-in'> | ||
<Alert bsStyle="success"> | ||
<strong>Success</strong> | ||
{' Referral was sent successfully for client '} | ||
{clientName} | ||
{'.'} | ||
</Alert> | ||
<Toolbar> | ||
{cancelButton('Done', 'primary')} | ||
</Toolbar> | ||
</FadeIn> | ||
) : ( | ||
<FadeIn className='check-in'> | ||
<Alert bsStyle="danger"> | ||
<strong>Referral Failed</strong> | ||
{' '} | ||
{result.error || 'unknown error'} | ||
</Alert> | ||
<Toolbar> | ||
<Button bsStyle='primary' onClick={() => this.setState({ result: undefined })}>Try Again</Button> | ||
{cancelButton()} | ||
</Toolbar> | ||
</FadeIn> | ||
) | ||
|
||
if (result) { | ||
return renderResult() | ||
} else if (client && programs) { | ||
return ( | ||
<div className='refer-client'> | ||
<h2> | ||
{`${client.first_name} ${client.last_name} `} | ||
<small> | ||
refer client | ||
</small> | ||
</h2> | ||
<hr/> | ||
<h4>Select a program below</h4> | ||
<Toolbar> | ||
<Button bsStyle='primary' disabled={!selectedId} onClick={onSend}> | ||
Send Referral | ||
</Button> | ||
<Link to={`/admin/${shelterId}`} className='btn btn-default'> | ||
Cancel | ||
</Link> | ||
</Toolbar> | ||
<hr/> | ||
<ReferralTable programs={programs} selectedId={selectedId} | ||
onSelected={selectedId => this.setState({ selectedId })}/> | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<div className='spinner'/> | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
const RefferalHeader = () => ( | ||
<thead> | ||
<tr> | ||
<th>Select</th> | ||
<th>Program Name</th> | ||
<th>Program Location</th> | ||
<th>Program Type</th> | ||
</tr> | ||
</thead> | ||
) | ||
|
||
RefferalHeader.displayName = 'RefferalHeader' | ||
|
||
export default RefferalHeader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import Radio from 'react-bootstrap/lib/Radio' | ||
import programTypes from './programTypes' | ||
|
||
const ReferralRow = ({ selected, program: { _id, name, type, location }, onSelected }) => ( | ||
<tr className={selected ? 'selected' : ''}> | ||
<td> | ||
<Radio checked={selected} onChange={() => onSelected(_id)}/> | ||
</td> | ||
<td>{name}</td> | ||
<td>{location}</td> | ||
<td>{programTypes[type] || type}</td> | ||
</tr> | ||
) | ||
|
||
ReferralRow.displayName = 'ReferralRow' | ||
|
||
export default ReferralRow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import Table from 'react-bootstrap/lib/Table' | ||
import RefferalHeader from './ReferralHeader' | ||
import ReferralRow from './ReferralRow' | ||
|
||
const ReferralTable = ({programs, selectedId, onSelected}) => ( | ||
<Table striped bordered> | ||
<RefferalHeader/> | ||
<tbody> | ||
{programs.map(program => ( | ||
<ReferralRow key={program._id} program={program} selected={program._id === selectedId} | ||
onSelected={onSelected}/> | ||
)) | ||
} | ||
</tbody> | ||
</Table> | ||
) | ||
|
||
export default ReferralTable |
Oops, something went wrong.