WelcomeView.vue
92 lines
| 1 | <script setup lang="ts"> |
| 2 | import { onMounted, ref } from 'vue'; |
| 3 | |
| 4 | import FAQ from '@/components/FAQ.vue'; |
| 5 | import Hero from '@/components/Hero.vue'; |
| 6 | import { useModal } from '@/composables/useModal'; |
| 7 | import { useToast } from '@/composables/useToast'; |
| 8 | import { connectFaqData } from '@/data/faq'; |
| 9 | import { reachRepo } from '@/data/repositories/reachRepo'; |
| 10 | import { ModalName } from '@/types/enums/modalEnum'; |
| 11 | import { translate } from '@/utils/translate'; |
| 12 | |
| 13 | const TRUSTED_AUTH_DOMAINS = /^https:\/\/auth\.hostinger\.(dev|com)/; |
| 14 | |
| 15 | const { showError } = useToast(); |
| 16 | |
| 17 | const isConnectedToAnotherSite = ref(false); |
| 18 | const isButtonLoading = ref(false); |
| 19 | const { openModal } = useModal(); |
| 20 | const domain = window.location.hostname; |
| 21 | |
| 22 | const handleGetStarted = async () => { |
| 23 | isButtonLoading.value = true; |
| 24 | |
| 25 | const [data, error] = await reachRepo.generateAuthUrl(); |
| 26 | |
| 27 | isButtonLoading.value = false; |
| 28 | |
| 29 | if (error || !data) { |
| 30 | showError(error?.message || translate('hostinger_reach_error_message')); |
| 31 | |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (data.authUrl && TRUSTED_AUTH_DOMAINS.test(data.authUrl)) { |
| 36 | window.location.href = data.authUrl; |
| 37 | } else { |
| 38 | showError(translate('hostinger_reach_error_message')); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | const openApiKeyModal = (apiKey: string = '') => { |
| 43 | openModal(ModalName.REACH_API_KEY_MODAL, { apiKey }, { hasCloseButton: true, isXL: true }); |
| 44 | }; |
| 45 | |
| 46 | onMounted(() => { |
| 47 | const params = new URLSearchParams(window.location.search); |
| 48 | const key = params.get('api_key'); |
| 49 | |
| 50 | if (key !== null) { |
| 51 | openApiKeyModal(); |
| 52 | } |
| 53 | }); |
| 54 | </script> |
| 55 | |
| 56 | <template> |
| 57 | <div class="welcome-view"> |
| 58 | <Hero |
| 59 | :is-connected-to-another-site="isConnectedToAnotherSite" |
| 60 | :is-button-loading="isButtonLoading" |
| 61 | :domain="domain" |
| 62 | :on-get-started="handleGetStarted" |
| 63 | :on-manual-api-key-click="() => openApiKeyModal()" |
| 64 | /> |
| 65 | <div class="faq-wrap"> |
| 66 | <FAQ :faq-data="connectFaqData" /> |
| 67 | </div> |
| 68 | </div> |
| 69 | </template> |
| 70 | |
| 71 | <style scoped lang="scss"> |
| 72 | .welcome-view { |
| 73 | min-height: 100vh; |
| 74 | padding: 0 16px; |
| 75 | |
| 76 | @media (max-width: 480px) { |
| 77 | padding: 0 12px; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | @media (max-width: 320px) { |
| 82 | .welcome-view { |
| 83 | padding: 0 8px; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | .faq-wrap { |
| 88 | max-width: 780px; |
| 89 | margin: 24px auto; |
| 90 | } |
| 91 | </style> |
| 92 |