-
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
Lochana Jayawickrama
authored and
Lochana Jayawickrama
committed
Aug 3, 2018
1 parent
dfbf76c
commit 5bb1c02
Showing
18 changed files
with
2,434 additions
and
483 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`header test 1`] = ` | ||
<header> | ||
<h1> | ||
Epensify | ||
</h1> | ||
r | ||
<NavLink | ||
activeClassName="is-active" | ||
aria-current="page" | ||
exact={true} | ||
to="/" | ||
> | ||
Dashboard | ||
</NavLink> | ||
<NavLink | ||
activeClassName="is-active" | ||
aria-current="page" | ||
exact={true} | ||
to="/create" | ||
> | ||
Create Expense | ||
</NavLink> | ||
<NavLink | ||
activeClassName="is-active" | ||
aria-current="page" | ||
exact={true} | ||
to="/help" | ||
> | ||
Help | ||
</NavLink> | ||
</header> | ||
`; |
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,7 +1,18 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import ExpenseForm from './ExpenseForm'; | ||
import {addExpense} from '../actions/expenses'; | ||
|
||
const AddExpensePage = () => ( | ||
<div>AddExpense</div> | ||
const AddExpensePage = (props) => ( | ||
<div> | ||
<h1>Add Expense</h1> | ||
<ExpenseForm | ||
onSubmit={(expense)=>{ | ||
props.dispatch(addExpense(expense)); | ||
props.history.push('/'); | ||
}} | ||
/> | ||
</div> | ||
); | ||
|
||
export default AddExpensePage; | ||
export default connect()(AddExpensePage); |
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,10 +1,30 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import ExpenseForm from './ExpenseForm'; | ||
import {editExpense, removeExpense} from '../actions/expenses'; | ||
|
||
const EditExpensePage = (props) =>{ | ||
const EditExpensePage = (props) => { | ||
console.log(props) | ||
return( | ||
<div>EditExpense of {props.match.params.id}</div> | ||
return ( | ||
<div> | ||
<ExpenseForm | ||
expense={props.expense} | ||
onSubmit={(expense) => { | ||
props.dispatch(editExpense(props.expense.id,expense)); | ||
props.history.push('/'); | ||
}} | ||
/> | ||
<button onClick={()=>{ | ||
props.dispatch(removeExpense({id:props.expense.id})); | ||
props.history.push('/'); | ||
}}>Remove</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditExpensePage; | ||
const mapStateToProps = (state, props) => { | ||
return { | ||
expense: state.expenses.find((expense) => expense.id === props.match.params.id) | ||
}; | ||
}; | ||
export default connect(mapStateToProps)(EditExpensePage); |
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,94 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
import { SingleDatePicker } from 'react-dates'; | ||
import 'react-dates/lib/css/_datepicker.css'; | ||
import 'react-dates/initialize'; | ||
|
||
export default class ExpenseForm extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
this.state={ | ||
description: props.expense ? props.expense.description : '', | ||
note: props.expense ? props.expense.note : '', | ||
amount: props.expense ? (props.expense.amount / 100).toString() : '', | ||
createdAt: props.expense ? moment(props.expense.createdAt) : moment(), | ||
calendarFocused: false, | ||
error: '' | ||
}; | ||
} | ||
|
||
onDescriptionChange = (e) => { | ||
const description = e.target.value; | ||
this.setState(() => ({ description })); | ||
}; | ||
onNoteChange = (e) => { | ||
const note = e.target.value; | ||
this.setState(() => ({ note })); | ||
}; | ||
onAmountChange = (e) => { | ||
const amount = e.target.value; | ||
|
||
if (!amount || amount.match(/^\d{1,}(\.\d{0,2})?$/)) { | ||
this.setState(() => ({ amount })); | ||
} | ||
}; | ||
onDateChange = (createdAt) => { | ||
if(createdAt){ | ||
this.setState(() => ({ createdAt })); | ||
} | ||
}; | ||
onFocusChange = ({ focused }) => { | ||
this.setState(() => ({ calendarFocused: focused })); | ||
}; | ||
onSubmit=(e)=>{ | ||
e.preventDefault(); | ||
if (!this.state.description|| !this.state.amount){ | ||
this.setState(()=>({error:'Please provide description and amount'})); | ||
}else{ | ||
this.setState(()=>({error:''})); | ||
this.props.onSubmit({ | ||
description:this.state.description, | ||
amount: parseFloat(this.state.amount,10)*100, | ||
createdAt:this.state.createdAt.valueOf(), | ||
note:this.state.note | ||
}); | ||
} | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
{this.state.error && <p>{this.state.error}</p>} | ||
<form onSubmit={this.onSubmit}> | ||
<input | ||
type="text" | ||
placeholder="Description" | ||
autoFocus | ||
value={this.state.description} | ||
onChange={this.onDescriptionChange} | ||
/> | ||
<input | ||
type="text" | ||
placeholder="Amount" | ||
value={this.state.amount} | ||
onChange={this.onAmountChange} | ||
/> | ||
<SingleDatePicker | ||
date={this.state.createdAt} | ||
onDateChange={this.onDateChange} | ||
focused={this.state.calendarFocused} | ||
onFocusChange={this.onFocusChange} | ||
numberOfMonths={1} | ||
isOutsideRange={() => false} | ||
/> | ||
<textarea | ||
placeholder="Add a note for your expense (optional)" | ||
value={this.state.note} | ||
onChange={this.onNoteChange} | ||
> | ||
</textarea> | ||
<button>Add Expense</button> | ||
</form> | ||
</div> | ||
) | ||
} | ||
} |
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,61 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { DateRangePicker } from 'react-dates'; | ||
import { setTextFilter, sortByDate, sortByAmount, setStartDate, setEndDate } from '../actions/filters'; | ||
|
||
class ExpenseListFilters extends React.Component { | ||
state = { | ||
calendarFocused: null | ||
}; | ||
onDatesChange = ({ startDate, endDate }) => { | ||
this.props.dispatch(setStartDate(startDate)); | ||
this.props.dispatch(setEndDate(endDate)); | ||
}; | ||
onFocusChange = (calendarFocused) => { | ||
this.setState(() => ({ calendarFocused })); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
value={this.props.filters.text} | ||
onChange={(e) => { | ||
this.props.dispatch(setTextFilter(e.target.value)); | ||
}} | ||
/> | ||
<select | ||
value={this.props.filters.sortBy} | ||
onChange={(e) => { | ||
if (e.target.value === 'date') { | ||
this.props.dispatch(sortByDate()); | ||
} else if (e.target.value === 'amount') { | ||
this.props.dispatch(sortByAmount()); | ||
} | ||
}} | ||
> | ||
<option value="date">Date</option> | ||
<option value="amount">Amount</option> | ||
</select> | ||
<DateRangePicker | ||
startDate={this.props.filters.startDate} | ||
endDate={this.props.filters.endDate} | ||
onDatesChange={this.onDatesChange} | ||
focusedInput={this.state.calendarFocused} | ||
onFocusChange={this.onFocusChange} | ||
showClearDates={true} | ||
numberOfMonths={1} | ||
isOutsideRange={() => false} | ||
/> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
filters: state.filters | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(ExpenseListFilters); |
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
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
Oops, something went wrong.