shift-admin-ui-kit
Version:
UI Kit for Shift Commerce Projects
39 lines (30 loc) • 966 B
JavaScript
import React, { Component } from "react"
import { connect } from 'react-redux'
// import actions
import { setApiBaseEndpoint, setApiHeaders } from "../actions"
class ApiConfig extends Component {
shiftApiHeaders() {
return {
"Content-Type": "application/vnd.api+json",
"Accept": "application/vnd.api+json",
"Authorization": `Bearer ${this.props.authentication.token}`
}
}
componentDidUpdate(oldProps) {
if (oldProps.authentication.token !== this.props.authentication.token) {
this.props.dispatch(setApiHeaders( this.shiftApiHeaders() ))
}
}
componentDidMount() {
this.props.dispatch(setApiBaseEndpoint( this.props.baseEndpoint ))
this.props.dispatch(setApiHeaders( this.shiftApiHeaders() ))
}
render() {
return null
}
}
const mapStateToProps = (state) => {
const authentication = state.authentication || {}
return { authentication }
}
export default connect(mapStateToProps)(ApiConfig)