LicenceStore.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright (C) 2019 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import { observable, action, runInAction } from 'mobx'
  16. import licenceSource from '../sources/LincenceSource'
  17. import type { Licence } from '../types/Licence'
  18. class LicenceStore {
  19. @observable loadingLicenceInfo: boolean = false
  20. @observable licenceInfo: ?Licence = null
  21. @observable addingLicence: boolean = false
  22. @action async loadLicenceInfo() {
  23. this.loadingLicenceInfo = true
  24. try {
  25. let licence = await licenceSource.loadLicenceInfo()
  26. runInAction(() => {
  27. this.licenceInfo = licence
  28. this.loadingLicenceInfo = false
  29. })
  30. } catch (ex) {
  31. runInAction(() => {
  32. this.loadingLicenceInfo = false
  33. })
  34. throw ex
  35. }
  36. }
  37. @action async addLicence(licence: string) {
  38. this.addingLicence = true
  39. try {
  40. await licenceSource.addLicence(licence)
  41. runInAction(() => {
  42. this.addingLicence = false
  43. })
  44. } catch (ex) {
  45. runInAction(() => {
  46. this.addingLicence = false
  47. })
  48. throw ex
  49. }
  50. }
  51. }
  52. export default new LicenceStore()