2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
showFullPrice: boolean,
|
|
|
|
costInfo: ?{ includesData: boolean, cost: number },
|
|
|
|
fetchCostInfo: string => void,
|
|
|
|
uri: string,
|
|
|
|
fetching: boolean,
|
|
|
|
claim: ?{},
|
2018-07-25 06:23:58 +02:00
|
|
|
// below props are just passed to <CreditAmount />
|
2018-10-19 22:38:07 +02:00
|
|
|
badge?: boolean,
|
2018-07-25 06:23:58 +02:00
|
|
|
inheritStyle?: boolean,
|
|
|
|
showLBC?: boolean,
|
2018-08-06 19:58:33 +02:00
|
|
|
hideFree?: boolean, // hide the file price if it's free
|
2020-05-11 17:54:39 +02:00
|
|
|
className?: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class FilePrice extends React.PureComponent<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
showFullPrice: false,
|
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2019-08-21 20:22:51 +02:00
|
|
|
componentDidMount() {
|
2018-05-03 07:20:31 +02:00
|
|
|
this.fetchCost(this.props);
|
|
|
|
}
|
|
|
|
|
2019-08-21 20:22:51 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.fetchCost(this.props);
|
2018-05-03 07:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fetchCost = (props: Props) => {
|
|
|
|
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
|
|
|
}
|
2018-05-03 07:20:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2020-05-11 17:54:39 +02:00
|
|
|
const { costInfo, showFullPrice, badge, inheritStyle, showLBC, hideFree, className } = this.props;
|
2019-12-14 21:13:13 +01:00
|
|
|
if (costInfo && (!costInfo.cost || (!costInfo.cost && hideFree))) {
|
2018-08-06 19:58:33 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-05-12 19:14:06 +02:00
|
|
|
|
2018-05-25 18:16:17 +02:00
|
|
|
return costInfo ? (
|
2017-06-06 23:19:12 +02:00
|
|
|
<CreditAmount
|
2018-07-25 02:50:04 +02:00
|
|
|
showFree
|
2018-10-19 22:38:07 +02:00
|
|
|
badge={badge}
|
2018-07-25 06:23:58 +02:00
|
|
|
inheritStyle={inheritStyle}
|
|
|
|
showLBC={showLBC}
|
2017-06-06 23:19:12 +02:00
|
|
|
amount={costInfo.cost}
|
2018-05-25 18:16:17 +02:00
|
|
|
isEstimate={!costInfo.includesData}
|
2017-08-23 02:59:36 +02:00
|
|
|
showFullPrice={showFullPrice}
|
2020-05-11 17:54:39 +02:00
|
|
|
className={className}
|
2017-06-06 23:19:12 +02:00
|
|
|
/>
|
2018-05-25 18:16:17 +02:00
|
|
|
) : null;
|
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;
|