|
1 | | -import React from 'react' |
| 1 | +import React, { useEffect } from 'react' |
2 | 2 | import { Flex, Box, Type } from 'blockstack-ui' |
3 | 3 | import { connect } from 'react-redux' |
4 | 4 |
|
| 5 | +import { selectMaker } from '@stores/maker/reducer' |
| 6 | +import { fetchApps } from '@stores/maker/actions' |
5 | 7 | import { selectApiServer, selectUser } from '@stores/apps/selectors' |
6 | 8 | import { Page } from '@components/page' |
7 | 9 | import Head from '@containers/head' |
8 | 10 | import Maker from '@components/maker' |
9 | 11 | import { MakerContainer, MakerContentBox, MakerStickyStatusBox } from '@components/maker/styled' |
10 | 12 |
|
11 | | -class MakerPortal extends React.Component { |
12 | 13 |
|
13 | | - state = { |
14 | | - loading: true, |
15 | | - apps: [], |
16 | | - errorMessage: null, |
17 | | - status: { |
18 | | - paymentDetailsComplete: false, |
19 | | - kycComplete: false, |
20 | | - legalComplete: false |
21 | | - } |
22 | | - } |
23 | | - |
24 | | - componentDidMount() { |
25 | | - this.fetchApps() |
26 | | - } |
27 | | - |
28 | | - async fetchApps() { |
29 | | - const { apiServer, user } = this.props |
30 | | - |
31 | | - if (!(user && user.jwt)) { |
32 | | - this.setState({ |
33 | | - ...this.state, |
34 | | - loading: false, |
35 | | - errorMessage: 'Please sign in to access the maker portal.' |
36 | | - }) |
37 | | - return |
38 | | - } |
39 | | - |
40 | | - const uri = `${apiServer}/api/maker/apps` |
41 | | - const response = await fetch(uri, { |
42 | | - headers: { |
43 | | - Authorization: `Bearer ${user.jwt}` |
44 | | - } |
45 | | - }) |
46 | | - const { apps } = await response.json() |
47 | | - this.setState({ |
48 | | - loading: false, |
49 | | - apps |
50 | | - }) |
51 | | - } |
52 | | - |
53 | | - updateStatus (props) { |
54 | | - this.setState({ ...this.state, status: { ...this.state.status, ...props } }) |
55 | | - } |
56 | | - |
57 | | - setPaymentDetailsComplete () { |
58 | | - this.updateStatus({ paymentDetailsComplete: true }) |
59 | | - } |
60 | | - |
61 | | - setKycComplete () { |
62 | | - this.updateStatus({ kycComplete: true }) |
63 | | - } |
64 | | - |
65 | | - setLegalComplete () { |
66 | | - this.updateStatus({ legalComplete: true }) |
67 | | - } |
| 14 | +const MakerPortal = ({ apiServer, user, maker, loading, errorMessage, dispatch }) => { |
68 | 15 |
|
69 | | - render() { |
70 | | - const { apiServer, user } = this.props |
71 | | - |
72 | | - const { loading, errorMessage, apps } = this.state |
73 | | - const [app] = apps // TODO: this is for now until we handle multiple apps |
74 | | - |
75 | | - if (loading || errorMessage) { |
76 | | - return ( |
77 | | - <Page innerPadding={0} wrap> |
78 | | - <Flex> |
79 | | - <Box width={1}> |
80 | | - <Type fontSize={5} my={7} textAlign="center">{loading ? 'Loading...' : errorMessage}</Type> |
81 | | - </Box> |
82 | | - </Flex> |
83 | | - </Page> |
84 | | - ) |
85 | | - } |
| 16 | + useEffect(() => { |
| 17 | + fetchApps({ apiServer, user })(dispatch) |
| 18 | + }, []) |
86 | 19 |
|
| 20 | + const app = maker.appEntities[maker.appIds[0]] |
| 21 | + if (loading || !app) { |
87 | 22 | return ( |
88 | 23 | <Page innerPadding={0} wrap> |
89 | | - <Head title={app.name} /> |
90 | | - <MakerContainer> |
91 | | - <Type fontSize={3} fontWeight={500} mx={[4, 6]} py={6} px={[20, 0]}> |
92 | | - {app.name} |
93 | | - </Type> |
94 | | - <Flex flexDirection={['column', 'column', 'row-reverse']} maxWidth={[null, null, 1140]} alignItems="flex-start"> |
95 | | - <MakerStickyStatusBox> |
96 | | - <Maker.Status |
97 | | - app={app} |
98 | | - apiServer={apiServer} |
99 | | - status={this.state.status} |
100 | | - /> |
101 | | - </MakerStickyStatusBox> |
102 | | - <Box> |
103 | | - <MakerContentBox> |
104 | | - <Maker.PaymentDetails |
105 | | - app={app} |
106 | | - user={user} |
107 | | - apiServer={apiServer} |
108 | | - onPaymentDetailsComplete={() => this.setPaymentDetailsComplete()} |
109 | | - /> |
110 | | - </MakerContentBox> |
111 | | - <MakerContentBox> |
112 | | - <Maker.KYC |
113 | | - app={app} |
114 | | - user={user} |
115 | | - apiServer={apiServer} |
116 | | - onKycComplete={() => this.setKycComplete()} |
117 | | - /> |
118 | | - </MakerContentBox> |
119 | | - <MakerContentBox> |
120 | | - <Maker.ParticipationAgreement |
121 | | - app={app} |
122 | | - user={user} |
123 | | - apiServer={apiServer} |
124 | | - onLegalComplete={() => this.setLegalComplete()} |
125 | | - /> |
126 | | - </MakerContentBox> |
127 | | - </Box> |
128 | | - </Flex> |
129 | | - </MakerContainer> |
| 24 | + <Flex> |
| 25 | + <Box width={1}> |
| 26 | + <Type fontSize={5} my={7} textAlign="center">{loading ? 'Loading...' : errorMessage}</Type> |
| 27 | + </Box> |
| 28 | + </Flex> |
130 | 29 | </Page> |
131 | 30 | ) |
132 | 31 | } |
| 32 | + console.log(app) |
| 33 | + return ( |
| 34 | + <Page innerPadding={0} wrap> |
| 35 | + <Head title={app.name} /> |
| 36 | + <MakerContainer> |
| 37 | + <Type fontSize={3} fontWeight={500} mx={[4, 6]} py={6} px={[20, 0]}> |
| 38 | + {app.name} |
| 39 | + </Type> |
| 40 | + <Flex flexDirection={['column', 'column', 'row-reverse']} maxWidth={[null, null, 1140]} alignItems="flex-start"> |
| 41 | + <MakerStickyStatusBox> |
| 42 | + <Maker.Status |
| 43 | + app={app} |
| 44 | + apiServer={apiServer} |
| 45 | + status={maker.status} |
| 46 | + /> |
| 47 | + </MakerStickyStatusBox> |
| 48 | + <Box> |
| 49 | + <MakerContentBox> |
| 50 | + <Maker.PaymentDetails |
| 51 | + app={app} |
| 52 | + user={user} |
| 53 | + apiServer={apiServer} |
| 54 | + dispatch={dispatch} |
| 55 | + // onPaymentDetailsComplete={() => dispatch(setPaymentDetailsComplete())} |
| 56 | + /> |
| 57 | + </MakerContentBox> |
| 58 | + <MakerContentBox> |
| 59 | + <Maker.KYC |
| 60 | + app={app} |
| 61 | + user={user} |
| 62 | + apiServer={apiServer} |
| 63 | + // onKycComplete={() => dispatch(setKycComplete())} |
| 64 | + /> |
| 65 | + </MakerContentBox> |
| 66 | + <MakerContentBox> |
| 67 | + <Maker.ParticipationAgreement |
| 68 | + app={app} |
| 69 | + user={user} |
| 70 | + apiServer={apiServer} |
| 71 | + // onLegalComplete={() => dispatch(setLegalComplete())} |
| 72 | + /> |
| 73 | + </MakerContentBox> |
| 74 | + </Box> |
| 75 | + </Flex> |
| 76 | + </MakerContainer> |
| 77 | + </Page> |
| 78 | + ) |
133 | 79 | } |
134 | 80 |
|
135 | 81 | const mapStateToProps = (state) => ({ |
136 | 82 | user: selectUser(state), |
137 | | - apiServer: selectApiServer(state) |
| 83 | + apiServer: selectApiServer(state), |
| 84 | + maker: selectMaker(state) |
138 | 85 | }) |
139 | 86 |
|
140 | 87 | export default connect(mapStateToProps)(MakerPortal) |
0 commit comments