Skip to content

Commit

Permalink
Merge pull request #1401 from botpress/f_fix-nodes-parsing
Browse files Browse the repository at this point in the history
fix(admin): nodes parsing & ensure fingerprint
  • Loading branch information
slvnperron committed Feb 2, 2019
2 parents 6410308 + 7601e52 commit 1670eb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CustomizeLicenseForm extends Component {

handleLabelChanged = e => this.setState({ label: e.target.value }, () => this.updateParent())
handleCheckboxChanged = e => this.setState({ [e.target.name]: e.target.checked }, this.calculatePrice)
handleInputChanged = e => this.setState({ [e.target.name]: e.target.value }, this.calculatePrice)
handleNumberInputChanged = e => this.setState({ [e.target.name]: e.target.valueAsNumber }, this.calculatePrice)

render() {
if (!this.props.products) {
Expand Down Expand Up @@ -128,7 +128,7 @@ class CustomizeLicenseForm extends Component {
min="0"
max="100"
value={this.state.nodes}
onChange={this.handleInputChanged}
onChange={this.handleNumberInputChanged}
/>
</PriceItem>
<PriceItem
Expand Down
10 changes: 5 additions & 5 deletions src/bp/ui-admin/src/Pages/Components/Licensing/KeyListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class KeyListItem extends Component {
try {
const licensing = await api.getLicensing()
await licensing.delete(`/me/keys/${license.stripeSubscriptionId}`)
this.props.refreshLicense()
this.props.onLicenseUpdated({ ...license, canceled: true })
} catch (error) {
console.error('error canceling license')
}
Expand All @@ -65,7 +65,7 @@ export default class KeyListItem extends Component {
try {
const licenseKey = await this.activateWithServerFingerprint()
await this.updateServerKey(licenseKey)
this.props.refreshLicense()
this.props.onLicenseUpdated(licenseKey)
} catch (error) {
console.log('error while setting up license')
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class KeyListItem extends Component {
<DropdownMenu>
{license.assigned && <DropdownItem onClick={this.revealLicense}>Reveal License Key</DropdownItem>}
<DropdownItem onClick={this.assignFingerprint}>Assign Fingerprint</DropdownItem>
<DropdownItem onClick={this.useOnServer}>Use on this Server</DropdownItem>
{this.props.clusterFingerprint && <DropdownItem onClick={this.useOnServer}>Use on this Server</DropdownItem>}
<DropdownItem onClick={this.updateLicense}>Update License</DropdownItem>
{!license.canceled && <DropdownItem onClick={this.disableAutoRenew}>Disable Auto-Renew</DropdownItem>}
</DropdownMenu>
Expand All @@ -144,7 +144,7 @@ export default class KeyListItem extends Component {
render() {
const { license } = this.props
const assignedClass = license.assigned ? 'assigned' : 'not-assigned'
const isActive = this.props.clusterFingerprint === license.fingerprint
const isActive = this.props.clusterFingerprint && this.props.clusterFingerprint === license.fingerprint

return (
<tr disabled={license.canceled}>
Expand All @@ -157,7 +157,7 @@ export default class KeyListItem extends Component {
</span>
</td>
<td>
<span className="table--keys__users">{license.limits && license.limits.nodes + 1}</span>
<span className="table--keys__users">{license.limits && Number(license.limits.nodes) + 1}</span>
</td>
<td>
<span className="table--keys__users">{license.quantities.isGoldSupport ? 'Gold' : 'Standard'}</span>
Expand Down
11 changes: 8 additions & 3 deletions src/bp/ui-admin/src/Pages/MyAccount/BotpressAccount/KeyList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ActivateRevealKeyModal from '../../Components/Licensing/ActivateRevealKey
import UpdateLicenseModal from '../../Components/Licensing/UpdateLicenseModal'
import BuyLicenseModal from '../../Components/Licensing/BuyLicenseModal'
import LoadingSection from '../../Components/LoadingSection'
import { fetchAllKeys, fetchProducts, fetchLicensing, logoutUser } from '../../../reducers/license'
import { fetchAllKeys, fetchProducts, fetchLicensing, logoutUser, licenseUpdated } from '../../../reducers/license'

class KeyList extends Component {
state = {
Expand All @@ -29,6 +29,11 @@ class KeyList extends Component {

toggleBuyModal = () => this.setState({ buyModalOpen: !this.state.buyModalOpen })

onLicenseUpdated = license => {
this.props.licenseUpdated(license)
this.setState({ updateModalOpen: false })
}

toggleUpdateModal = selectedLicense => {
this.setState({
updateModalOpen: !this.state.updateModalOpen,
Expand Down Expand Up @@ -86,7 +91,7 @@ class KeyList extends Component {
products={this.props.products}
clusterFingerprint={clusterFingerprint}
onRevealActivate={this.toggleKeyModal}
onLicenseUpdated={this.toggleUpdateModal}
onLicenseUpdated={this.onLicenseUpdated}
/>
))}
</tbody>
Expand Down Expand Up @@ -171,7 +176,7 @@ class KeyList extends Component {

const mapStateToProps = state => ({ ...state.license })

const mapDispatchToProps = { fetchAllKeys, fetchProducts, fetchLicensing, logoutUser }
const mapDispatchToProps = { fetchAllKeys, fetchProducts, fetchLicensing, logoutUser, licenseUpdated }
export default connect(
mapStateToProps,
mapDispatchToProps
Expand Down
12 changes: 12 additions & 0 deletions src/bp/ui-admin/src/reducers/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const UPDATE_LICENSING_ACCOUNT = 'license/UPDATE_LICENSING_ACCOUNT'
export const FETCH_PRODUCTS_REQUESTED = 'license/FETCH_PRODUCTS_REQUESTED'
export const FETCH_PRODUCTS_RECEIVED = 'license/FETCH_PRODUCTS_RECEIVED'
export const LOGOUT_USER_FROM_LICENSE_SERVER = 'license/LOGOUT_USER_FROM_LICENSE_SERVER'
export const LICENSE_KEY_UPDATED = 'license/LICENSE_KEY_UPDATED'

const initialState = {
license: null,
Expand All @@ -22,6 +23,12 @@ const initialState = {

export default (state = initialState, action) => {
switch (action.type) {
case LICENSE_KEY_UPDATED:
const idx = state.keys.findIndex(k => k.stripeSubscriptionId === action.license.stripeSubscriptionId)
return {
...state,
keys: [...state.keys.slice(0, idx), action.license, ...state.keys.slice(idx + 1)]
}
case LOGOUT_USER_FROM_LICENSE_SERVER:
return {
...initialState
Expand Down Expand Up @@ -75,6 +82,11 @@ export default (state = initialState, action) => {
}
}

export const licenseUpdated = license => ({
type: LICENSE_KEY_UPDATED,
license
})

export const logoutUser = () => {
logout()
return {
Expand Down

0 comments on commit 1670eb1

Please sign in to comment.