Skip to content

Commit

Permalink
feat: send transfer bounty from the author transfer sent tab
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanmtz committed Feb 28, 2024
1 parent 8d75a51 commit 8287cb0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 30 deletions.
76 changes: 49 additions & 27 deletions frontend/src/components/profile/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,53 @@ const Transfers = ({ searchTransfer, updateTransfer, transfers, user, intl, hist
getTranfers().then(t => console.log('transfers:', t))
}, [user])

const transferActions = (t) => {
if(!user.account_id && t.status !== 'pending') return null
switch(value) {
case 'from':
return (user.account_id && t.status === 'pending') ?
(<Button
size='small'
onClick={ async () => {
await updateTransfer({ id: t.id })
await searchTransfer({ userId: user.id })
} }
variant='contained'
color='secondary'
>
<FormattedMessage id='transfers.button.cancel' defaultMessage='Send bounty' />
</Button>
) : null
case 'to':
return ( user.account_id && t.status === 'pending') ?
<Button
size='small'
onClick={ async () => {
await updateTransfer({ id: t.id })
await searchTransfer({ to: user.id })
} }
variant='contained'
color='secondary'
disabled={ t.status !== 'pending'}
>
<FormattedMessage id='transfers.action.payout.button' defaultMessage='Request payout' />
</Button>
:
!user.account_id && <Button
size='small'
onClick={ () => {
history.push('/profile/user-account/details')
} }
variant='contained'
color='secondary'
>
<FormattedMessage id='transfers.alert.button' defaultMessage='Update your account' />
</Button>
default:
return null
}
}

return (
<div style={ { margin: '40px 0' } }>
<Container>
Expand Down Expand Up @@ -126,33 +173,8 @@ const Transfers = ({ searchTransfer, updateTransfer, transfers, user, intl, hist
<a href={ `/#/task/${t.Task.id}/${slugify(t.Task.title)}` }>
{ t.Task.title }
</a>,
value === 'to' && (
(user.account_id && t.status === 'pending') ?
<Button
size='small'
onClick={ async () => {
await updateTransfer({ id: t.id })
await searchTransfer({ to: user.id })
} }
variant='contained'
color='secondary'
disabled={ t.status !== 'pending'}
>
<FormattedMessage id='transfers.action.payout.button' defaultMessage='Request payout' />
</Button>
:
!user.account_id && <Button
size='small'
onClick={ () => {
history.push('/profile/user-account/details')
} }
variant='contained'
color='secondary'
>
<FormattedMessage id='transfers.alert.button' defaultMessage='Update your account' />
</Button>
)]) } || {}
}
transferActions(t)
]) } || {}}
/>
</div>
</Container>
Expand Down
6 changes: 3 additions & 3 deletions modules/transfers/transferUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ module.exports = Promise.method(async function transferUpdate(params) {
returning: true

})
const { Task: task, User: user } = existingTransfer
const { value, Task: task, User: user } = existingTransfer
if (!updateTask || !updateTransfer) {
TransferMail.error(user, task, task.value)
return { error: 'update_task_reject' }
}
const taskOwner = await models.User.findByPk(task.userId)
TransferMail.notifyOwner(taskOwner.dataValues, task, task.value)
TransferMail.success(user, task, task.value)
TransferMail.notifyOwner(taskOwner.dataValues, task, value)
TransferMail.success(user, task, value)
return updateTransfer[1][0].dataValues
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/transfer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ describe("Transfer", () => {
.persist()
.post('/v1/transfers')
.reply(200, transfer );
nock('https://api.stripe.com')
.persist()
.get('/v1/transfers')
.reply(200, transfer );
const task = await createTask(agent);
const taskData = task.dataValues;
const order = await createOrder({userId: taskData.userId, TaskId: taskData.id, paid: true, provider: 'stripe'});
Expand Down

0 comments on commit 8287cb0

Please sign in to comment.