mandant-crm/frontend/composables/useHistory.ts
Tim Stollberg 570f17e8b8 feat(frontend): commit uncommitted settings, custom fields, and import work
This local working tree had accumulated a substantial amount of
finished-but-never-committed frontend work: custom client fields
(replacing the old static ClientFields with a dynamic
ClientCustomFieldCard + useCustomFields), CSV import
(useImport + settings/import page), history type management
(useHistoryTypes + settings/history-types page), an admin-only route
middleware, several new icon components, a shared useApiFetch
composable, and a client detail page restructure ([id].vue ->
[id]/index.vue). None of it had ever been pushed, so production was
running a stale build that was already linking to routes/components
that didn't exist server-side (missing IconSettings, 404s on
/settings/import, etc). This commit brings the repo in line with
local state.
2026-07-18 16:27:19 +07:00

42 lines
1.1 KiB
TypeScript

import type { HistoryEntry } from '~/types'
export const useHistory = (clientId: number) => {
const entries = ref<HistoryEntry[]>([])
const fetchEntries = async (): Promise<void> => {
const response = await useApiFetch<{ data: HistoryEntry[] }>(`/api/clients/${clientId}/history`)
entries.value = response.data
}
const addEntry = async (payload: {
history_entry_type_id: number
body: string
occurred_at: string | null
}): Promise<void> => {
await useApiFetch(`/api/clients/${clientId}/history`, {
method: 'POST',
body: payload,
})
await fetchEntries()
}
const updateEntry = async (
id: number,
payload: { body: string; occurred_at: string | null }
): Promise<void> => {
await useApiFetch(`/api/history/${id}`, {
method: 'PUT',
body: payload,
})
await fetchEntries()
}
const deleteEntry = async (id: number): Promise<void> => {
await useApiFetch(`/api/history/${id}`, {
method: 'DELETE',
})
entries.value = entries.value.filter(e => e.id !== id)
}
return { entries, fetchEntries, addEntry, updateEntry, deleteEntry }
}