WIP - scaffold approvals
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
SidebarRail,
|
||||
} from '@/components/ui/sidebar'
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
|
||||
import { LayoutGrid, Boxes, Settings, Home, ChevronRight, Database, Layers, LogOut, Users, Globe, Building, Phone } from 'lucide-vue-next'
|
||||
import { LayoutGrid, Boxes, Settings, Home, ChevronRight, Database, Layers, LogOut, Users, Globe, Building, ClipboardCheck, ListChecks, ClipboardList, Phone } from 'lucide-vue-next'
|
||||
import { useSoftphone } from '~/composables/useSoftphone'
|
||||
|
||||
const { logout } = useAuth()
|
||||
@@ -100,6 +100,21 @@ const staticMenuItems = [
|
||||
url: '/',
|
||||
icon: Home,
|
||||
},
|
||||
{
|
||||
title: 'Approvals',
|
||||
url: '/approvals',
|
||||
icon: ClipboardCheck,
|
||||
},
|
||||
{
|
||||
title: 'Tasks',
|
||||
url: '/tasks',
|
||||
icon: ListChecks,
|
||||
},
|
||||
{
|
||||
title: 'Activity Log',
|
||||
url: '/activity-log',
|
||||
icon: ClipboardList,
|
||||
},
|
||||
{
|
||||
title: 'Setup',
|
||||
icon: Settings,
|
||||
@@ -124,6 +139,11 @@ const staticMenuItems = [
|
||||
url: '/setup/roles',
|
||||
icon: Layers,
|
||||
},
|
||||
{
|
||||
title: 'Approvals',
|
||||
url: '/setup/approvals',
|
||||
icon: ClipboardCheck,
|
||||
},
|
||||
{
|
||||
title: 'Integrations',
|
||||
url: '/settings/integrations',
|
||||
|
||||
70
frontend/pages/activity-log/index.vue
Normal file
70
frontend/pages/activity-log/index.vue
Normal file
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background">
|
||||
<NuxtLayout name="default">
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div v-if="loading" class="text-center py-12">Loading...</div>
|
||||
<div v-else-if="error" class="text-destructive">Error: {{ error }}</div>
|
||||
<div v-else>
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Activity Log</h1>
|
||||
<button
|
||||
@click="fetchActivities"
|
||||
class="px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90"
|
||||
>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4">
|
||||
<div
|
||||
v-for="activity in activities"
|
||||
:key="activity.id"
|
||||
class="p-6 border rounded-lg bg-card"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h3 class="text-lg font-semibold">{{ activity.action }}</h3>
|
||||
<span class="text-xs text-muted-foreground">{{ formatDate(activity.createdAt) }}</span>
|
||||
</div>
|
||||
<p class="text-sm text-muted-foreground mb-2">
|
||||
{{ activity.description || 'No description' }}
|
||||
</p>
|
||||
<div class="text-sm text-muted-foreground">
|
||||
<div>Subject: {{ activity.subjectType }} • {{ activity.subjectId }}</div>
|
||||
<div>Causer: {{ activity.causerId || 'System' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</NuxtLayout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { api } = useApi()
|
||||
|
||||
const activities = ref<any[]>([])
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
const formatDate = (value?: string) => {
|
||||
if (!value) return '—'
|
||||
const date = new Date(value)
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
const fetchActivities = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
activities.value = await api.get('/activity-log')
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchActivities()
|
||||
})
|
||||
</script>
|
||||
232
frontend/pages/approvals/index.vue
Normal file
232
frontend/pages/approvals/index.vue
Normal file
@@ -0,0 +1,232 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background">
|
||||
<NuxtLayout name="default">
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div v-if="loading" class="text-center py-12">Loading...</div>
|
||||
<div v-else-if="error" class="text-destructive">Error: {{ error }}</div>
|
||||
<div v-else>
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Approval Requests</h1>
|
||||
<button
|
||||
@click="showCreateForm = true"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
New Request
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="showCreateForm" class="mb-6 p-6 border rounded-lg bg-card">
|
||||
<h2 class="text-xl font-semibold mb-4">Create Approval Request</h2>
|
||||
<form @submit.prevent="createRequest" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Definition</label>
|
||||
<select
|
||||
v-model="newRequest.definitionId"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
>
|
||||
<option value="" disabled>Select a definition</option>
|
||||
<option v-for="definition in definitions" :key="definition.id" :value="definition.id">
|
||||
{{ definition.name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Target Object Type</label>
|
||||
<input
|
||||
v-model="newRequest.targetObjectType"
|
||||
type="text"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="Expense"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Target Object ID</label>
|
||||
<input
|
||||
v-model="newRequest.targetObjectId"
|
||||
type="text"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="record-id"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Action</label>
|
||||
<input
|
||||
v-model="newRequest.action"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="submit"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Submitted By (User ID)</label>
|
||||
<input
|
||||
v-model="newRequest.submittedById"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="user-id"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Snapshot (JSON)</label>
|
||||
<textarea
|
||||
v-model="newRequest.snapshot"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background font-mono text-sm"
|
||||
rows="3"
|
||||
placeholder='{"amount": 1200, "currency": "USD"}'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Field Changes (JSON)</label>
|
||||
<textarea
|
||||
v-model="newRequest.fieldChanges"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background font-mono text-sm"
|
||||
rows="3"
|
||||
placeholder='{"amount": {"from": 500, "to": 1200}}'
|
||||
/>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
Create
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="showCreateForm = false"
|
||||
class="px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4">
|
||||
<div
|
||||
v-for="request in requests"
|
||||
:key="request.id"
|
||||
class="p-6 border rounded-lg bg-card"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold">{{ request.definition?.name || 'Approval Request' }}</h3>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ request.targetObjectType }} • {{ request.targetObjectId }}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
class="text-xs px-2 py-1 rounded"
|
||||
:class="statusClass(request.status)"
|
||||
>
|
||||
{{ request.status }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-sm text-muted-foreground">
|
||||
<div>Steps: {{ request.steps?.length || 0 }}</div>
|
||||
<div>Submitted: {{ formatDate(request.submittedAt) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</NuxtLayout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { api } = useApi()
|
||||
|
||||
const requests = ref<any[]>([])
|
||||
const definitions = ref<any[]>([])
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
const showCreateForm = ref(false)
|
||||
const newRequest = ref({
|
||||
definitionId: '',
|
||||
targetObjectType: '',
|
||||
targetObjectId: '',
|
||||
action: '',
|
||||
submittedById: '',
|
||||
snapshot: '',
|
||||
fieldChanges: '',
|
||||
})
|
||||
|
||||
const parseJson = (value: string) => {
|
||||
if (!value) return undefined
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (err) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const statusClass = (status: string) => {
|
||||
if (status === 'approved') return 'bg-primary/10 text-primary'
|
||||
if (status === 'rejected') return 'bg-destructive/10 text-destructive'
|
||||
return 'bg-muted text-muted-foreground'
|
||||
}
|
||||
|
||||
const formatDate = (value?: string) => {
|
||||
if (!value) return '—'
|
||||
const date = new Date(value)
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
const fetchRequests = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
requests.value = await api.get('/approvals')
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchDefinitions = async () => {
|
||||
try {
|
||||
definitions.value = await api.get('/setup/approvals')
|
||||
} catch (e) {
|
||||
definitions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const createRequest = async () => {
|
||||
try {
|
||||
await api.post('/approvals', {
|
||||
definitionId: newRequest.value.definitionId,
|
||||
targetObjectType: newRequest.value.targetObjectType,
|
||||
targetObjectId: newRequest.value.targetObjectId,
|
||||
action: newRequest.value.action || undefined,
|
||||
submittedById: newRequest.value.submittedById || undefined,
|
||||
snapshot: parseJson(newRequest.value.snapshot),
|
||||
fieldChanges: parseJson(newRequest.value.fieldChanges),
|
||||
})
|
||||
showCreateForm.value = false
|
||||
newRequest.value = {
|
||||
definitionId: '',
|
||||
targetObjectType: '',
|
||||
targetObjectId: '',
|
||||
action: '',
|
||||
submittedById: '',
|
||||
snapshot: '',
|
||||
fieldChanges: '',
|
||||
}
|
||||
await fetchRequests()
|
||||
} catch (e: any) {
|
||||
alert('Error creating approval request: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([fetchRequests(), fetchDefinitions()])
|
||||
})
|
||||
</script>
|
||||
241
frontend/pages/setup/approvals/index.vue
Normal file
241
frontend/pages/setup/approvals/index.vue
Normal file
@@ -0,0 +1,241 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background">
|
||||
<NuxtLayout name="default">
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div v-if="loading" class="text-center py-12">Loading...</div>
|
||||
<div v-else-if="error" class="text-destructive">Error: {{ error }}</div>
|
||||
<div v-else>
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Approval Definitions</h1>
|
||||
<button
|
||||
@click="showCreateForm = true"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
New Definition
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="showCreateForm" class="mb-6 p-6 border rounded-lg bg-card">
|
||||
<h2 class="text-xl font-semibold mb-4">Create Approval Definition</h2>
|
||||
<form @submit.prevent="createDefinition" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Name</label>
|
||||
<input
|
||||
v-model="newDefinition.name"
|
||||
type="text"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="Expense Approval"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Trigger Type</label>
|
||||
<select
|
||||
v-model="newDefinition.triggerType"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
>
|
||||
<option value="action">Action</option>
|
||||
<option value="state_transition">State Transition</option>
|
||||
<option value="field_change">Field Change</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Target Object Type</label>
|
||||
<input
|
||||
v-model="newDefinition.targetObjectType"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="Expense"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Description</label>
|
||||
<textarea
|
||||
v-model="newDefinition.description"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
rows="2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Entry Criteria (JSON)</label>
|
||||
<textarea
|
||||
v-model="newDefinition.entryCriteria"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background font-mono text-sm"
|
||||
rows="3"
|
||||
placeholder='{"amount": {"gte": 500}}'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Steps (JSON Array)</label>
|
||||
<textarea
|
||||
v-model="newDefinition.steps"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background font-mono text-sm"
|
||||
rows="4"
|
||||
placeholder='[{"key":"manager","name":"Manager Review","assignees":[]}]'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Voting Policy (JSON)</label>
|
||||
<textarea
|
||||
v-model="newDefinition.votingPolicy"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background font-mono text-sm"
|
||||
rows="3"
|
||||
placeholder='{"type":"majority"}'
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Rejection Rule</label>
|
||||
<input
|
||||
v-model="newDefinition.rejectionRule"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="any"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Material Change Policy</label>
|
||||
<input
|
||||
v-model="newDefinition.materialChangePolicy"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="invalidate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input id="isActive" v-model="newDefinition.isActive" type="checkbox" />
|
||||
<label for="isActive" class="text-sm">Active</label>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
Create
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="showCreateForm = false"
|
||||
class="px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
<div
|
||||
v-for="definition in definitions"
|
||||
:key="definition.id"
|
||||
class="p-6 border rounded-lg bg-card"
|
||||
>
|
||||
<div class="flex items-start justify-between mb-2">
|
||||
<h3 class="text-xl font-semibold">{{ definition.name }}</h3>
|
||||
<span
|
||||
class="text-xs px-2 py-1 rounded"
|
||||
:class="definition.isActive ? 'bg-primary/10 text-primary' : 'bg-muted text-muted-foreground'"
|
||||
>
|
||||
{{ definition.isActive ? 'Active' : 'Inactive' }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-sm text-muted-foreground mb-4">
|
||||
{{ definition.description || 'No description' }}
|
||||
</p>
|
||||
<div class="text-sm space-y-1">
|
||||
<div><span class="text-muted-foreground">Trigger:</span> {{ definition.triggerType }}</div>
|
||||
<div>
|
||||
<span class="text-muted-foreground">Target:</span>
|
||||
{{ definition.targetObjectType || 'Any' }}
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-muted-foreground">Version:</span> {{ definition.version }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</NuxtLayout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { api } = useApi()
|
||||
|
||||
const definitions = ref<any[]>([])
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
const showCreateForm = ref(false)
|
||||
const newDefinition = ref({
|
||||
name: '',
|
||||
triggerType: 'action',
|
||||
targetObjectType: '',
|
||||
description: '',
|
||||
entryCriteria: '',
|
||||
steps: '',
|
||||
votingPolicy: '',
|
||||
rejectionRule: 'any',
|
||||
materialChangePolicy: 'invalidate',
|
||||
isActive: true,
|
||||
})
|
||||
|
||||
const parseJson = (value: string) => {
|
||||
if (!value) return undefined
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (err) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const fetchDefinitions = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
definitions.value = await api.get('/setup/approvals')
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const createDefinition = async () => {
|
||||
try {
|
||||
await api.post('/setup/approvals', {
|
||||
name: newDefinition.value.name,
|
||||
triggerType: newDefinition.value.triggerType,
|
||||
targetObjectType: newDefinition.value.targetObjectType || undefined,
|
||||
description: newDefinition.value.description || undefined,
|
||||
entryCriteria: parseJson(newDefinition.value.entryCriteria),
|
||||
steps: parseJson(newDefinition.value.steps),
|
||||
votingPolicy: parseJson(newDefinition.value.votingPolicy),
|
||||
rejectionRule: newDefinition.value.rejectionRule || undefined,
|
||||
materialChangePolicy: newDefinition.value.materialChangePolicy || undefined,
|
||||
isActive: newDefinition.value.isActive,
|
||||
})
|
||||
showCreateForm.value = false
|
||||
newDefinition.value = {
|
||||
name: '',
|
||||
triggerType: 'action',
|
||||
targetObjectType: '',
|
||||
description: '',
|
||||
entryCriteria: '',
|
||||
steps: '',
|
||||
votingPolicy: '',
|
||||
rejectionRule: 'any',
|
||||
materialChangePolicy: 'invalidate',
|
||||
isActive: true,
|
||||
}
|
||||
await fetchDefinitions()
|
||||
} catch (e: any) {
|
||||
alert('Error creating approval definition: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchDefinitions()
|
||||
})
|
||||
</script>
|
||||
186
frontend/pages/tasks/index.vue
Normal file
186
frontend/pages/tasks/index.vue
Normal file
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background">
|
||||
<NuxtLayout name="default">
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div v-if="loading" class="text-center py-12">Loading...</div>
|
||||
<div v-else-if="error" class="text-destructive">Error: {{ error }}</div>
|
||||
<div v-else>
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Tasks</h1>
|
||||
<button
|
||||
@click="showCreateForm = true"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
New Task
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="showCreateForm" class="mb-6 p-6 border rounded-lg bg-card">
|
||||
<h2 class="text-xl font-semibold mb-4">Create Task</h2>
|
||||
<form @submit.prevent="createTask" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Title</label>
|
||||
<input
|
||||
v-model="newTask.title"
|
||||
type="text"
|
||||
required
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="Follow up on approval"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Description</label>
|
||||
<textarea
|
||||
v-model="newTask.description"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
rows="2"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Assigned To (User ID)</label>
|
||||
<input
|
||||
v-model="newTask.assignedToId"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Due At</label>
|
||||
<input
|
||||
v-model="newTask.dueAt"
|
||||
type="datetime-local"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Related Object Type</label>
|
||||
<input
|
||||
v-model="newTask.relatedObjectType"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
placeholder="ApprovalAssignment"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-2">Related Object ID</label>
|
||||
<input
|
||||
v-model="newTask.relatedObjectId"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 border rounded-md bg-background"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
|
||||
>
|
||||
Create
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="showCreateForm = false"
|
||||
class="px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4">
|
||||
<div
|
||||
v-for="task in tasks"
|
||||
:key="task.id"
|
||||
class="p-6 border rounded-lg bg-card"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h3 class="text-lg font-semibold">{{ task.title }}</h3>
|
||||
<span
|
||||
class="text-xs px-2 py-1 rounded"
|
||||
:class="task.status === 'completed' ? 'bg-primary/10 text-primary' : 'bg-muted text-muted-foreground'"
|
||||
>
|
||||
{{ task.status }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-sm text-muted-foreground mb-2">
|
||||
{{ task.description || 'No description' }}
|
||||
</p>
|
||||
<div class="text-sm text-muted-foreground">
|
||||
<div>Assigned: {{ task.assignedToId || 'Unassigned' }}</div>
|
||||
<div>Due: {{ formatDate(task.dueAt) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</NuxtLayout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { api } = useApi()
|
||||
|
||||
const tasks = ref<any[]>([])
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
const showCreateForm = ref(false)
|
||||
const newTask = ref({
|
||||
title: '',
|
||||
description: '',
|
||||
assignedToId: '',
|
||||
dueAt: '',
|
||||
relatedObjectType: '',
|
||||
relatedObjectId: '',
|
||||
})
|
||||
|
||||
const formatDate = (value?: string) => {
|
||||
if (!value) return '—'
|
||||
const date = new Date(value)
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
const fetchTasks = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
tasks.value = await api.get('/tasks')
|
||||
} catch (e: any) {
|
||||
console.log('here');
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const createTask = async () => {
|
||||
try {
|
||||
await api.post('/tasks', {
|
||||
title: newTask.value.title,
|
||||
description: newTask.value.description || undefined,
|
||||
assignedToId: newTask.value.assignedToId || undefined,
|
||||
dueAt: newTask.value.dueAt || undefined,
|
||||
relatedObjectType: newTask.value.relatedObjectType || undefined,
|
||||
relatedObjectId: newTask.value.relatedObjectId || undefined,
|
||||
})
|
||||
showCreateForm.value = false
|
||||
newTask.value = {
|
||||
title: '',
|
||||
description: '',
|
||||
assignedToId: '',
|
||||
dueAt: '',
|
||||
relatedObjectType: '',
|
||||
relatedObjectId: '',
|
||||
}
|
||||
await fetchTasks()
|
||||
} catch (e: any) {
|
||||
alert('Error creating task: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchTasks()
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user