liquid-funding/app/components/FunderProfilesTable.jsx

59 lines
2.1 KiB
React
Raw Normal View History

2019-01-18 17:03:17 +00:00
import React, { Fragment } from 'react'
2018-12-02 13:24:31 +00:00
import MaterialTable from 'material-table'
import LiquidPledging from 'Embark/contracts/LiquidPledging'
2019-01-18 17:03:17 +00:00
import withObservables from '@nozbe/with-observables'
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
import { FundingContext } from '../context'
2018-12-07 14:47:00 +00:00
const { cancelProject } = LiquidPledging.methods
2018-12-02 13:24:31 +00:00
const convertToHours = seconds => seconds / 60 / 60
const cancelText = canceled => canceled ? 'Yes' : 'No'
const formatField = field => ({
2019-01-18 17:03:17 +00:00
...field.getFields(),
2018-12-02 13:24:31 +00:00
commitTime: convertToHours(field.commitTime),
canceled: cancelText(field.canceled)
})
const FunderProfilesTable = ({ profiles }) => (
<FundingContext.Consumer>
{({ account }) =>
<Fragment>
<MaterialTable
columns={[
{ title: 'Profile Id', field: 'idProfile', type: 'numeric' },
{ title: 'Name', field: 'name' },
{ title: 'Url', field: 'url' },
{ title: 'Admin Address', field: 'addr'},
{ title: 'Commit Time', field: 'commitTime', type: 'numeric' },
{ title: 'Type', field: 'type' },
{ title: 'Canceled', field: 'canceled' }
]}
2019-01-18 17:03:17 +00:00
data={profiles.map(formatField)}
title="Funding Profiles"
2019-01-10 19:37:23 +00:00
options={{ showEmptyDataSourceMessage: true }}
actions={[
2019-01-10 19:37:23 +00:00
rowData => ({
icon: 'cancel',
2019-01-18 17:03:17 +00:00
disabled: !account || rowData.addr.toLowerCase() != account.toLowerCase(),
tooltip: 'Cancel',
onClick: (event, rowData) => {
cancelProject(rowData.idProject || rowData.idProfile)
.send()
.then(async res => {
console.log({res})
const profile = profiles.find(p => p.idProfile == rowData.idProfile)
await profile.markAsCanceled()
})
}
})
]}
/>
</Fragment>
}
</FundingContext.Consumer>
2018-12-02 13:24:31 +00:00
)
2019-01-18 17:03:17 +00:00
export default withDatabase(withObservables([], ({ database }) => ({
profiles: database.collections.get('profiles').query().observeWithColumns(['canceled']),
2019-01-18 17:03:17 +00:00
}))(FunderProfilesTable))