-
Notifications
You must be signed in to change notification settings - Fork 0
feat: create flow item action #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <template> | ||
| <h2 class="text-2xl/6 font-bold tracking-tight"> | ||
| {{ title }} | ||
| </h2> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| defineProps<{ | ||
| title: string | ||
| }>() | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/atrium-telegram/app/components/form/CreateFlowItem.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <template> | ||
| <UForm | ||
| :validate="createValidator(createFlowItemSchema)" | ||
| :state="state" | ||
| class="flex flex-col gap-3" | ||
| @submit="onSubmit" | ||
| > | ||
| <UFormField | ||
| :label="$t('common.title')" | ||
| name="title" | ||
| required | ||
| > | ||
| <UInput | ||
| v-model="state.title" | ||
| size="xl" | ||
| class="w-full" | ||
| /> | ||
| </UFormField> | ||
|
|
||
| <UFormField label="Текст" name="description"> | ||
| <UTextarea | ||
| v-model="state.description" | ||
| placeholder="Основной текст поста" | ||
| autoresize | ||
| size="xl" | ||
| class="w-full" | ||
| /> | ||
| </UFormField> | ||
|
|
||
| <UButton | ||
| type="submit" | ||
| variant="solid" | ||
| color="secondary" | ||
| size="xl" | ||
| block | ||
| class="mt-3" | ||
| :label="$t('common.create')" | ||
| /> | ||
| </UForm> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import type { CreateFlowItem } from '#shared/services/flow' | ||
| import type { FormSubmitEvent } from '@nuxt/ui' | ||
| import { createFlowItemSchema } from '#shared/services/flow' | ||
|
|
||
| const emit = defineEmits(['success', 'submitted']) | ||
|
|
||
| const { t } = useI18n() | ||
| const { vibrate } = useFeedback() | ||
| const actionToast = useActionToast() | ||
|
|
||
| const flowStore = useFlowStore() | ||
| const userStore = useUserStore() | ||
|
|
||
| const state = ref<Partial<CreateFlowItem>>({ | ||
| title: undefined, | ||
| description: undefined, | ||
| type: 'user_post', | ||
| userId: userStore.id, | ||
| }) | ||
|
|
||
| async function onSubmit(event: FormSubmitEvent<CreateFlowItem>) { | ||
| const toastId = actionToast.start() | ||
| emit('submitted') | ||
|
|
||
| try { | ||
| await $fetch('/api/flow', { | ||
| method: 'POST', | ||
| headers: { | ||
| Authorization: `tma ${userStore.initDataRaw}`, | ||
| }, | ||
| body: event.data, | ||
| }) | ||
|
|
||
| await Promise.all([ | ||
| flowStore.update(), | ||
| userStore.update(), | ||
| ]) | ||
|
|
||
| actionToast.success(toastId, t('toast.flow-item-created')) | ||
| vibrate('success') | ||
| emit('success') | ||
| } catch (error) { | ||
| console.error(error) | ||
| actionToast.error(toastId) | ||
| vibrate('error') | ||
| } | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <template> | ||
| <PageContainer> | ||
| <div class="flex flex-col gap-2.5"> | ||
| <SectionTitle title="Создание поста" /> | ||
|
|
||
| <FormCreateFlowItem @success="handleSuccess()" /> | ||
| </div> | ||
| </PageContainer> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| definePageMeta({ | ||
| name: 'flow-new', | ||
| canReturn: true, | ||
| }) | ||
|
|
||
| function handleSuccess() { | ||
| return navigateTo('/') | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| <template> | ||
| <PageContainer> | ||
| <h1 class="text-2xl/6 font-bold tracking-tight"> | ||
| В работе | ||
| </h1> | ||
| <SectionTitle title="В работе" /> | ||
| </PageContainer> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| <template> | ||
| <PageContainer :back="false"> | ||
| <h1 class="text-2xl"> | ||
| Нет доступа! | ||
| </h1> | ||
| <SectionTitle title="Нет доступа!" /> | ||
| <p>Напишите в поддержку.</p> | ||
| </PageContainer> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { createFlowItemSchema } from '#shared/services/flow' | ||
| import { repository } from '@roll-stack/database' | ||
| import { type } from 'arktype' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| try { | ||
| const body = await readBody(event) | ||
| const data = createFlowItemSchema(body) | ||
| if (data instanceof type.errors) { | ||
| throw data | ||
| } | ||
|
|
||
| const item = await repository.flow.createItem({ | ||
| type: data.type, | ||
| title: data.title, | ||
| description: data.description, | ||
| userId: data.userId, | ||
| }) | ||
| if (!item) { | ||
| throw createError({ | ||
| statusCode: 500, | ||
| message: 'Item not created', | ||
| }) | ||
| } | ||
|
|
||
| // Bot notification in chat | ||
| // if (list.chat) { | ||
| // const bot = await repository.chat.findNotificationBot(list.chat.id) | ||
| // if (bot) { | ||
| // const text = `${event.context.user.name} ${event.context.user.surname} ${suffixByGender(['создал', 'создала'], event.context.user.gender)} задачу «${task.name}»` | ||
|
|
||
| // // Send message as bot | ||
| // await repository.chat.createMessage({ | ||
| // chatId: list.chat.id, | ||
| // userId: bot.user.id, | ||
| // text, | ||
| // }) | ||
| // } | ||
| // } | ||
|
|
||
| return { | ||
| ok: true, | ||
| result: item, | ||
| } | ||
| } catch (error) { | ||
| throw errorResolver(error) | ||
| } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { type } from 'arktype' | ||
|
|
||
| const flowTypeSchema = type('"user_post" | "daily_task_report" | "weekly_task_report"') | ||
|
|
||
| export const createFlowItemSchema = type({ | ||
| title: type('2 <= string <= 150').describe('error.length.invalid'), | ||
| description: type('string <= 1500 | undefined').describe('error.length.invalid').optional(), | ||
| type: flowTypeSchema.describe('error.length.invalid'), | ||
| userId: type('string | undefined').describe('error.length.invalid').optional(), | ||
| }) | ||
| export type CreateFlowItem = typeof createFlowItemSchema.infer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not trust client-supplied userId; derive from authenticated context.
Accepting userId from the request body enables impersonation. Use event.context.user.id and ignore body.userId.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents