AdminForumInfo.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div class='admin_forum_info category_widget__box'>
  3. <div class='cateogry_widget__text'>
  4. <div class='category_widget__text__title'>Forum info</div>
  5. </div>
  6. <fancy-input
  7. placeholder='Forum name'
  8. v-model='name'
  9. :error='errors.forumName'
  10. ></fancy-input>
  11. <fancy-input
  12. placeholder='Forum description'
  13. v-model='description'
  14. :error='errors.forumDescription'
  15. ></fancy-input>
  16. <loading-button :loading='loading' @click='save'>Save settings</loading-button>
  17. </div>
  18. </template>
  19. <script>
  20. import FancyInput from './FancyInput'
  21. import LoadingButton from './LoadingButton'
  22. import AjaxErrorHandler from '../assets/js/errorHandler'
  23. export default {
  24. name: 'AdminForumInfo',
  25. components: {
  26. FancyInput,
  27. LoadingButton
  28. },
  29. data () {
  30. return {
  31. name: '',
  32. description: '',
  33. loading: false,
  34. errors: {
  35. forumName: '',
  36. forumDescription: ''
  37. }
  38. }
  39. },
  40. methods: {
  41. save () {
  42. this.errors.forumName = ''
  43. this.errors.forumDescription = ''
  44. if(!this.name.trim().length) {
  45. this.errors.forumName = 'Forum name can\'t be blank'
  46. return
  47. }
  48. this.loading = true
  49. let settingsReq = this.axios.put('/api/v1/settings', {
  50. forumName: this.name,
  51. forumDescription: this.description
  52. })
  53. settingsReq.then(res => {
  54. this.loading = false
  55. this.$store.commit('setForumName', res.data.forumName)
  56. }).catch(e => {
  57. this.loading = false
  58. AjaxErrorHandler(this.$store)(err, (error, modalErrors) => {
  59. if(this.errors[error.path] !== undefined) {
  60. this.errors[error.path] = error.message
  61. } else {
  62. modalErrors.push(error.message)
  63. }
  64. })
  65. })
  66. }
  67. },
  68. mounted () {
  69. this.axios
  70. .get('/api/v1/settings')
  71. .then(res => {
  72. this.name = res.data.forumName || ''
  73. this.description = res.data.forumDescription || ''
  74. })
  75. .catch(AjaxErrorHandler(this.$store))
  76. }
  77. }
  78. </script>
  79. <style lang='scss' scoped>
  80. @import '../assets/scss/variables.scss';
  81. .admin_forum_info {
  82. }
  83. </style>