Vue3: migrating from vuex to Pinia (#249)

* Vue3: migrating from vuex to Pinia

* toggle input fixes

* update configureCompat

---------

Co-authored-by: Forms Dev <chirag+new@notionforms.io>
This commit is contained in:
Chirag Chhatrala
2023-12-01 23:27:14 +05:30
committed by GitHub
parent af30067eda
commit 47653ebe64
105 changed files with 2092 additions and 1577 deletions

View File

@@ -31,18 +31,23 @@
</template>
<script>
import { mapGetters } from 'vuex'
import { computed } from 'vue'
import { useAuthStore } from '../../stores/auth'
export default {
setup () {
const authStore = useAuthStore()
return {
user : computed(() => authStore.user)
}
},
data: () => ({
appName: window.config.appName,
currYear: new Date().getFullYear(),
}),
computed: {
...mapGetters({
user: 'auth/user'
}),
helpUrl: () => window.config.links.help_url,
githubUrl: () => window.config.links.github_url,
forumUrl: () => window.config.links.github_forum_url,

View File

@@ -24,28 +24,34 @@
</template>
<script>
import { mapGetters } from 'vuex'
import { computed } from 'vue'
import { useAuthStore } from '../../stores/auth';
import { useWorkspacesStore } from '../../stores/workspaces';
export default {
setup () {
const authStore = useAuthStore()
const workspacesStore = useWorkspacesStore()
return {
authStore,
workspacesStore,
isImpersonating : computed(() => authStore.isImpersonating),
}
},
data: () => ({
loading: false
}),
computed: {
...mapGetters({
isImpersonating: 'auth/isImpersonating'
})
},
computed: {},
mounted () {
},
mounted () {},
methods: {
reverseImpersonation () {
this.loading = true
this.$store.dispatch('auth/stopImpersonating')
.then(() => {
this.$store.commit('open/workspaces/set', [])
this.authStore.stopImpersonating().then(() => {
this.workspacesStore.set([])
this.$router.push({ name: 'settings.admin' })
this.loading = false
})

View File

@@ -62,14 +62,22 @@
</template>
<script>
import { computed } from 'vue'
import axios from 'axios'
import { mapGetters } from 'vuex'
import { useAuthStore } from '../../../stores/auth';
import VTransition from '../../common/transitions/VTransition.vue'
export default {
components: { VTransition },
props: {},
setup () {
const authStore = useAuthStore()
return {
user : computed(() => authStore.user)
}
},
data: () => ({
changelogEntries: [],
showNewFeatures: false
@@ -80,9 +88,6 @@ export default {
},
computed: {
...mapGetters({
user: 'auth/user'
}),
requestFeatureLink () {
return window.config.links.feature_requests
},

View File

@@ -122,8 +122,10 @@
</template>
<script>
import { computed } from 'vue'
import axios from 'axios'
import {mapGetters, mapState} from 'vuex'
import { useAuthStore } from '../../../../stores/auth'
import { useFormsStore } from '../../../../stores/forms'
import Dropdown from '../../../common/Dropdown.vue'
import FormTemplateModal from '../../../open/forms/components/templates/FormTemplateModal.vue'
@@ -135,6 +137,15 @@ export default {
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,
@@ -143,9 +154,6 @@ export default {
}),
computed: {
...mapGetters({
user: 'auth/user'
}),
formEndpoint: () => '/api/open/forms/{id}',
},
@@ -163,7 +171,7 @@ export default {
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.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
@@ -173,7 +181,7 @@ export default {
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.formsStore.remove(this.form)
this.$router.push({name: 'home'})
this.alertSuccess('Form was deleted.')
this.loadingDelete = false

View File

@@ -72,7 +72,9 @@
</template>
<script>
import { computed } from 'vue'
import axios from 'axios'
import { useFormsStore } from '../../../../stores/forms'
export default {
name: 'RegenerateFormLink',
@@ -81,6 +83,13 @@ export default {
form: { type: Object, required: true }
},
setup () {
const formsStore = useFormsStore()
return {
formsStore
}
},
data: () => ({
loadingNewLink: false,
showGenerateFormLinkModal: false,
@@ -95,7 +104,7 @@ export default {
if (this.loadingNewLink) return
this.loadingNewLink = true
axios.put(this.formEndpoint.replace('{id}', this.form.id) + '/regenerate-link/' + option).then((response) => {
this.$store.commit('open/forms/addOrUpdate', response.data.form)
this.formsStore.addOrUpdate(response.data.form)
this.$router.push({name: 'forms.show', params: {slug: response.data.form.slug}})
this.alertSuccess(response.data.message)
this.loadingNewLink = false

View File

@@ -11,14 +11,14 @@
</template>
<script>
import { mapGetters } from 'vuex'
import TextInput from '../../forms/TextInput.vue'
import Form from 'vform'
import VButton from '../../common/Button.vue'
import { computed } from 'vue'
import axios from 'axios'
import Form from 'vform'
import { useAuthStore } from '../../../stores/auth'
import TextInput from '../../forms/TextInput.vue'
import VButton from '../../common/Button.vue'
export default {
components: { VButton, TextInput },
props: {
show: {
@@ -34,6 +34,14 @@ export default {
default: true
}
},
setup () {
const authStore = useAuthStore()
return {
user : computed(() => authStore.user)
}
},
data: () => ({
form: new Form({
name: '',
@@ -88,10 +96,6 @@ export default {
}
},
computed: {
...mapGetters({
user: 'auth/user'
})
}
computed: {}
}
</script>

View File

@@ -107,7 +107,8 @@
</template>
<script>
import { mapGetters } from 'vuex'
import { computed } from 'vue'
import { useAuthStore } from '../../../stores/auth'
import axios from 'axios'
import MonthlyYearlySelector from './MonthlyYearlySelector.vue'
import CheckoutDetailsModal from './CheckoutDetailsModal.vue'
@@ -127,6 +128,13 @@ export default {
default: false
}
},
setup () {
const authStore = useAuthStore()
return {
authenticated : computed(() => authStore.check),
user : computed(() => authStore.user)
}
},
data: () => ({
isYearly: true,
selectedPlan: 'pro',
@@ -160,11 +168,6 @@ export default {
}
},
computed: {
...mapGetters({
authenticated: 'auth/check',
user: 'auth/user'
})
}
computed: {}
}
</script>

View File

@@ -39,7 +39,8 @@
</template>
<script>
import store from '~/store'
import { computed } from 'vue'
import { useTemplatesStore } from '../../../stores/templates'
import TemplateTags from './TemplateTags.vue'
export default {
@@ -52,22 +53,29 @@ export default {
}
},
setup () {
const templatesStore = useTemplatesStore()
return {
templatesStore
}
},
data: () => ({}),
computed: {
template () {
return this.$store.getters['open/templates/getBySlug'](this.slug)
return this.templatesStore.getBySlug(this.slug)
}
},
watch: {
slug () {
store.dispatch('open/templates/loadTemplate', this.slug)
this.templatesStore.loadTemplate(this.slug)
}
},
mounted () {
store.dispatch('open/templates/loadTemplate', this.slug)
this.templatesStore.loadTemplate(this.slug)
},
methods: {

View File

@@ -41,6 +41,9 @@
</template>
<script>
import { computed } from 'vue'
import { useTemplatesStore } from '../../../stores/templates'
export default {
props: {
slug: {
@@ -53,19 +56,26 @@ export default {
}
},
setup () {
const templatesStore = useTemplatesStore()
return {
templatesStore
}
},
data: () => ({}),
computed: {
template () {
return this.$store.getters['open/templates/getBySlug'](this.slug)
return this.templatesStore.getBySlug(this.slug)
},
types () {
if (!this.template) return null
return this.$store.getters['open/templates/getTemplateTypes'](this.template.types)
return this.templatesStore.getTemplateTypes(this.template.types)
},
industries () {
if (!this.template) return null
return this.$store.getters['open/templates/getTemplateIndustries'](this.template.industries)
return this.templatesStore.getTemplateIndustries(this.template.industries)
}
},

View File

@@ -79,24 +79,25 @@
</template>
<script>
import store from '~/store'
import { mapGetters, mapState } from 'vuex'
import { computed } from 'vue'
import { useAuthStore } from '../../../stores/auth'
import { useTemplatesStore } from '../../../stores/templates'
import Form from 'vform'
import Fuse from 'fuse.js'
import SingleTemplate from './SingleTemplate.vue'
const loadTemplates = function (onlyMy) {
const templatesStore = useTemplatesStore()
if(onlyMy){
store.dispatch('open/templates/loadAll', {'onlymy':true})
templatesStore.loadAll({'onlymy':true})
} else {
store.dispatch('open/templates/loadIfEmpty')
templatesStore.loadIfEmpty()
}
}
export default {
name: 'TemplatesList',
components: { SingleTemplate },
props: {
onlyMy: {
type: Boolean,
@@ -104,6 +105,18 @@ export default {
}
},
setup () {
const authStore = useAuthStore()
const templatesStore = useTemplatesStore()
return {
user : computed(() => authStore.user),
templates : computed(() => templatesStore.content),
templatesLoading : computed(() => templatesStore.loading),
industries : computed(() => templatesStore.industries),
types : computed(() => templatesStore.types)
}
},
data: () => ({
selectedType: 'all',
selectedIndustry: 'all',
@@ -119,15 +132,6 @@ export default {
},
computed: {
...mapState({
templates: state => state['open/templates'].content,
templatesLoading: state => state['open/templates'].loading,
industries: state => state['open/templates'].industries,
types: state => state['open/templates'].types
}),
...mapGetters({
user: 'auth/user'
}),
industriesOptions () {
return [{ name: 'All Industries', value: 'all' }].concat(Object.values(this.industries).map((industry) => {
return {

View File

@@ -87,16 +87,19 @@
</template>
<script>
import {mapGetters} from 'vuex'
import { computed } from 'vue'
import { useAuthStore } from '../../../stores/auth'
export default {
props: {},
data: () => ({}),
computed: {
...mapGetters({
authenticated: 'auth/check'
}),
},
methods: {}
setup () {
const authStore = useAuthStore()
return {
authenticated : computed(() => authStore.check)
}
},
props: {},
data: () => ({}),
computed: {},
methods: {}
}
</script>

View File

@@ -36,19 +36,23 @@
</template>
<script>
import store from '~/store'
import { mapGetters, mapState } from 'vuex'
import { computed } from 'vue'
import { useTemplatesStore } from '../../../stores/templates'
import SingleTemplate from '../templates/SingleTemplate.vue'
export default {
components: { SingleTemplate },
props: { },
setup () {
const templatesStore = useTemplatesStore()
return {
templatesStore,
templates : computed(() => templatesStore.content)
}
},
data: () => ({}),
computed: {
...mapState({
templates: state => state['open/templates'].content
}),
sliderTemplates () {
return this.templates.slice(0, 20)
}
@@ -66,7 +70,7 @@ export default {
},
mounted() {
store.dispatch('open/templates/loadAll', { limit: 20 })
this.templatesStore.loadAll({ limit: 20 })
},
methods: {