2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import { CreditAmount } from "component/common";
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class FilePrice extends React.PureComponent {
|
2017-05-18 19:58:28 +02:00
|
|
|
componentWillMount() {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.fetchCost(this.props);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.fetchCost(nextProps);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-12 19:14:06 +02:00
|
|
|
fetchCost(props) {
|
2017-06-08 06:42:19 +02:00
|
|
|
const { costInfo, fetchCostInfo, uri, fetching, claim } = props;
|
2017-06-05 10:37:37 +02:00
|
|
|
|
|
|
|
if (costInfo === undefined && !fetching && claim) {
|
2017-06-06 23:19:12 +02:00
|
|
|
fetchCostInfo(uri);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 19:14:06 +02:00
|
|
|
render() {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { costInfo, look = "indicator" } = this.props;
|
2017-05-12 19:14:06 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const isEstimate = costInfo ? !costInfo.includesData : null;
|
2017-05-12 19:14:06 +02:00
|
|
|
|
|
|
|
if (!costInfo) {
|
2017-06-06 23:19:12 +02:00
|
|
|
return (
|
|
|
|
<span className={`credit-amount credit-amount--${look}`}>???</span>
|
|
|
|
);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
return (
|
|
|
|
<CreditAmount
|
|
|
|
label={false}
|
|
|
|
amount={costInfo.cost}
|
|
|
|
isEstimate={isEstimate}
|
|
|
|
showFree={true}
|
|
|
|
/>
|
|
|
|
);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FilePrice;
|