Skip to content

Commit 2a64966

Browse files
payments list
1 parent 07f71c8 commit 2a64966

File tree

10 files changed

+84
-4
lines changed

10 files changed

+84
-4
lines changed

api/schema/resolvers/PaymentResolver.js

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ module.exports = {
4141
if (payment.external_uuid && payment.external_uuid_type === 'bitcoin') {
4242
return apiModules.paymentManagement.getBitcoinCheckoutUrl(payment.external_uuid)
4343
}
44+
},
45+
contributor: (payment, args, { models }) => {
46+
return models.Contributor.findOne({
47+
where: {
48+
id: payment.contributor_id
49+
}
50+
})
4451
}
4552
},
4653
Query: {

api/schema/resolvers/ProjectResolver.js

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ module.exports = {
4747
]
4848
})
4949
},
50+
payments: (project, args, { models }) => {
51+
return models.Payment.findAll({
52+
where: {
53+
project_id: project.id
54+
}
55+
})
56+
},
5057
averageHourlyPaid: async (project, args, { models }) => {
5158
validateDatesFormat({
5259
fromDate: args.fromDate,

api/schema/types/PaymentType.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = gql`
1818
allocations: [Allocation]
1919
isBitcoinInvoiceExpired: Boolean
2020
bitcoinCheckoutUrl: String
21+
contributor: Contributor
2122
}
2223
2324

api/schema/types/ProjectType.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = gql`
1919
expected_budget_currency: String
2020
allocations(contributorId: Int): [Allocation]
2121
allocatedPayments: [Payment]
22+
payments: [Payment]
2223
averageHourlyPaid(fromDate: String, toDate: String): Int
2324
averageIssueCost(fromDate: String, toDate: String): AverageIssueCost
2425
client: Client

srcv2/operations/mutations/PaymentMutations.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { gql } from '@apollo/client'
22

33
export const CREATE_PAYMENT = gql`
4-
mutation CreatePayment($project_id: Int!, $amount: Int!, $date_incurred: String!, $date_paid: String, $currency: String) {
4+
mutation CreatePayment($project_id: Int!, $amount: Int!, $date_incurred: String!, $date_paid: String, $currency: String, $contributor_id: Int) {
55
createPayment(createFields: {
66
amount: $amount
77
project_id: $project_id
88
date_incurred: $date_incurred
99
date_paid: $date_paid
1010
currency: $currency
11+
contributor_id: $contributor_id
1112
}){
1213
id
1314
amount

srcv2/operations/queries/ProjectQueries.js

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export const GET_PROJECT = gql`
3939
name
4040
}
4141
}
42+
payments {
43+
id
44+
amount
45+
currency
46+
contributor {
47+
id
48+
name
49+
github_handle
50+
}
51+
}
4252
}
4353
}
4454
`

srcv2/pages/AddPaymentPage.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { selectCurrencyInformation } from '../scripts/selectors'
1616
import { GET_PROJECT } from '../operations/queries/ProjectQueries'
1717
import { CREATE_PAYMENT } from '../operations/mutations/PaymentMutations'
1818

19+
import { sessionUser } from '../reactivities/variables'
20+
1921
const AddPaymentPage = () => {
2022

2123
const { projectId } = useParams()
@@ -63,7 +65,8 @@ const AddPaymentPage = () => {
6365
project_id: Number(projectId),
6466
date_incurred: paymentIncurred,
6567
date_paid: paymentPaid,
66-
currency: project.expected_budget_currency
68+
currency: project.expected_budget_currency,
69+
contributor_id: sessionUser().id
6770
}
6871
const newPayment = await createPayment({ variables })
6972
if (loadingNewPayment) return 'Loading...'

srcv2/pages/DashboardPage.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Section from '../components/Section'
1010

1111
import { sessionUser } from '../reactivities/variables'
1212

13+
import { getHandle } from '../scripts/selectors'
14+
1315
const DashboardPage = () => {
1416

1517
const walletSetupPrototypeLink = 'https://www.figma.com/proto/qgGWXmprU7vTv7guzWzvML/Project-Trinary?node-id=4561%3A17974&scaling=scale-down&page-id=4076%3A12706&starting-point-node-id=4552%3A15225&show-proto-sidebar=1'
@@ -19,7 +21,7 @@ const DashboardPage = () => {
1921
<Section backgroundColor={'bg-white'} className={'rounded-b-[70px]'}>
2022
<div className='grid grid-flow-row auto-rows-max gap-8'>
2123
<p className='text-2xl text-left font-bold'>
22-
{`Welcome, @${sessionUser().github_handle.split('/').pop()}`}
24+
{`Welcome, @${getHandle(sessionUser().github_handle)}`}
2325
</p>
2426
<div className={`${sessionUser().totalPaid ? 'bg-setlife px-8' : 'bg-white'} rounded grid grid-flow-row auto-rows-max gap-2 py-4`}>
2527
{!!sessionUser().totalPaid &&

srcv2/pages/ProjectDetailPage.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Section from '../components/Section'
1010

1111
import { GET_PROJECT } from '../operations/queries/ProjectQueries'
1212

13+
import { getHandle, selectCurrencyInformation } from '../scripts/selectors'
14+
1315
const ProjectDetailPage = (props) => {
1416

1517
const { projectId } = useParams()
@@ -31,6 +33,9 @@ const ProjectDetailPage = (props) => {
3133

3234
const project = dataProject.getProjectById
3335

36+
console.log('project')
37+
console.log(project)
38+
3439
const renderContributors = (contributors) => {
3540
return contributors.map(contributor => {
3641
return (
@@ -46,6 +51,37 @@ const ProjectDetailPage = (props) => {
4651
})
4752
}
4853

54+
const renderPayments = (payments) => {
55+
return payments.map(payment => {
56+
return (
57+
<div className='payment bg-white-light rounded-lg p-4 grid grid-flow-row auto-rows-max'>
58+
<div className='flex grid grid-cols-2 gap-4 '>
59+
<div className='text-left'>
60+
{payment.contributor &&
61+
<>
62+
<p className='text-xl font-bold'>
63+
{payment.contributor.name}
64+
</p>
65+
<p>
66+
{`@${getHandle(payment.contributor.github_handle)}`}
67+
</p>
68+
</>
69+
}
70+
</div>
71+
<div>
72+
<p className='text-xl font-bold text-right'>
73+
{`${selectCurrencyInformation({ currency: payment.currency }).symbol} ${payment.amount}`}
74+
</p>
75+
</div>
76+
</div>
77+
<button type='button' className='text-right w-fit ml-auto' onClick={() => history.push(`/payments/edit/${payment.id}`)}>
78+
<Icon className='fas fa-pen text-grey' fontSize='small'/>
79+
</button>
80+
</div>
81+
)
82+
})
83+
}
84+
4985
return (
5086
<div className='ProjectDetailPage mb-10'>
5187
<button type='button' className='w-fit' onClick={() => history.push('/dashboard')}>
@@ -140,7 +176,7 @@ const ProjectDetailPage = (props) => {
140176
</div>
141177
</Section>
142178
<Section>
143-
<p className='font-bold text-xl mb-4'>
179+
<p className='font-bold text-xl mb-2'>
144180
Issues
145181
</p>
146182
<div className='rounded-lg bg-white-light p-4'>
@@ -184,6 +220,14 @@ const ProjectDetailPage = (props) => {
184220
</div>
185221
</Section>
186222
<OpenInGithubButton url={`${project.github_url}/pulls`}/>
223+
<Section>
224+
<p className='font-bold text-xl mb-2'>
225+
Payments
226+
</p>
227+
<div className='grid gap-4'>
228+
{renderPayments(project.payments)}
229+
</div>
230+
</Section>
187231
<CreatePaymentFloatingBadge projectId={projectId} />
188232
</div>
189233
)

srcv2/scripts/selectors.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { CURRENCIES } from '../constants'
22

3+
export const getHandle = (url) => {
4+
return url.split('/').pop()
5+
}
6+
37
export const selectCurrencyInformation = (props) => {
48
return CURRENCIES.find(c => c.name == props.currency)
59
}

0 commit comments

Comments
 (0)