PluginProbe
The Innovative Form Builder – IvyForms / 1.1
The Innovative Form Builder – IvyForms v1.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / stores / useEntry.ts

useEntry.ts in The Innovative Form Builder – IvyForms 1.1, at frontend/src/stores/useEntry.ts

58 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { defineStore } from 'pinia'
2 import { ref } from 'vue'
3 import { useApiClient } from '@/composables/useApiClient.ts'
4 import IvyMessage from '@/views/_components/message/ivyMessage.ts'
5 import { useLabels } from '@/composables/useLabels.ts'
6 import { useAllEntries } from '@/stores/useAllEntries.ts'
7
8 export const useEntry = defineStore('entry', () => {
9 const entry = ref(null)
10 const entryFields = ref([])
11 const loading = ref(false)
12 const error = ref(null)
13 const { getLabel } = useLabels()
14 const { request } = useApiClient()
15 const allEntriesStore = useAllEntries()
16
17 const fetchEntry = async (id: number) => {
18 try {
19 const { data, error, status } = await request(`entry/${id}`, {
20 method: 'GET',
21 headers: {
22 'Content-Type': 'application/json',
23 },
24 })
25 if (!error && status === 200 && data?.data) {
26 entry.value = data.data.entry
27 entryFields.value = data.data.fields || []
28 loading.value = false
29
30 // Mark the entry as read
31 if (entry.value.status === 'unread') {
32 await allEntriesStore.updateStatus(id, 'read')
33 entry.value.status = 'read'
34 }
35 } else {
36 IvyMessage({
37 message: `${getLabel('failed_to_get_entry')} ${data?.message || ''}`,
38 type: 'error',
39 })
40 console.error(getLabel('failed_to_get_entry'), data?.message)
41 }
42 } catch (error) {
43 IvyMessage({
44 message: `${getLabel('failed_to_get_entry')} ${error}`,
45 type: 'error',
46 })
47 }
48 }
49
50 return {
51 entry,
52 entryFields,
53 loading,
54 error,
55 fetchEntry,
56 }
57 })
58