Skip to content

Commit 0a65327

Browse files
authored
feat: add flow item comment action (#205)
1 parent d23bc1c commit 0a65327

8 files changed

Lines changed: 178 additions & 15 deletions

File tree

apps/atrium-telegram/app/components/flow/ItemCard.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<ActiveCard>
33
<div class="flex flex-row gap-2 items-center">
44
<UAvatar
5-
v-if="item.userId"
5+
v-if="item.userId && item.type === 'user_post'"
66
:src="userAvatarUrl"
77
class="size-8"
88
/>
99
<UIcon
1010
v-else
11-
name="i-lucide-clipboard-check"
11+
:name="getIconName(item.type)"
1212
class="size-8 text-primary"
1313
/>
1414

@@ -59,4 +59,18 @@ const { item } = defineProps<{
5959
const userStore = useUserStore()
6060
const isViewed = computed(() => item.views.some((view) => view.userId === userStore?.id))
6161
const userAvatarUrl = computed(() => userStore.users.find((user) => user.id === item.userId)?.avatarUrl ?? undefined)
62+
63+
function getIconName(type: FlowItemWithData['type']): string {
64+
switch (type) {
65+
case 'user_post':
66+
return 'i-lucide-square-user-round'
67+
case 'partner_maintenance':
68+
return 'i-lucide-user'
69+
case 'daily_task_report':
70+
case 'weekly_task_report':
71+
return 'i-lucide-clipboard-check'
72+
default:
73+
return 'i-lucide-clipboard'
74+
}
75+
}
6276
</script>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<UForm
3+
:validate="createValidator(createFlowItemCommentSchema)"
4+
:state="state"
5+
class="flex flex-col gap-3"
6+
@submit="onSubmit"
7+
>
8+
<UFormField label="Ваше сообщение" name="text">
9+
<UTextarea
10+
v-model="state.text"
11+
placeholder="Не торопись, осмотрись..."
12+
autoresize
13+
size="xl"
14+
class="w-full"
15+
/>
16+
</UFormField>
17+
18+
<UButton
19+
type="submit"
20+
variant="solid"
21+
color="secondary"
22+
size="xl"
23+
icon="i-lucide-send"
24+
block
25+
class="mt-3"
26+
:disabled="!state.text"
27+
:label="$t('common.send')"
28+
/>
29+
</UForm>
30+
</template>
31+
32+
<script setup lang="ts">
33+
import type { CreateFlowItemComment } from '#shared/services/flow'
34+
import type { FormSubmitEvent } from '@nuxt/ui'
35+
import { createFlowItemCommentSchema } from '#shared/services/flow'
36+
37+
const { itemId } = defineProps<{ itemId: string }>()
38+
39+
const emit = defineEmits(['success', 'submitted'])
40+
41+
const { vibrate } = useFeedback()
42+
const userStore = useUserStore()
43+
const flowStore = useFlowStore()
44+
45+
const state = ref<Partial<CreateFlowItemComment>>({
46+
text: undefined,
47+
})
48+
49+
async function onSubmit(event: FormSubmitEvent<CreateFlowItemComment>) {
50+
emit('submitted')
51+
52+
try {
53+
await $fetch(`/api/flow/id/${itemId}/comment`, {
54+
method: 'POST',
55+
headers: {
56+
Authorization: `tma ${userStore.initDataRaw}`,
57+
},
58+
body: event.data,
59+
})
60+
61+
await Promise.all([
62+
flowStore.update(),
63+
userStore.update(),
64+
])
65+
66+
vibrate('success')
67+
emit('success')
68+
} catch (error) {
69+
console.error(error)
70+
vibrate('error')
71+
}
72+
}
73+
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<PageContainer>
3+
<SectionTitle title="Реестр договоров" />
4+
5+
<div>Чуть позже</div>
6+
</PageContainer>
7+
</template>

apps/atrium-telegram/app/pages/flow/[itemId]/index.vue

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Посмотрели
3838
</h3>
3939

40-
<div class="flex flex-row gap-2">
40+
<div class="flex flex-row flex-wrap gap-1">
4141
<UAvatar
4242
v-for="view in item?.views"
4343
:key="view.id"
@@ -61,16 +61,26 @@
6161
</UBadge>
6262
</div>
6363

64-
<UButton
65-
variant="solid"
66-
color="secondary"
67-
size="xl"
68-
block
69-
class="items-center justify-center"
70-
icon="i-lucide-message-circle"
71-
label="Написать сообщение"
72-
@click="vibrate()"
73-
/>
64+
<UDrawer v-model:open="isDrawerOpened">
65+
<UButton
66+
variant="solid"
67+
color="secondary"
68+
size="xl"
69+
block
70+
class="items-center justify-center"
71+
icon="i-lucide-message-circle"
72+
label="Написать сообщение"
73+
@click="vibrate()"
74+
/>
75+
76+
<template #body>
77+
<FormCreateFlowItemComment
78+
:item-id="item?.id ?? ''"
79+
@submitted="isDrawerOpened = false"
80+
@success="isDrawerOpened = false"
81+
/>
82+
</template>
83+
</UDrawer>
7484

7585
<div v-if="item?.comments.length" class="w-full flex flex-col gap-3.5 flex-1 last-of-type:mb-20">
7686
<FlowItemComment
@@ -96,6 +106,8 @@ definePageMeta({
96106
const { params } = useRoute('flow-itemId')
97107
const { vibrate } = useFeedback()
98108
109+
const isDrawerOpened = ref(false)
110+
99111
const userStore = useUserStore()
100112
const flowStore = useFlowStore()
101113
const item = computed(() => flowStore.items.find((item) => item.id === params.itemId))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<PageContainer>
3+
<SectionTitle title="Кухни" />
4+
5+
<div>Чуть позже</div>
6+
</PageContainer>
7+
</template>
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
<template>
22
<PageContainer>
3-
<SectionTitle title="В работе" />
3+
<div class="flex flex-col gap-2">
4+
<UButton
5+
v-for="item in items"
6+
:key="item.label"
7+
size="xl"
8+
color="neutral"
9+
variant="ghost"
10+
:label="item.label"
11+
:to="item.to"
12+
:icon="item.icon"
13+
:ui="{
14+
base: 'px-0 pt-0 text-2xl/6 font-bold',
15+
}"
16+
@click="item.onClick"
17+
/>
18+
</div>
419
</PageContainer>
520
</template>
21+
22+
<script lang="ts" setup>
23+
const { vibrate } = useFeedback()
24+
25+
const items = ref([
26+
{
27+
label: 'Реестр договоров',
28+
to: '/agreement',
29+
icon: 'i-lucide-list-checks',
30+
onClick: () => vibrate(),
31+
},
32+
{
33+
label: 'Партнеры',
34+
to: '/partner',
35+
icon: 'i-lucide-users',
36+
onClick: () => vibrate(),
37+
},
38+
{
39+
label: 'Кухни',
40+
to: '/kitchen',
41+
icon: 'i-lucide-store',
42+
onClick: () => vibrate(),
43+
},
44+
])
45+
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<PageContainer>
3+
<SectionTitle title="Партнеры" />
4+
5+
<div>Чуть позже</div>
6+
</PageContainer>
7+
</template>

packages/database/src/types/entities.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export type TimeZone = '+00:00'
3131
| '+11:00'
3232
| '+12:00'
3333

34-
export type FlowItemType = 'daily_task_report' | 'weekly_task_report' | 'user_post' | 'task_list'
34+
export type FlowItemType = 'daily_task_report'
35+
| 'weekly_task_report'
36+
| 'user_post'
37+
| 'partner_maintenance'
3538

3639
export type PermissionCode = 'product:view'
3740
| 'product:edit'

0 commit comments

Comments
 (0)