Skip to content

Beautiful Open-Source Form Builder

Merge branch 'main' into vue-3

Forms Dev496ef9335386
diff --cc resources/js/components/open/forms/components/form-components/FormCustomSeo.vue
index 4fe2d2d07,feed7f6be..f7fe18473
--- a/resources/js/components/open/forms/components/form-components/FormCustomSeo.vue
+++ b/resources/js/components/open/forms/components/form-components/FormCustomSeo.vue
@@@ -46,8 -42,22 +49,22 @@@ export default
},
/* We add a setter */
set (value) {
- this.$store.commit('open/working_form/set', value)
+ this.workingFormStore.set(value)
}
+ },
+ workspace () {
+ return this.$store.getters['open/workspaces/getCurrent']()
+ },
+ customDomainOptions () {
+ return this.workspace.custom_domains.map((domain) => {
+ return {
+ name: domain,
+ value: domain
+ }
+ })
+ },
+ customDomainAllowed () {
+ return window.config.custom_domains_enabled
}
},
watch: {},
diff --cc resources/js/components/pages/forms/show/ExtraMenu.vue
index 703ad77ce,f74b58b93..78e1789b5
--- a/resources/js/components/pages/forms/show/ExtraMenu.vue
+++ b/resources/js/components/pages/forms/show/ExtraMenu.vue
@@@ -130,63 -145,57 +147,63 @@@ import Dropdown from '../../../common/D
import FormTemplateModal from '../../../open/forms/components/templates/FormTemplateModal.vue'
export default {
- name: 'ExtraMenu',
- components: { Dropdown, FormTemplateModal },
- props: {
- form: { type: Object, required: true },
- isMainPage: { type: Boolean, required: false, default: false }
- },
+ name: 'ExtraMenu',
+ components: { Dropdown, FormTemplateModal },
+ props: {
+ form: { type: Object, required: true },
+ isMainPage: { type: Boolean, required: false, default: false }
+ },
+
+ setup () {
+ const authStore = useAuthStore()
+ const formsStore = useFormsStore()
+ return {
+ formsStore,
+ user : computed(() => authStore.user)
+ }
+ },
- data: () => ({
- loadingDuplicate: false,
- loadingDelete: false,
- showDeleteFormModal: false,
- showFormTemplateModal: false
- }),
+ data: () => ({
+ loadingDuplicate: false,
+ loadingDelete: false,
+ showDeleteFormModal: false,
+ showFormTemplateModal: false
+ }),
- computed: {
- ...mapGetters({
- user: 'auth/user'
- }),
- formEndpoint: () => '/api/open/forms/{id}'
- },
-
- methods: {
- copyLink () {
- const el = document.createElement('textarea')
- el.value = this.form.share_url
- document.body.appendChild(el)
- el.select()
- document.execCommand('copy')
- document.body.removeChild(el)
- this.alertSuccess('Copied!')
- },
- duplicateForm () {
- if (this.loadingDuplicate) return
- this.loadingDuplicate = true
- axios.post(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate').then((response) => {
- this.$store.commit('open/forms/addOrUpdate', response.data.new_form)
- this.$router.push({ name: 'forms.show', params: { slug: response.data.new_form.slug } })
- this.alertSuccess('Form was successfully duplicated.')
- this.loadingDuplicate = false
- })
+ computed: {
+ formEndpoint: () => '/api/open/forms/{id}',
},
- deleteForm () {
- if (this.loadingDelete) return
- this.loadingDelete = true
- axios.delete(this.formEndpoint.replace('{id}', this.form.id)).then(() => {
- this.$store.commit('open/forms/remove', this.form)
- this.$router.push({ name: 'home' })
- this.alertSuccess('Form was deleted.')
- this.loadingDelete = false
- })
+
+ methods: {
+ copyLink(){
+ const el = document.createElement('textarea')
+ el.value = this.form.share_url
+ document.body.appendChild(el)
+ el.select()
+ document.execCommand('copy')
+ document.body.removeChild(el)
+ this.alertSuccess('Copied!')
+ },
+ duplicateForm() {
+ if (this.loadingDuplicate) return
+ this.loadingDuplicate = true
+ axios.post(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate').then((response) => {
+ this.formsStore.addOrUpdate(response.data.new_form)
+ this.$router.push({name: 'forms.show', params: {slug: response.data.new_form.slug}})
+ this.alertSuccess('Form was successfully duplicated.')
+ this.loadingDuplicate = false
+ })
+ },
+ deleteForm() {
+ if (this.loadingDelete) return
+ this.loadingDelete = true
+ axios.delete(this.formEndpoint.replace('{id}', this.form.id)).then(() => {
+ this.formsStore.remove(this.form)
+ this.$router.push({name: 'home'})
+ this.alertSuccess('Form was deleted.')
+ this.loadingDelete = false
+ })
+ },
}
- }
}
</script>
diff --cc resources/js/pages/forms/show/index.vue
index 812782e97,828d1b36a..e4a1b5285
--- a/resources/js/pages/forms/show/index.vue
+++ b/resources/js/pages/forms/show/index.vue
@@@ -209,13 -186,19 +209,13 @@@ export default
},
computed: {
- ...mapGetters({
- user: 'auth/user'
- }),
- ...mapState({
- formsLoading: state => state['open/forms'].loading,
- workspacesLoading: state => state['open/workspaces'].loading
- }),
workingForm: {
-- get () {
- return this.$store.state['open/working_form'].content
++ get () {
+ return this.workingFormStore.content
},
+ /* We add a setter */
set (value) {
- this.$store.commit('open/working_form/set', value)
+ this.workingFormStore.set(value)
}
},
workspace () {
diff --cc resources/js/pages/settings/workspace.vue
index 231763a59,0ff63d3f4..e0456382e
--- a/resources/js/pages/settings/workspace.vue
+++ b/resources/js/pages/settings/workspace.vue
@@@ -73,27 -115,17 +115,31 @@@
</template>
<script>
+import { computed } from 'vue'
import Form from 'vform'
-import { mapActions, mapState } from 'vuex'
+import { useFormsStore } from '../../stores/forms'
+import { useWorkspacesStore } from '../../stores/workspaces'
import SeoMeta from '../../mixins/seo-meta.js'
+ import TextAreaInput from '../../components/forms/TextAreaInput.vue'
+ import axios from 'axios'
+ import * as domain from 'domain'
export default {
- components: {},
+ components: { TextAreaInput },
+ mixins: [SeoMeta],
scrollToTop: false,
+ mixins: [SeoMeta],
+
+ setup () {
+ const formsStore = useFormsStore()
+ const workspacesStore = useWorkspacesStore()
+ return {
+ formsStore,
+ workspacesStore,
+ workspaces: computed(() => workspacesStore.content),
+ loading: computed(() => workspacesStore.loading)
+ }
+ },
data: () => ({
metaTitle: 'Workspaces',
@@@ -101,24 -133,61 +147,54 @@@
name: '',
emoji: ''
}),
- workspaceModal: false
+ workspaceModal: false,
+ customDomains: '',
+ customDomainsLoading: false
}),
- mounted() {
+ mounted () {
- this.loadWorkspaces()
+ this.workspacesStore.loadIfEmpty()
+ this.initCustomDomains()
},
- computed: {},
+ computed: {
- ...mapState({
- workspaces: state => state['open/workspaces'].content,
- loading: state => state['open/workspaces'].loading
- }),
+ workspace () {
- return this.$store.getters['open/workspaces/getCurrent']()
++ return this.workspacesStore.getCurrent()
+ },
+ customDomainsEnabled () {
+ return window.config.custom_domains_enabled
+ }
+ },
methods: {
- switchWorkspace(workspace) {
- this.workspacesStore.setCurrentId(workspace.id)
- this.$router.push({name: 'home'})
- this.formsStore.load(workspace.id)
- ...mapActions({
- loadWorkspaces: 'open/workspaces/loadIfEmpty'
- }),
+ saveChanges () {
+ if (this.customDomainsLoading) return
+ this.customDomainsLoading = true
+ // Update the workspace custom domain
+ axios.put('/api/open/workspaces/' + this.workspace.id + '/custom-domains', {
+ custom_domains: this.customDomains.split('\n')
+ .map(domain => domain.trim())
+ .filter(domain => domain && domain.length > 0)
+ }).then((response) => {
- this.$store.commit('open/workspaces/addOrUpdate', response.data)
++ this.workspacesStore.addOrUpdate(response.data)
+ this.alertSuccess('Custom domains saved.')
+ }).catch((error) => {
+ this.alertError('Failed to update custom domains: ' + error.response.data.message)
+ }).finally(() => {
+ this.customDomainsLoading = false
+ })
+ },
+ initCustomDomains () {
+ if (!this.workspace) return
+ this.customDomains = this.workspace.custom_domains.join('\n')
},
- deleteWorkspace(workspace) {
+ deleteWorkspace (workspace) {
+ if (this.workspaces.length <= 1) {
+ this.alertError('You cannot delete your only workspace.')
+ return
+ }
this.alertConfirm('Do you really want to delete this workspace? All forms created in this workspace will be removed.', () => {
- this.$store.dispatch('open/workspaces/delete', workspace.id).then(() => {
+ this.workspacesStore.delete(workspace.id).then(() => {
this.alertSuccess('Workspace successfully removed.')
})
})
@@@ -132,11 -201,17 +208,17 @@@
'(\\#[-a-z\\d_]*)?$', 'i') // fragment locator
return !!pattern.test(str)
},
- async createWorkspace () {
- const { data } = await this.form.post('/api/open/workspaces/create')
- this.$store.dispatch('open/workspaces/load')
+ async createWorkspace() {
+ const {data} = await this.form.post('/api/open/workspaces/create')
+ this.workspacesStore.load()
this.workspaceModal = false
}
+ },
+
+ watch: {
+ workspace () {
+ this.initCustomDomains()
+ }
}
}
</script>
diff --cc resources/js/router/index.js
index b9dec2a21,8004e5d0f..0acc35746
--- a/resources/js/router/index.js
+++ b/resources/js/router/index.js
@@@ -1,11 -1,16 +1,11 @@@
-import Vue from 'vue'
-import store from '~/store'
-import Meta from 'vue-meta'
import routes from './routes'
-import Router from 'vue-router'
-import { sync } from 'vuex-router-sync'
+import { createWebHistory, createRouter } from 'vue-router'
import * as Sentry from '@sentry/vue'
-
-Vue.use(Meta)
-Vue.use(Router)
+import { useAppStore } from '../stores/app'
+import { defineComponent, nextTick } from 'vue'
// The middleware for every page of the application.
- const globalMiddleware = ['check-auth', 'notion-connection']
+ const globalMiddleware = ['locale', 'check-auth', 'custom-domains']
// Load middleware modules dynamically.
const requireContext = import.meta.glob('../middleware/**/*.js', { eager: true })
diff --cc resources/js/stores/workspaces.js
index 96c4df6e8,000000000..de71db97e
mode 100644,000000..100644
--- a/resources/js/stores/workspaces.js
+++ b/resources/js/stores/workspaces.js
@@@ -1,93 -1,0 +1,97 @@@
+import axios from 'axios'
+import { defineStore } from 'pinia'
+
+export const namespaced = true
+export const workspaceEndpoint = '/api/open/workspaces/'
+
+const localStorageCurrentWorkspaceKey = 'currentWorkspace'
+
+export const useWorkspacesStore = defineStore('workspaces', {
+ state: () => ({
+ content: [],
+ currentId: null,
+ loading: false
+ }),
+ getters: {
+ getById: (state) => (id) => {
+ if (state.content.length === 0) return null
+ return state.content.find(item => item.id === id)
+ },
+ getCurrent: (state) => () => {
+ if (state.content.length === 0 || state.currentId === null) return null
+ return state.content.find(item => item.id === state.currentId)
+ }
+ },
+ actions: {
+ set (items) {
+ this.content = items
+ if (this.currentId == null && this.content.length > 0) {
+ // If one only, set it
+ if (this.content.length === 1) {
+ this.currentId = items[0].id
+ localStorage.setItem(localStorageCurrentWorkspaceKey, this.currentId)
+ } else if (localStorage.getItem(localStorageCurrentWorkspaceKey) && this.content.find(item => item.id === parseInt(localStorage.getItem(localStorageCurrentWorkspaceKey)))) {
+ // Check local storage for current workspace, or take first
+ this.currentId = parseInt(localStorage.getItem(localStorageCurrentWorkspaceKey))
+ localStorage.setItem(localStorageCurrentWorkspaceKey, this.currentId)
+ } else {
+ // Else, take first
+ this.currentId = items[0].id
+ localStorage.setItem(localStorageCurrentWorkspaceKey, this.currentId)
+ }
+ } else {
+ localStorage.removeItem(localStorageCurrentWorkspaceKey)
+ }
+ },
+ setCurrentId (id) {
+ this.currentId = id
+ localStorage.setItem(localStorageCurrentWorkspaceKey, id)
+ },
+ addOrUpdate (item) {
+ this.content = this.content.filter((val) => val.id !== item.id)
+ this.content.push(item)
+ if (this.currentId == null) {
+ this.currentId = item.id
+ localStorage.setItem(localStorageCurrentWorkspaceKey, this.currentId)
+ }
+ },
+ remove (itemId) {
+ this.content = this.content.filter((val) => val.id !== itemId)
++ if (this.currentId === itemId) {
++ this.currentId = this.content.length > 0 ? this.content[0].id : null
++ localStorage.setItem(localStorageCurrentWorkspaceKey, this.currentId)
++ }
+ },
+ startLoading () {
+ this.loading = true
+ },
+ stopLoading () {
+ this.loading = false
+ },
+ resetState () {
+ this.set([])
+ this.stopLoading()
+ },
+ load () {
+ this.set([])
+ this.startLoading()
+ return axios.get(workspaceEndpoint).then((response) => {
+ this.set(response.data)
+ this.stopLoading()
+ })
+ },
+ loadIfEmpty () {
+ if (this.content.length === 0) {
+ return this.load()
+ }
+ return Promise.resolve()
+ },
+ delete (id) {
+ this.startLoading()
+ return axios.delete(workspaceEndpoint + id).then((response) => {
+ this.remove(response.data.workspace_id)
+ this.stopLoading()
+ })
+ }
+ }
+})
diff --cc vite.config.js
index 54e598769,03933665f..6e7acb956
--- a/vite.config.js
+++ b/vite.config.js
@@@ -49,8 -45,13 +50,14 @@@ export default defineConfig(
resolve: {
alias: {
'~': '/resources/js',
- '@': '/resources'
+ '@': '/resources',
+ vue: '@vue/compat'
}
+ },
+ server: {
+ hmr: {
+ host: 'localhost',
+ protocol: 'ws'
+ }
}
})