aboutsummaryrefslogtreecommitdiff
path: root/src/site/pages
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2021-06-17 16:06:53 +0300
committerZephyrrus <[email protected]>2021-06-17 16:06:53 +0300
commit0cae7e9eda3b62c17cfa7ec620913f4a504bc5ee (patch)
tree8573814b4c86f03390cf8e641a03bc8dc7572ec0 /src/site/pages
parentfeat: show setting values on the settings page and implement sending to backe... (diff)
downloadhost.fuwn.me-0cae7e9eda3b62c17cfa7ec620913f4a504bc5ee.tar.xz
host.fuwn.me-0cae7e9eda3b62c17cfa7ec620913f4a504bc5ee.zip
feat: show validation errors from joi on the frontend
Diffstat (limited to 'src/site/pages')
-rw-r--r--src/site/pages/dashboard/admin/settings.vue23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/site/pages/dashboard/admin/settings.vue b/src/site/pages/dashboard/admin/settings.vue
index 7346729..51e5ea8 100644
--- a/src/site/pages/dashboard/admin/settings.vue
+++ b/src/site/pages/dashboard/admin/settings.vue
@@ -15,7 +15,7 @@
<h5 class="title is-5 has-text-grey-lighter">
{{ sectionName }}
</h5>
- <JoiObject ref="jois" :settings="fields" />
+ <JoiObject ref="jois" :settings="fields" :errors="validationErrors" />
</div>
<div class="mb2 mt2 text-center">
@@ -42,6 +42,11 @@ export default {
JoiObject
},
middleware: ['auth', 'admin'],
+ data() {
+ return {
+ validationErrors: {}
+ };
+ },
computed: {
...mapState({
settings: state => state.admin.settings,
@@ -74,16 +79,24 @@ export default {
onConfirm: () => this.saveSettings()
});
},
- saveSettings() {
+ async saveSettings() {
// handle refs
let settings = {};
for (const joiComponent of this.$refs.jois) {
settings = { ...settings, ...joiComponent.getValues() };
}
- this.$handler.executeAction('admin/saveSettings', settings);
- // restart service
- // this.$handler.executeAction('admin/restartService');
+ try {
+ await this.$store.dispatch('admin/saveSettings', settings);
+ this.$set(this, 'validationErrors', {});
+
+ await this.$store.dispatch('config/fetchSettings');
+ this.$handler.executeAction('admin/restartService');
+ } catch (e) {
+ if (e.response?.data?.errors) {
+ this.$set(this, 'validationErrors', e.response.data.errors);
+ }
+ }
}
},
head() {