From 8c8affbeb8b69087e5fcacd07a25d9259e4511d9 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Fri, 5 Jul 2024 11:21:28 +0300 Subject: [PATCH] modal --- assets/main.scss | 14 ++++++++++- components/modal.vue | 59 ++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/assets/main.scss b/assets/main.scss index c1abc11..f8886a2 100644 --- a/assets/main.scss +++ b/assets/main.scss @@ -43,6 +43,7 @@ body { a[href^=http] { @apply relative no-underline; + &:after { content: '↷'; @apply ml-2; @@ -96,8 +97,9 @@ a[href^="#"] { @apply relative h-[50vh] min-h-[600px]; } } + &_content { - > .container { + >.container { @apply items-start; } } @@ -146,6 +148,16 @@ a[href^="#"] { @apply absolute right-4 top-4 text-4xl opacity-50; } + &-status { + @apply text-center; + &-icon { + @apply text-8xl; + } + &-text { + @apply text-3xl; + } + } + h2 { @apply px-4; } diff --git a/components/modal.vue b/components/modal.vue index 344057e..eec4526 100644 --- a/components/modal.vue +++ b/components/modal.vue @@ -23,6 +23,7 @@ const toggleModal = () => { modal_data.phone = undefined modal_data.name = undefined modal_state.show_form = false + modal_state.show_status = null isModalOpen.value = !isModalOpen.value } type modalDataType = { @@ -40,7 +41,8 @@ const modal_form = reactive({ errors: [], }) const modal_state = reactive({ - show_form: false + show_form: false, + show_status: null as null | 'loading' | 'success' | 'error', }) const openForm = () => { modal_state.show_form = !modal_state.show_form @@ -67,26 +69,29 @@ const validate = () => { return } } -const submit = (e: any) => { +const submit = async (e: any) => { goal('submit_form', modal_data) - fetch(`${apiBase}/custom_request/`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - name: modal_data.name || `ref from site ${new Date}`, - phone: modal_data.phone, - email: modal_data.email, - fence_info: [ - ...Object.values(total_txt.value).map(el => el.join('\n')), - total_colors.value.join('\n') - ].join('\n\n'), + modal_state.show_status = 'loading' + try { + const res = await fetch(`${apiBase}/custom_request/`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + name: modal_data.name || `ref from site ${new Date}`, + phone: modal_data.phone, + email: modal_data.email, + fence_info: [ + ...Object.values(total_txt.value as object).map(el => el.join('\n')), + total_colors.value.join('\n') + ].join('\n\n'), + }) }) - }) - modal_data.phone = undefined - modal_data.name = undefined - toggleModal() + modal_state.show_status = 'success' + } catch (error) { + modal_state.show_status = 'error' + } } const roubleSign = new Intl.NumberFormat('ru-RU', { style: 'currency', @@ -164,9 +169,15 @@ const total_txt = computed(() => { const goal = (target: string, params: object) => { const nuxtApp = useNuxtApp() if (nuxtApp.$metrika) { - nuxtApp.$metrika.reachGoal(target, params || {}) + (nuxtApp.$metrika as any).reachGoal(target, params || {}) } } + +const modalStatus = { + 'loading': ["mdi:circle-arrows", 'Отправляем данные'], + 'success': ["mdi:check-circle-outline", 'Данные отправлены'], + 'error': ["mdi:close-circle-outline", 'Ошибка отправки'], +}