import React from 'react'; import {formatPrice} from '../Util/formatters'; import superagent from 'superagent'; import { Container, Segment, Grid, Header, Image, Icon, Button, Table, Form, Label, Message, Menu, Tab, Dropdown, Modal, Card, Divider} from 'semantic-ui-react' export default class CollectionEditor extends React.Component { constructor(props) { super(props); this.state = { products: [], collection: null }; } async componentDidMount() { if (this.props.match.params.collectionId) { this.setState({ loading: true }); const res = await superagent.get(`/api/admin/media/product/${this.props.match.params.collectionId}`).accept('json'); console.log(res.body); this.setState({ collection: res.body, loading: false }); } this.setState({ loading: true }); const mediaProductsRes = await superagent.get(`/api/admin/media/media_products`).accept('json'); const mediaProductsOptions = mediaProductsRes.body.map(nv => { return { "key": nv.id, "value": nv.id, "text": `${nv.title}` } }); this.setState({ allMediaProducts: mediaProductsRes.body, mediaProductsOptions }); } async onSaveCollection() { this.setState({ loading: true }); try { if (this.state.collection.id) { const res = await superagent.put(`/api/admin/media/collection`).send(this.state.product); console.log(res); //this.setState({ loading: false }); } else { console.log(this.state.product); const res = await superagent.post(`/api/admin/media/collection`).send(this.state.product); this.setState({ product: res.body }); } this.setState({ messages: null, loading: false }) } catch (e) { console.log(e.response.body); this.setState({ messages: e.response.body, loading: false }); } } // Remove and add products to the collection... render() { return ( Title Store Link BigMediaId Duration Synchronization Interval Entitlement Class Location Codes SKUs Tools {this.props.collection.products.map((product, productIndex) => { const locationCodes = product.locationCodes ? (
{product.locationCodes.map(locationCode => ( ))}
) :
; const prices = (
{product.stripeProductData.skus.data.map(sku => ( ))}
); return (
{product.title}
Store {product.bigMediaId} {locationCodes} {prices}
); })}
); } }