From c273a173c96c7140e2f961914ec1bf374b695074 Mon Sep 17 00:00:00 2001 From: aarizona Date: Wed, 15 May 2024 21:51:42 +0300 Subject: [PATCH] add bx selector --- .env.example | 3 ++ front/assets/css/main.css | 12 +++++ front/nuxt.config.ts | 1 + front/pages/bx/tg.vue | 107 +++++++++++++++++++++++++++++--------- front/tailwind.config.js | 1 + main.py | 16 +++++- 6 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 .env.example create mode 100644 front/assets/css/main.css diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..548fdb1 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +VTK_KEYS='{"office":"TOKEN","park":"TOKEN"}' +BX_API_CALL= +TG_TOKEN= \ No newline at end of file diff --git a/front/assets/css/main.css b/front/assets/css/main.css new file mode 100644 index 0000000..79d2db1 --- /dev/null +++ b/front/assets/css/main.css @@ -0,0 +1,12 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer components { + a[href][target="_blank"] { + @apply text-pink-500 hover:text-pink-700 + } + code { + @apply bg-slate-200 border-slate-300 border rounded p-1 cursor-pointer + } +} \ No newline at end of file diff --git a/front/nuxt.config.ts b/front/nuxt.config.ts index 8bdcc94..ce4a09a 100644 --- a/front/nuxt.config.ts +++ b/front/nuxt.config.ts @@ -7,6 +7,7 @@ export default defineNuxtConfig({ viewer: true, // and more... }, + css: ['~/assets/css/main.css'], ssr: false, devServer: { port: 3010 diff --git a/front/pages/bx/tg.vue b/front/pages/bx/tg.vue index 59671b7..10b26f0 100644 --- a/front/pages/bx/tg.vue +++ b/front/pages/bx/tg.vue @@ -11,7 +11,7 @@ interface APIBody { status: 'success' | 'error' } -const steps = ['get_me', 'get_user_id', 'get_bx'] +const steps = ['get_me', 'get_user_id', 'get_bx', "end_step", "test_webhook"] const { data, pending, error, status } = await useLazyFetch(`${config.public.apiBase}/api/tg/get_me`, { server: false }) @@ -21,8 +21,18 @@ const shown_steps = ref(['get_me']) const loading = ref(false) const disabled = ref(false) -const serverData = ref() -const serverData2 = ref() +const tg_data = ref() +const bx_data = ref() + +const selected_tg = ref() +const selected_bx = ref() + +const isShown = (step: typeof steps[number]) => { + return shown_steps.value.includes(step) +} +const isPassed = (step: typeof steps[number]) => { + return [{ 'line-through': passed_step.value.includes(step) }] +} const passToStep = (stepName: typeof steps[number]) => { try { @@ -35,7 +45,6 @@ const passToStep = (stepName: typeof steps[number]) => { } const nextStep = async () => { - passed_step.value.push(step.value) if (step.value == 'get_me') { await retryStep('get_user_id') passToStep('get_user_id') @@ -44,50 +53,96 @@ const nextStep = async () => { await retryStep('get_bx') passToStep('get_bx') } + else if (step.value == 'get_bx') { + if (!selected_bx.value) { + return + } + await retryStep('end_step') + passToStep('end_step') + } + else if (step.value == 'end_step') { + await retryStep('test_webhook') + passToStep('test_webhook') + } } const retryStep = async (stepName: typeof steps[number]) => { if (stepName == 'get_user_id') { loading.value = true const tg_res = await $fetch(`${config.public.apiBase}/api/tg/get_updates`) - serverData.value = tg_res.data + tg_data.value = tg_res.data loading.value = false } else if (stepName == 'get_bx') { loading.value = true + selected_tg.value = tg_data.value[0].message.chat.id const bx_res = await $fetch(`${config.public.apiBase}/api/bx/get_users`) - serverData2.value = bx_res.data + bx_data.value = bx_res.data loading.value = false } } + +const testWebhook = async () => { + const bx_res = await $fetch(`${config.public.apiBase}/api/bx/test_webhook/${selected_tg.value}`) + console.log(bx_res) +}