2018-01-31 02:15:23 +01:00
|
|
|
import React from 'react';
|
2018-02-07 20:30:39 +01:00
|
|
|
import ErrorPage from 'components/ErrorPage';
|
2018-02-02 20:10:58 +01:00
|
|
|
import ShowAssetLite from 'components/ShowAssetLite';
|
|
|
|
import ShowAssetDetails from 'components/ShowAssetDetails';
|
2018-01-31 02:15:23 +01:00
|
|
|
|
2018-02-08 08:18:18 +01:00
|
|
|
import { ASSET } from 'constants/show_request_types';
|
|
|
|
|
|
|
|
function requestIsAnAssetRequest ({ requestType }) {
|
|
|
|
return requestType === ASSET;
|
|
|
|
}
|
|
|
|
|
2018-01-31 02:15:23 +01:00
|
|
|
class ShowAsset extends React.Component {
|
|
|
|
componentDidMount () {
|
2018-02-13 04:01:29 +01:00
|
|
|
const { asset, previousRequest, requestId, requestName, requestModifier } = this.props;
|
|
|
|
if (!previousRequest) { // case: the asset request does not exist
|
2018-02-13 03:18:56 +01:00
|
|
|
return this.props.onNewRequest(requestId, requestName, requestModifier);
|
|
|
|
};
|
|
|
|
if (!asset) { // case: the asset request does not exist
|
2018-02-13 04:01:29 +01:00
|
|
|
const { name, claimId } = previousRequest;
|
2018-02-13 03:18:56 +01:00
|
|
|
return this.props.onShowNewAsset(name, claimId);
|
|
|
|
};
|
2018-01-31 02:15:23 +01:00
|
|
|
}
|
2018-02-08 03:01:51 +01:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2018-02-13 03:18:56 +01:00
|
|
|
if (requestIsAnAssetRequest(nextProps)) {
|
2018-02-13 04:01:29 +01:00
|
|
|
const { asset, previousRequest, requestId, requestName, requestModifier } = nextProps;
|
|
|
|
if (!previousRequest) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return this.props.onNewRequest(requestId, requestName, requestModifier);
|
|
|
|
};
|
|
|
|
if (!asset) {
|
2018-02-13 04:01:29 +01:00
|
|
|
const { name, claimId } = previousRequest;
|
2018-02-13 03:18:56 +01:00
|
|
|
return this.props.onShowNewAsset(name, claimId);
|
|
|
|
};
|
2018-02-08 03:01:51 +01:00
|
|
|
}
|
2018-01-31 02:15:23 +01:00
|
|
|
}
|
|
|
|
render () {
|
2018-02-13 03:18:56 +01:00
|
|
|
const {asset, requestExtension} = this.props;
|
|
|
|
if (asset) {
|
2018-02-08 03:01:51 +01:00
|
|
|
if (requestExtension) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return <ShowAssetLite/>;
|
2018-02-05 02:51:17 +01:00
|
|
|
}
|
2018-02-13 03:18:56 +01:00
|
|
|
return <ShowAssetDetails/>;
|
|
|
|
}
|
|
|
|
;
|
2018-01-31 02:15:23 +01:00
|
|
|
return (
|
2018-02-13 03:18:56 +01:00
|
|
|
<ErrorPage error={'loading asset data...'}/>
|
2018-01-31 02:15:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowAsset;
|