# ivyforms/0.6/frontend/src/stores/useEntry.ts

The Innovative Form Builder – IvyForms, version 0.6. 58 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.6/code/frontend/src/stores/useEntry.ts
- Raw: https://pluginprobe.com/plugins/ivyforms/0.6/raw/frontend/src/stores/useEntry.ts
- Modified: 2025-11-19T18:42:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.6/code/frontend/src/stores/useEntry.ts#L10-L20`.

```typescript
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApiClient } from '@/composables/useApiClient.ts'
import IvyMessage from '@/views/_components/message/ivyMessage.ts'
import { useLabels } from '@/composables/useLabels.ts'
import { useAllEntries } from '@/stores/useAllEntries.ts'

export const useEntry = defineStore('entry', () => {
  const entry = ref(null)
  const entryFields = ref([])
  const loading = ref(false)
  const error = ref(null)
  const { getLabel } = useLabels()
  const { request } = useApiClient()
  const allEntriesStore = useAllEntries()

  const fetchEntry = async (id: number) => {
    try {
      const { data, error, status } = await request(`entry/${id}`, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
        },
      })
      if (!error && status === 200 && data?.data) {
        entry.value = data.data.entry
        entryFields.value = data.data.fields || []
        loading.value = false

        // Mark the entry as read
        if (entry.value.status === 'unread') {
          await allEntriesStore.updateStatus(id, 'read')
          entry.value.status = 'read'
        }
      } else {
        IvyMessage({
          message: getLabel('failed_to_get_entry'),
          type: 'error',
        })
        console.error(getLabel('failed_to_get_entry'), data?.message)
      }
    } catch (error) {
      IvyMessage({
        message: `${getLabel('failed_to_get_entry')} ${error}`,
        type: 'error',
      })
    }
  }

  return {
    entry,
    entryFields,
    loading,
    error,
    fetchEntry,
  }
})

```
