import * as React from 'react'; import * as _get from 'lodash.get'; import * as _isEmpty from 'lodash.isempty'; import * as classNames from 'classnames'; import {HTMLProps, PureComponent} from 'react'; import {Image} from './models'; import { Button, Col, FormGroup, FormText, Icon, Img, ImgThumbnail, Label, Row, Scrollbars} from './'; const styles = { image: (hidden: boolean) => hidden ? { display: 'none', } : {}, }; export interface FormImagesProps extends HTMLProps { images?: Image[]; mapImageUrl?: string; marketingImageUrl?: string; modelName?: string; noUploadButton?: boolean; onClickMarketingOrMapImage?: () => void; onClickRemoveButton?: (image: Image) => void; onClickUploaButton?: () => void; } export interface FormImagesState { errorOnLoadMarketingImage: boolean; errorOnLoadMapImage: boolean; removeButtonsVisible: boolean; } export class FormImages extends PureComponent { static defaultProps: FormImagesProps = { images: [], mapImageUrl: '', marketingImageUrl: '', modelName: '', noUploadButton: false, onClickMarketingOrMapImage: () => { return; }, onClickRemoveButton: () => { return; }, onClickUploaButton: () => { return; }, }; state: FormImagesState = { errorOnLoadMarketingImage: false, errorOnLoadMapImage: false, removeButtonsVisible: false, }; render() { const {images, noUploadButton, readOnly, onClickUploaButton} = this.props; const {errorOnLoadMarketingImage, removeButtonsVisible} = this.state; return (
{/* */} {this.renderMarketingImage()} {this.renderMapImage()}
{!noUploadButton && !readOnly && ( )} {this.renderUploadedImages()} {!readOnly && !_isEmpty(images) && (
)}
{/*
*/}
{!readOnly && !errorOnLoadMarketingImage && ( Click the image to open a map )} {errorOnLoadMarketingImage && ( Reference image not found )}
); } renderMarketingImage = () => { const {marketingImageUrl, readOnly, onClickMarketingOrMapImage} = this.props; const {errorOnLoadMarketingImage} = this.state; const image: any = {url: marketingImageUrl}; return readOnly ? ( ) : ( ); } renderMapImage = () => { const {mapImageUrl, readOnly, onClickMarketingOrMapImage} = this.props; const {errorOnLoadMapImage} = this.state; const image: any = {url: mapImageUrl}; if (_isEmpty(mapImageUrl)) { return null; } return readOnly ? ( ) : ( ); } renderUploadedImages = () => { const {images, readOnly, onClickRemoveButton} = this.props; const {removeButtonsVisible} = this.state; const toImage = (url: string) => ({url}); return images.map((image, index) => ( )); } handleRemoveButtonClick = (image: Image) => () => { this.props.onClickRemoveButton(image); } handleRemoveMediaChange = () => { this.setState({removeButtonsVisible: !this.state.removeButtonsVisible}); } updateState = (stateProp: string, error: boolean) => () => { this.setState({[stateProp]: error} as any); } getMarketingImageAlt = () => { return `Marketing image ${this.props.modelName}`; } }