Add frontend/src/stores/workspace.js
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import axios from 'axios'
|
||||
|
||||
export const useWorkspaceStore = defineStore('workspace', {
|
||||
state: () => ({
|
||||
workspaces: [],
|
||||
currentWorkspace: null
|
||||
}),
|
||||
actions: {
|
||||
async fetchWorkspaces() {
|
||||
try {
|
||||
const response = await axios.get('/api/v1/workspaces')
|
||||
this.workspaces = response.data
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch workspaces:', error)
|
||||
}
|
||||
},
|
||||
async createWorkspace(name, description) {
|
||||
try {
|
||||
const response = await axios.post('/api/v1/workspaces', { name, description })
|
||||
this.workspaces.push(response.data)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error('Failed to create workspace:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
async deleteWorkspace(id) {
|
||||
try {
|
||||
await axios.delete(`/api/v1/workspaces/${id}`)
|
||||
this.workspaces = this.workspaces.filter(w => w.id !== id)
|
||||
} catch (error) {
|
||||
console.error('Failed to delete workspace:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user