Skip to content

Commit

Permalink
Payment Viewer Frontend page
Browse files Browse the repository at this point in the history
  • Loading branch information
GBS-Skile committed Jun 19, 2019
1 parent 3c2cab1 commit 270e944
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const App = () => {
<Route path="/user/setting/" component={UserInfoPage} exact />
<Route path="/user/create_room/" component={RoomCreatePage} exact />
<Route path="/user/:room_id/entrance/" component={EntrancePage} />
<Route path="/room/:room_id/payment/" component={PaymentPage} />
<Route path="/room/:room_id/payment/" component={PaymentPage} exact />
<Route path="/room/:room_id/payment/:payment_id/" component={PaymentPage} exact />
<Route path="/room/:room_id/setting/" component={RoomSettingPage} />
<Route path="/room/:room_id/member/:member/" component={IndividualPage} exact />
<Route path="/room/:room_id/member/:member/:to" component={AccountPage} />
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/atoms/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const Button = styled.button`
width: 100%;
max-width: 224px;
z-index: 1;
:disabled {
background-color: lightgrey;
color: grey;
cursor: none;
}
`

const LightButton = styled(Button)`
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/atoms/Graph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const Wrapper = styled.div`
padding-top: 100%;
width: 100%;
position: relative;
z-index: -1;
`

const Content = styled.div`
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/organisms/PaymentForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const Credit = ({ member: {membername}, index, ...props }) => (
/>
)

const PaymentForm = ({ handleSubmit, room, members, payment, amountLeft, total, nBbang, ...props }) => {
const PaymentForm = ({ handleSubmit, room, members, payment, amountLeft, total, nBbang, ...rest }) => {
const { disabled } = rest
return (
<Form onSubmit={handleSubmit}>
<Block>
Expand Down Expand Up @@ -78,7 +79,7 @@ const PaymentForm = ({ handleSubmit, room, members, payment, amountLeft, total,
>
취소
</LinkButton>
<Button type="submit" horizontal>확인</Button>
<Button type="submit" horizontal disabled={disabled}>확인</Button>
</Block>
</Form>
)
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/organisms/PaymentList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ const PaymentList = ({ paymentlist, roomurl }) => (
<List>
{
paymentlist && paymentlist.map(
({ forWhat, fromWho, total }, idx) => (
<ListItem key={idx} title={`${forWhat}${fromWho}`} description={total} linkTo={`/room/${roomurl}/payment_list/${forWhat}`} />
({ id, forWhat, fromWho, total }, idx) => (
<ListItem key={idx}
title={`${forWhat} - ${fromWho}`}
description={total}
linkTo={`/room/${roomurl}/payment/${id}/`}
/>
)
)
}
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/containers/PaymentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,25 @@ const mapDispatchToProps = dispatch => ({
}
})

const PaymentFormContainer = ({...props}) => {
const initialValues = {
credits: props.members.map(
({ membername }) => ({ toWho: membername, amount: 0.0 })
),
room: props.room,
}
const PaymentFormContainer = ({payment, ...props}) => {
const initialValues = (payment ?
{ // if payment exists
...payment,
room: props.room,
} :
{ // if payment doesn't exist
credits: props.members.map(
({ membername }) => ({ toWho: membername, amount: 0.0 })
),
room: props.room,
}
)

console.log(initialValues)

return (
<PaymentReduxForm
disabled={!!payment}
initialValues={initialValues}
{...props}
/>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/containers/PaymentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { connect } from 'react-redux'

import { PaymentPage } from 'components'

const PaymentPageContainer = props => {
return <PaymentPage {...props} />
const PaymentPageContainer = ({ match, payments, ...props }) => {
const paymentId = parseInt(match.params.payment_id)
const payment = payments.find(p => p.id === paymentId)
return <PaymentPage payment={payment} {...props} />
}

const mapStateToProps = state => ({
room: state.room.room,
members: state.member.members,
payment: state.payment.payment,
payments: state.payment.payments,
})

export default connect(mapStateToProps)(PaymentPageContainer)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const req = require.context('.', true, /\.\/.+\/sagas\.js$/)
const sagas = req.keys().map(key => req(key).default)

sagas.push(function* () {
yield takeEvery(a => a.error, function* ({ type, error }) {
yield takeEvery(a => a.error && a.type[0] !== '@', function* ({ type, error }) {
toastError(type, JSON.stringify(error))
})
})
Expand Down

0 comments on commit 270e944

Please sign in to comment.