From 88136b61502eb0acd11ca2c8f236c6feb28dc06c Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Thu, 13 Jun 2024 09:45:04 +0300 Subject: [PATCH] modal --- assets/main.scss | 1 + components/modal.vue | 80 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/assets/main.scss b/assets/main.scss index 7df4a75..8d7fd0f 100644 --- a/assets/main.scss +++ b/assets/main.scss @@ -139,6 +139,7 @@ textarea { button { @apply rounded-full bg-primary hover:bg-primary-400 transition-colors px-10 py-3 inline-block text-lg font-bold shadow-lg cursor-pointer disabled:opacity-50 disabled:hover:bg-primary; + &.neutral, &[type="reset"] { @apply bg-neutral hover:bg-neutral-400 } diff --git a/components/modal.vue b/components/modal.vue index 441b502..5616d4f 100644 --- a/components/modal.vue +++ b/components/modal.vue @@ -3,13 +3,24 @@ const config = useRuntimeConfig() const apiBase = config.public.apiBase const isModalOpen = useState('modal_open', () => false) + +const lamelles_count = useState('lamelles_count') +const fence_section = useState('fence_section') +const pillar_color = useState('pillar_color') +const lamelle_color = useState('lamelle_color') +const section_count = useState('section_count') + const toggleModal = () => { modal_data.phone = undefined modal_data.name = undefined + modal_state.show_form = false isModalOpen.value = !isModalOpen.value } - -const modal_data = reactive({ +type modalDataType = { + phone?: string + name?: string +} +const modal_data = reactive({ phone: undefined, name: undefined }) @@ -17,7 +28,12 @@ const modal_form = reactive({ disabled: true, errors: [], }) - +const modal_state = reactive({ + show_form: false +}) +const openForm = () => { + modal_state.show_form = !modal_state.show_form +} const validateInput = (evt: KeyboardEvent) => { const valid_symbols = /[a-zA-Z0-9\+(\\)\ @\.]/ if (!valid_symbols.test(evt.key)) { @@ -29,11 +45,15 @@ const validate = () => { const phone_regexp = /^\+?[\d\s-()]{0,14}\d{11}$/ const email_regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ - if (modal_phone.value.length < 3) { + if (!modal_data.phone) { modal_form.disabled = true return } - if (phone_regexp.test(modal_phone.value) || email_regex.test(modal_phone.value)) { + if (modal_data.phone.length < 3) { + modal_form.disabled = true + return + } + if (phone_regexp.test(modal_data.phone) || email_regex.test(modal_data.phone)) { modal_form.disabled = false return } @@ -45,26 +65,54 @@ const submit = (e: any) => { 'Content-Type': 'application/json' }, body: JSON.stringify({ - name: modal_name.value || "ref from site", - phone: modal_phone.value + name: modal_data.name || `ref from site ${new Date}`, + phone: modal_data.phone }) }) - modal_phone.value = '' + modal_data.phone = undefined + modal_data.name = undefined isModalOpen.value = false } \ No newline at end of file