cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              @import url('https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i');

body {
  background: #f5f5f5;
  color: #222;
  font-family: 'PT Sans', Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding: 20px;
}

* {
  box-sizing: border-box;
}

input[type=checkbox] {
  transform: scale(1.25);
}

.u-text-bold {
  font-weight: 700;
}

.c-global-message {
  background: #ef4507;
  color: #fff;
  padding: 10px 16px;
  position: fixed;
  top: -7px;
  left: 0;
  right: 0;
  text-align: center;
  text-transform: uppercase;
  
  &--success {
    background: #60b208;
  }
}

.c-loader {
  background: rgba(255,255,255,.75);
  position: fixed;
  left: 0;
  top: 0; 
  right: 0;
  bottom: 0;
  z-index: 1000;
  
  &:before {
    background: rgba(255,255,255,.75) center center/55px no-repeat url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-489/loader.svg');
    content: attr(data-text);
    display: block;
    font-size: 18px;
    font-weight: 700;
    width: 100px;
    padding-top: 100px;
    position: absolute;
    top: 50%;
    left: 50%;
    text-align: center;
    text-transform: uppercase;
    transform: translate(-50%,calc(-50% - 10px));
  }
}

.c-btn {
  background: #ef4507;
  border-radius: 3px;
  color: #fff;
  cursor: pointer;
  border: 0;
  display: inline-block;
  font-size: 14px;
  padding: 10px;
  text-transform: uppercase;
  transition: background .2s linear;
  
  &:hover {
    background: darken(#ef4507, 7%);
  }
  
  &--block {
    display: block;
    width: 100%;
  }
  
  &--success {
    background: #60b208;

    &:hover {
      background: darken(#60b208, 7%);
    }
  }
}

.u-vr {
  margin-top: 8px;
}

.c-expense-list {
  margin: -8px;
  
  &__item {
    padding: 4px;
  }
  
  &__item__content {
    align-items: center;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
    display: flex;
    height: 100%;
    padding: 12px;
    
    & > * + * {
      margin-left: 16px; 
    }
    
    & > :nth-child(2) {
      flex-grow: 1;
    }
    
    & > :last-child {
      width: 60px;
    }
  }
  
  h3 {
    font-size: 22px;
    font-weight: 700;
    line-height: 20px;
    margin-bottom: 2px;
    text-transform: uppercase;
  }
  
  h4 {
    color: #666;
    font-size: 15px;
  }
}
            
          
!
            
              const { Component, PropTypes } = React;
const { render } = ReactDOM;

const API_BASE_URL = 'https://stashtracker-api.herokuapp.com/api';

const generateKey = (prefix) => {
  return `${prefix}-${Math.round(Math.random() * 10000)}`;
};

const formatDate = (date) => {
  const dateArray = date.split('/');
  dateArray.push(dateArray.shift());
  return dateArray.join('/');
};

class Loader extends Component {
  constructor (props) {
    super(props);
  }
  
  static propTypes = {
    text: PropTypes.string,
  };

  static defaultProps = {
    text: 'Loading',
  };
  
  render () {
    
    const { text } = this.props;
    
    return (
      <div className="c-loader" data-text={ text }></div>
    );
  }
}

class ExpenseList extends Component {
  constructor (props) {
    super(props);
    
    this.state = { 
      expenseList: [],
      isLoading: true,
      error: null
    };
  }
  
  static propTypes = {
    endpoint: PropTypes.string,
  };

  static defaultProps = {
    endpoint: '/getAllExpenses',
  };

  componentDidMount () {
    this._getAllExpenses();
  }

  _setGlobalMessageTimeout = (duration) => {
    setTimeout(() => {
      this.setState({
        error: false,
        confirmation: false
      });
    }, duration);
  };

  _getAllExpenses = () => {
    const { endpoint } = this.props;
    
    axios.get(`${API_BASE_URL}${endpoint}`)
      .then(res => {
        this.setState({ 
          expenseList: res.data, 
          isLoading: false 
        });
      })
      .catch(error => {
        this.setState({ 
          isLoading: false, 
          error: `Error: ${error.response.status}`
        }, () => {
          this._setGlobalMessageTimeout(3000);
        });
      });
  };

  _setExpenseStatus = (id, status) => {
    const newStatus = status === 0 ? 1 : 0;
    
    this.setState({ isLoading: true });
    
    axios.post(`${API_BASE_URL}/updatePaymentStatus/`, {
        id: id,
        isPaid: newStatus
      })
      .then(res => {
        this._getAllExpenses();
        this.setState({ 
          confirmation: 'Expense Successfully Updated'
        }, () => {
          this._setGlobalMessageTimeout(5000);
        });
      })
      .catch(error => {
        this.setState({ 
          isLoading: false, 
          error: `Error: ${error.response.status}`
        }, () => {
          this._setGlobalMessageTimeout(5000);
        });
      });
  };
  
  render () {
    
    const { _setExpenseStatus } = this;
    const { expenseList, isLoading, error, confirmation } = this.state;
    const message = error || confirmation;
    
    return (
      <div>
        { message 
          ? <div className={ classNames(
              'c-global-message u-vr', 
              {'c-global-message--success': confirmation }
            ) }>
              { message }
            </div> 
          : null }
        { isLoading ? <Loader /> : null }
        <ul className="c-expense-list">
          { _.map(expenseList, item => {
            
            const { id, expense, balance, dueDate, isPaid } = item;
            
            return <li key={ generateKey('foo') } className="c-expense-list__item">
              <div className="c-expense-list__item__content">
                <div>
                  <input type="checkbox" />
                </div>
                <div>
                  <h3>{ expense }</h3>
                  <h4>
                    <span className="u-text-bold">Balance:</span> ${ balance } <span className="u-text-bold">Due:</span> { formatDate(dueDate) }
                  </h4>
                </div>
                <div>
                  <button 
                    className={ classNames(
                      'c-btn c-btn--block',
                      {'c-btn--success': isPaid}
                    ) } 
                    onClick={ () => _setExpenseStatus(id, isPaid) }>
                    { isPaid === 1 ? 'Paid' : 'Pay' }
                  </button>
                </div>
              </div>
            </li>;
            
          }) }
        </ul>  
      </div>
    );
  }
};

class App extends React.Component {
  constructor (props) {
    super(props);
    
    this.state = {
      error: null,
      confirmation: null,
    };
  }
  
  _showGlobalMessage = (msg, type) => {
    let stateObj = {};
    stateObj[type] = msg;
    this.setState(stateObj);
  };
  
  _setGlobalMessageTimeout = (duration) => {
    setTimeout(() => {
      this.setState({
        error: false,
        confirmation: false
      });
    }, duration);
  };
  
  render () {
    return (
      <div>
        <ExpenseList endpoint="/getAllExpenses" /> 
      </div>
    );
  }
};

render(<App />, document.body);
            
          
!
999px
Loading ..................

Console