import React, { Component } from 'react';
import { connect } from 'react-redux';
import { fetchProfile } from '../actions/buskers.js';
import ProfileShortDonate from '../components/ProfileShortDonate';
import PropTypes from 'prop-types';
//import { StripeProvider } from 'react-stripe-elements';
//const STRIPE_API_KEY = window._CONFIG_.stripePublishableKey;
//const accountId = window._CONFIG_.accountId;
class ProfileShortDonateContainer extends Component {
constructor(props) {
super(props);
this.state = {
albumToDonate: null,
donateToAlbum: null,
donateToAlbumAmount: null,
isFetching: true
}
this.handleCancel = this.handleCancel.bind(this);
}
componentDidMount() {
const { dispatch, buskerID } = this.props;
const csrf = window._CONFIG_.csrf;
dispatch(fetchProfile(buskerID, csrf))
}
UNSAFE_componentWillReceiveProps(nextProps) {
const { user } = this.props;
const donateToAlbum = window._CONFIG_.albumid !== null ? window._CONFIG_.albumid : false
if (user.original !== nextProps.user.original) {
if (donateToAlbum) {
const albumToDonate = nextProps.user.activeUserAlbums && nextProps.user.activeUserAlbums.length > 0 ? nextProps.user.activeUserAlbums.filter(album => parseInt(album.id) === parseInt(donateToAlbum))[0] : false;
this.setState({
albumToDonate,
donateToAlbum: albumToDonate.id ? donateToAlbum : false,
donateToAlbumAmount: window._CONFIG_.donation !== null ? parseInt(window._CONFIG_.donation) < 5 ? 5 : parseInt(window._CONFIG_.donation) : window._CONFIG_.donation,
})
}
this.setState({
isFetching: false
})
}
}
handleCancel() {
const { user } = this.props;
const newLocation = `/${user.original.uid}`;
setTimeout(`window.location = '${newLocation}'`, 500)
}
render() {
const { user, dispatch } = this.props;
const { albumToDonate, donateToAlbum, donateToAlbumAmount, isFetching } = this.state;
// return (
//
// )
return (
)
}
}
ProfileShortDonateContainer.propTypes = {
buskerID: PropTypes.number.isRequired,
dispatch: PropTypes.func.isRequired,
user: PropTypes.shape().isRequired
}
const mapStateToProps = ({ buskers: { user } }) => ({
user
});
export default connect(mapStateToProps)(ProfileShortDonateContainer);