2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-05-21 17:38:28 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2020-05-21 17:38:28 +02:00
|
|
|
import classnames from 'classnames';
|
2018-03-26 23:32:43 +02:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
2020-05-21 17:38:28 +02:00
|
|
|
import Icon from 'component/common/icon';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
showFullPrice: boolean,
|
|
|
|
costInfo: ?{ includesData: boolean, cost: number },
|
2021-12-31 18:52:26 +01:00
|
|
|
doFetchCostInfoForUri: (string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
uri: string,
|
|
|
|
fetching: boolean,
|
|
|
|
claim: ?{},
|
2020-05-21 17:38:28 +02:00
|
|
|
claimWasPurchased: boolean,
|
|
|
|
claimIsMine: boolean,
|
|
|
|
type?: string,
|
2018-07-25 06:23:58 +02:00
|
|
|
// below props are just passed to <CreditAmount />
|
|
|
|
inheritStyle?: boolean,
|
|
|
|
showLBC?: boolean,
|
2018-08-06 19:58:33 +02:00
|
|
|
hideFree?: boolean, // hide the file price if it's free
|
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) => {
|
2021-12-31 18:52:26 +01:00
|
|
|
const { costInfo, doFetchCostInfoForUri, uri, fetching, claim } = props;
|
2017-06-05 10:37:37 +02:00
|
|
|
|
|
|
|
if (costInfo === undefined && !fetching && claim) {
|
2021-12-31 18:52:26 +01:00
|
|
|
doFetchCostInfoForUri(uri);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
2018-05-03 07:20:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2020-05-21 17:38:28 +02:00
|
|
|
const { costInfo, showFullPrice, showLBC, hideFree, claimWasPurchased, type, claimIsMine } = this.props;
|
|
|
|
|
|
|
|
if (claimIsMine || !costInfo || !costInfo.cost || (!costInfo.cost && hideFree)) {
|
2018-08-06 19:58:33 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-05-12 19:14:06 +02:00
|
|
|
|
2020-05-21 17:38:28 +02:00
|
|
|
return claimWasPurchased ? (
|
|
|
|
<span
|
|
|
|
className={classnames('file-price__key', {
|
|
|
|
'file-price__key--filepage': type === 'filepage',
|
|
|
|
'file-price__key--modal': type === 'modal',
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Icon icon={ICONS.PURCHASED} size={type === 'filepage' ? 22 : undefined} />
|
|
|
|
</span>
|
|
|
|
) : (
|
2017-06-06 23:19:12 +02:00
|
|
|
<CreditAmount
|
2020-05-21 17:38:28 +02:00
|
|
|
className={classnames('file-price', {
|
|
|
|
'file-price--filepage': type === 'filepage',
|
|
|
|
'file-price--modal': type === 'modal',
|
|
|
|
})}
|
2018-07-25 02:50:04 +02:00
|
|
|
showFree
|
2018-07-25 06:23:58 +02:00
|
|
|
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}
|
2017-06-06 23:19:12 +02:00
|
|
|
/>
|
2020-05-21 17:38:28 +02:00
|
|
|
);
|
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;
|