3a703 admin edit submission (#305)
* wip: admin submission edit feature * wip: refresh form submission after update * wip: connect submissions page data to store * Fixed the submission loading issue * test: admin edit submission feature test * Fix pending submission, editabe submission & more (#306) --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
58
client/stores/records.js
vendored
58
client/stores/records.js
vendored
@@ -1,49 +1,21 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const namespaced = true
|
||||
import { useContentStore } from '~/composables/stores/useContentStore'
|
||||
|
||||
/**
|
||||
* Loads records from database
|
||||
*/
|
||||
export const useRecordsStore = defineStore('records', {
|
||||
state: () => ({
|
||||
content: [],
|
||||
loading: false
|
||||
}),
|
||||
getters: {
|
||||
getById: (state) => (id) => {
|
||||
if (state.content.length === 0) return null
|
||||
return state.content.find(item => item.submission_id === id)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
set (items) {
|
||||
this.content = items
|
||||
},
|
||||
addOrUpdate (item) {
|
||||
this.content = this.content.filter((val) => val.id !== item.id)
|
||||
this.content.push(item)
|
||||
},
|
||||
remove (itemId) {
|
||||
this.content = this.content.filter((val) => val.id !== itemId)
|
||||
},
|
||||
startLoading () {
|
||||
this.loading = true
|
||||
},
|
||||
stopLoading () {
|
||||
this.loading = false
|
||||
},
|
||||
resetState () {
|
||||
this.set([])
|
||||
this.stopLoading()
|
||||
},
|
||||
loadRecord (request) {
|
||||
this.set([])
|
||||
this.startLoading()
|
||||
return request.then((data) => {
|
||||
this.addOrUpdate(data)
|
||||
this.stopLoading()
|
||||
})
|
||||
}
|
||||
export const useRecordsStore = defineStore('records', ()=>{
|
||||
|
||||
const contentStore = useContentStore()
|
||||
|
||||
const loadRecord = (request)=> {
|
||||
contentStore.resetState()
|
||||
contentStore.startLoading()
|
||||
return request.then((data) => {
|
||||
contentStore.save(data)
|
||||
contentStore.stopLoading()
|
||||
})
|
||||
}
|
||||
})
|
||||
return {...contentStore, loadRecord}
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user