Skip to content

Commit 35db9d1

Browse files
committed
Basic functionality for payments segment is ready
1 parent c6236aa commit 35db9d1

File tree

6 files changed

+86
-13
lines changed

6 files changed

+86
-13
lines changed

.exchange-rates.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"disclaimer":"Usage subject to terms: https://openexchangerates.org/terms","license":"https://openexchangerates.org/license","timestamp":1508320800,"base":"USD","rates":{"AED":3.673018,"AFN":68.128,"ALL":113.77,"AMD":480.465,"ANG":1.7834,"AOA":165.9225,"ARS":17.336766,"AUD":1.278672,"AWG":1.790501,"AZN":1.689,"BAM":1.6616,"BBD":2,"BDT":82.351,"BGN":1.665518,"BHD":0.377085,"BIF":1752.55,"BMD":1,"BND":1.357196,"BOB":6.903811,"BRL":3.1579,"BSD":1,"BTC":0.000186473497,"BTN":64.935987,"BWP":10.273488,"BYN":1.958245,"BZD":2.014074,"CAD":1.253285,"CDF":1562.881563,"CHF":0.981081,"CLF":0.023185,"CLP":622.423602,"CNH":6.624705,"CNY":6.62395,"COP":2949.33,"CRC":570.455,"CUC":1,"CUP":25.5,"CVE":93.95,"CZK":21.89831,"DJF":178.77,"DKK":6.339415,"DOP":47.313359,"DZD":114.3225,"EGP":17.634,"ERN":15.191062,"ETB":27.052062,"EUR":0.851629,"FJD":2.046698,"FKP":0.759579,"GBP":0.759579,"GEL":2.481206,"GGP":0.759579,"GHS":4.395998,"GIP":0.759579,"GMD":47.45,"GNF":8929.15,"GTQ":7.335827,"GYD":206.925,"HKD":7.807972,"HNL":23.424588,"HRK":6.392998,"HTG":62.9125,"HUF":262.505,"IDR":13508.120071,"ILS":3.511228,"IMP":0.759579,"INR":65.1415,"IQD":1166.95,"IRR":34216.446723,"ISK":105.64657,"JEP":0.759579,"JMD":127.68,"JOD":0.709001,"JPY":112.7525,"KES":103.46,"KGS":68.54048,"KHR":4035.45,"KMF":418.832027,"KPW":900,"KRW":1131.57,"KWD":0.302227,"KYD":0.832646,"KZT":333.424074,"LAK":8290.35,"LBP":1506.85,"LKR":153.545,"LRD":118.347343,"LSL":13.4005,"LYD":1.365585,"MAD":9.48341,"MDL":17.335624,"MGA":3056.2,"MKD":52.439856,"MMK":1363.5,"MNT":2453.525814,"MOP":8.036355,"MRO":364.675,"MUR":34.0805,"MVR":15.400126,"MWK":726.17,"MXN":18.80613,"MYR":4.22137,"MZN":60.880666,"NAD":13.4005,"NGN":356.5,"NIO":30.248971,"NOK":7.960645,"NPR":103.795,"NZD":1.403916,"OMR":0.38502,"PAB":1,"PEN":3.244494,"PGK":3.171515,"PHP":51.441,"PKR":105.28,"PLN":3.60395,"PYG":5631.85,"QAR":3.6391,"RON":3.903674,"RSD":101.517649,"RUB":57.371,"RWF":833.635,"SAR":3.7502,"SBD":7.792911,"SCR":13.381152,"SDG":6.670684,"SEK":8.171241,"SGD":1.358402,"SHP":0.759579,"SLL":7643.328121,"SOS":577.95,"SRD":7.448,"SSP":130.0769,"STD":20829.200481,"SVC":8.742198,"SYP":514.97499,"SZL":13.402242,"THB":33.14925,"TJS":8.79525,"TMT":3.50998,"TND":2.473794,"TOP":2.224732,"TRY":3.685404,"TTD":6.69697,"TWD":30.20775,"TZS":2248.5,"UAH":26.431,"UGX":3656.65,"USD":1,"UYU":29.382962,"UZS":8054.25,"VEF":10.104074,"VND":22720.753308,"VUV":106.413334,"WST":2.532373,"XAF":558.632113,"XAG":0.05896852,"XAU":0.00078099,"XCD":2.70255,"XDR":0.708893,"XOF":558.632113,"XPD":0.00102149,"XPF":101.626392,"XPT":0.00107992,"YER":250.319142,"ZAR":13.50018,"ZMW":9.676382,"ZWL":322.355011}}
1+
{"disclaimer":"Usage subject to terms: https://openexchangerates.org/terms","license":"https://openexchangerates.org/license","timestamp":1508364000,"base":"USD","rates":{"AED":3.672896,"AFN":68.258,"ALL":113.202841,"AMD":479.79798,"ANG":1.785238,"AOA":165.9225,"ARS":17.3385,"AUD":1.27423,"AWG":1.789995,"AZN":1.6985,"BAM":1.658402,"BBD":2,"BDT":82.161542,"BGN":1.658459,"BHD":0.377196,"BIF":1752.410443,"BMD":1,"BND":1.357663,"BOB":6.886497,"BRL":3.1716,"BSD":1,"BTC":0.000181705212,"BTN":64.970224,"BWP":10.2681,"BYN":1.959253,"BZD":2.010136,"CAD":1.246247,"CDF":1566.940781,"CHF":0.980812,"CLF":0.023185,"CLP":626.056164,"CNH":6.618376,"CNY":6.6273,"COP":2924,"CRC":569.982428,"CUC":1,"CUP":25.5,"CVE":93.9,"CZK":21.8045,"DJF":178.76,"DKK":6.312846,"DOP":47.44472,"DZD":114.22,"EGP":17.6465,"ERN":15.191062,"ETB":27.12175,"EUR":0.848025,"FJD":2.046698,"FKP":0.757387,"GBP":0.757387,"GEL":2.482754,"GGP":0.757387,"GHS":4.380008,"GIP":0.757387,"GMD":47.45,"GNF":8991.8,"GTQ":7.353379,"GYD":206.536783,"HKD":7.80835,"HNL":23.509231,"HRK":6.366544,"HTG":62.800398,"HUF":261.245,"IDR":13509.746714,"ILS":3.497915,"IMP":0.757387,"INR":65.0522,"IQD":1163.134957,"IRR":34230.946723,"ISK":105.5,"JEP":0.757387,"JMD":127.023805,"JOD":0.709001,"JPY":112.96083333,"KES":103.437968,"KGS":68.563978,"KHR":4052.141667,"KMF":417.634177,"KPW":900,"KRW":1132.5,"KWD":0.302161,"KYD":0.833373,"KZT":332.315291,"LAK":8270.4,"LBP":1507.587443,"LKR":153.084098,"LRD":118.354791,"LSL":13.429623,"LYD":1.364648,"MAD":9.424543,"MDL":17.27469,"MGA":3063.225758,"MKD":52.221,"MMK":1366.43506,"MNT":2453.525814,"MOP":8.042193,"MRO":364.5,"MUR":33.954,"MVR":15.400167,"MWK":724.899944,"MXN":18.88042,"MYR":4.222974,"MZN":60.992141,"NAD":13.431025,"NGN":358.552572,"NIO":30.64404,"NOK":7.958805,"NPR":103.804326,"NZD":1.396973,"OMR":0.384814,"PAB":1,"PEN":3.244218,"PGK":3.190662,"PHP":51.41,"PKR":104.941717,"PLN":3.5913,"PYG":5718.954248,"QAR":3.785013,"RON":3.888919,"RSD":100.955,"RUB":57.4119,"RWF":850.545,"SAR":3.75045,"SBD":7.777811,"SCR":13.38,"SDG":6.676624,"SEK":8.143506,"SGD":1.357065,"SHP":0.757387,"SLL":7643.328121,"SOS":576.579786,"SRD":7.448,"SSP":130.3084,"STD":20786.750286,"SVC":8.750528,"SYP":514.94499,"SZL":13.43564,"THB":33.14,"TJS":8.795317,"TMT":3.499986,"TND":2.485597,"TOP":2.224732,"TRY":3.678097,"TTD":6.706395,"TWD":30.1995,"TZS":2248.1,"UAH":26.332323,"UGX":3640.083069,"USD":1,"UYU":29.304924,"UZS":8057.15,"VEF":10.17125,"VND":22720.753308,"VUV":106.133334,"WST":2.532373,"XAF":556.26788,"XAG":0.05881223,"XAU":0.00078067,"XCD":2.70255,"XDR":0.70955,"XOF":556.26788,"XPD":0.00104661,"XPF":101.196291,"XPT":0.00108549,"YER":250.281642,"ZAR":13.5773,"ZMW":9.74075,"ZWL":322.355011}}

src/shared/components/sandbox/payments/Confirmation/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import './style.scss';
1212
export default function Confirmation({
1313
amount,
1414
assignee,
15+
resetPaymentData,
1516
}) {
1617
return (
1718
<Background>
@@ -30,8 +31,7 @@ export default function Confirmation({
3031
</div>
3132
<div styleName="actions">
3233
<Button
33-
// TODO: Demands some more logic here.
34-
to="/sandbox/payments/new"
34+
onClick={resetPaymentData}
3535
>Make another payment</Button>
3636
<PrimaryButton
3737
to="/sandbox/payments"
@@ -46,4 +46,5 @@ export default function Confirmation({
4646
Confirmation.propTypes = {
4747
amount: PT.number.isRequired,
4848
assignee: PT.string.isRequired,
49+
resetPaymentData: PT.func.isRequired,
4950
};

src/shared/components/sandbox/payments/Listing/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export default function Listing({
2121
const selectedProjectIdNum = Number(selectedProjectId);
2222
let content = memberTasks
2323
.filter(item => item.projectId === selectedProjectIdNum)
24-
.map(challenge => (
24+
.sort((a, b) => {
25+
const aDate = a.updatedAt || a.createdAt;
26+
const bDate = b.updatedAt || b.createdAt;
27+
return bDate.localeCompare(aDate);
28+
}).map(challenge => (
2529
<PaymentRow
2630
challenge={challenge}
2731
key={challenge.id}

src/shared/containers/sandbox/payments/Editor.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import _ from 'lodash';
99
import actions from 'actions';
10+
import Background from 'components/sandbox/payments/Background';
1011
import Confirmation from 'components/sandbox/payments/Confirmation';
1112
import Editor from 'components/sandbox/payments/Editor';
1213
import LoadingIndicator from 'components/LoadingIndicator';
@@ -15,6 +16,7 @@ import React from 'react';
1516
import { STATE as PAGE_STATE } from 'actions/page/sandbox/payments/editor';
1617
import { connect } from 'react-redux';
1718
import { getService as getChallengeService } from 'services/challenges';
19+
import { getService as getUserService } from 'services/user';
1820
import { goToLogin } from 'utils/tc';
1921

2022
/**
@@ -129,19 +131,32 @@ class EditorContainer extends React.Component {
129131
tokenV3,
130132
} = this.props;
131133
setPageState(PAGE_STATE.WAITING);
132-
const service = getChallengeService(tokenV3);
133-
const challenge = await service.createTask(
134+
const challengeService = getChallengeService(tokenV3);
135+
const userService = getUserService(tokenV3);
136+
const challenge = await challengeService.createTask(
134137
selectedProjectId,
135138
selectedBillingAccountId,
136139
paymentTitle,
137140
paymentDescription,
138141
paymentAssignee,
139142
paymentAmount,
140143
);
141-
await service.activate(challenge.id);
144+
const user = await userService.getUser(paymentAssignee);
145+
await challengeService.activate(challenge.id);
146+
if (user) {
147+
await challengeService.close(challenge.id, user.id);
148+
}
142149
setPageState(PAGE_STATE.PAID);
143150
}
144151

152+
resetPaymentData() {
153+
this.props.setPageState(PAGE_STATE.NEW_PAYMENT);
154+
this.props.setPaymentAmount(0);
155+
this.props.setPaymentAssignee('');
156+
this.props.setPaymentDescription('');
157+
this.props.setPaymentTitle('');
158+
}
159+
145160
render() {
146161
const {
147162
pageState,
@@ -161,12 +176,19 @@ class EditorContainer extends React.Component {
161176
tokenV3,
162177
} = this.props;
163178
if (!tokenV3 || !projects.length
164-
|| pageState === PAGE_STATE.WAITING) return <LoadingIndicator />;
179+
|| pageState === PAGE_STATE.WAITING) {
180+
return (
181+
<Background>
182+
<LoadingIndicator />
183+
</Background>
184+
);
185+
}
165186
if (pageState === PAGE_STATE.PAID) {
166187
return (
167188
<Confirmation
168189
amount={paymentAmount}
169190
assignee={paymentAssignee}
191+
resetPaymentData={() => this.resetPaymentData()}
170192
/>
171193
);
172194
}

src/shared/services/challenges.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ class ChallengesService {
156156
/**
157157
* Closes the specified challenge.
158158
* @param {Number} challengeId
159-
* @param {Number} winnerId
159+
* @param {Number} winnerId Optional. ID of the assignee to declare the
160+
* winner.
160161
* @return {Promise} Resolves to null value in case of success; otherwise it
161162
* is rejected.
162163
*/
163-
async close(challengeId) {
164-
// let url = `/challenges/${challengeId}/close`;
165-
let res = await this.private.api.post(
166-
`/challenges/${challengeId}/close`);
164+
async close(challengeId, winnerId) {
165+
let url = `/challenges/${challengeId}/close`;
166+
if (winnerId) url = `${url}?winnerId=${winnerId}`;
167+
let res = await this.private.api.post(url);
167168
if (!res.ok) throw new Error(res.statusText);
168169
res = (await res.json()).result;
169170
if (res.status !== 200) throw new Error(res.content);

src/shared/services/user.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* The User service provides functionality related to Topcoder user accounts.
3+
*/
4+
5+
import { getApiV3 } from './api';
6+
7+
export default class User {
8+
/**
9+
* Creates a new User service.
10+
* @param {String} tokenV3 Topcoder auth tokenV3.
11+
*/
12+
constructor(tokenV3) {
13+
this.private = {
14+
api: getApiV3(tokenV3),
15+
tokenV3,
16+
};
17+
}
18+
19+
/**
20+
* Gets user data object for the specified username.
21+
* @param {String} username
22+
* @return {Promise} Resolves to the user data object.
23+
*/
24+
async getUser(username) {
25+
let res = await this.private.api.get(`/users?filter=handle%3D${username}`);
26+
if (!res.ok) throw new Error(res.statusText);
27+
res = (await res.json()).result;
28+
if (res.status !== 200) throw new Error(res.content);
29+
return res.content[0];
30+
}
31+
}
32+
33+
/**
34+
* Returns a new or existing User service for the specified tokenV3.
35+
* @param {String} tokenV3 Optional. Topcoder auth token v3.
36+
* @return {Api} API v3 service object.
37+
*/
38+
let lastInstance = null;
39+
export function getService(tokenV3) {
40+
if (!lastInstance || lastInstance.private.tokenV3 !== tokenV3) {
41+
lastInstance = new User(tokenV3);
42+
}
43+
return lastInstance;
44+
}
45+

0 commit comments

Comments
 (0)