|
1 | 1 | <script lang="ts"> |
2 | 2 | import { isEmptyString, isNullish, nonNullish, fromNullishNullable } from '@dfinity/utils'; |
3 | | - import { createEventDispatcher, onMount } from 'svelte'; |
| 3 | + import { onMount } from 'svelte'; |
4 | 4 | import type { AuthenticationConfig } from '$declarations/satellite/satellite.did'; |
5 | | - import { setAuthConfig } from '$lib/api/satellites.api'; |
| 5 | + import ProgressHosting from '$lib/components/canister/ProgressHosting.svelte'; |
6 | 6 | import AddCustomDomainAuth from '$lib/components/hosting/AddCustomDomainAuth.svelte'; |
7 | 7 | import AddCustomDomainDns from '$lib/components/hosting/AddCustomDomainDns.svelte'; |
8 | 8 | import AddCustomDomainForm from '$lib/components/hosting/AddCustomDomainForm.svelte'; |
9 | 9 | import IconVerified from '$lib/components/icons/IconVerified.svelte'; |
10 | 10 | import Modal from '$lib/components/ui/Modal.svelte'; |
11 | | - import SpinnerModal from '$lib/components/ui/SpinnerModal.svelte'; |
12 | | - import { setCustomDomain } from '$lib/services/custom-domain.services'; |
| 11 | + import { configHosting } from '$lib/services/hosting.services'; |
13 | 12 | import { authStore } from '$lib/stores/auth.store'; |
14 | 13 | import { wizardBusy } from '$lib/stores/busy.store'; |
15 | 14 | import { i18n } from '$lib/stores/i18n.store'; |
16 | 15 | import { toasts } from '$lib/stores/toasts.store'; |
17 | 16 | import type { CustomDomainDns } from '$lib/types/custom-domain'; |
18 | 17 | import type { JunoModalCustomDomainDetail, JunoModalDetail } from '$lib/types/modal'; |
| 18 | + import type { HostingProgress } from '$lib/types/progress-hosting'; |
| 19 | + import type { Option } from '$lib/types/utils'; |
19 | 20 | import { toCustomDomainDns } from '$lib/utils/custom-domain.utils'; |
20 | 21 | import { emit } from '$lib/utils/events.utils'; |
21 | 22 |
|
22 | 23 | interface Props { |
23 | 24 | detail: JunoModalDetail; |
| 25 | + onclose: () => void; |
24 | 26 | } |
25 | 27 |
|
26 | | - let { detail }: Props = $props(); |
| 28 | + let { detail, onclose }: Props = $props(); |
27 | 29 |
|
28 | 30 | let { satellite, config } = $derived(detail as JunoModalCustomDomainDetail); |
29 | 31 |
|
|
45 | 47 | edit = true; |
46 | 48 | }); |
47 | 49 |
|
48 | | - let editConfig: AuthenticationConfig | null; |
| 50 | + let editConfig = $state<Option<AuthenticationConfig>>(); |
49 | 51 | const onAuth = (detail: AuthenticationConfig | null) => { |
50 | 52 | editConfig = detail; |
51 | 53 |
|
52 | 54 | step = 'dns'; |
53 | 55 | }; |
54 | 56 |
|
| 57 | + let progress: HostingProgress | undefined = $state(undefined); |
| 58 | + const onProgress = (hostingProgress: HostingProgress | undefined) => (progress = hostingProgress); |
| 59 | +
|
55 | 60 | const setupCustomDomain = async () => { |
56 | 61 | if (isNullish(dns)) { |
57 | 62 | toasts.error({ |
|
63 | 68 | wizardBusy.start(); |
64 | 69 | step = 'in_progress'; |
65 | 70 |
|
66 | | - try { |
67 | | - await setCustomDomain({ |
68 | | - satelliteId: satellite.satellite_id, |
69 | | - domainName: dns.hostname |
70 | | - }); |
71 | | -
|
72 | | - if (nonNullish(editConfig)) { |
73 | | - await setAuthConfig({ |
74 | | - satelliteId: satellite.satellite_id, |
75 | | - config: editConfig, |
76 | | - identity: $authStore.identity |
77 | | - }); |
78 | | - } |
| 71 | + const { success } = await configHosting({ |
| 72 | + satelliteId: satellite.satellite_id, |
| 73 | + domainName: dns.hostname, |
| 74 | + editConfig, |
| 75 | + identity: $authStore.identity, |
| 76 | + onProgress |
| 77 | + }); |
79 | 78 |
|
80 | | - step = 'ready'; |
81 | | - } catch (err: unknown) { |
82 | | - toasts.error({ |
83 | | - text: $i18n.errors.hosting_configuration_issues, |
84 | | - detail: err |
85 | | - }); |
| 79 | + wizardBusy.stop(); |
86 | 80 |
|
| 81 | + if (success !== 'ok') { |
87 | 82 | step = edit ? 'dns' : 'init'; |
| 83 | + return; |
88 | 84 | } |
89 | 85 |
|
90 | | - wizardBusy.stop(); |
| 86 | + step = 'ready'; |
91 | 87 | }; |
92 | 88 |
|
93 | | - const dispatch = createEventDispatcher(); |
94 | 89 | const close = () => { |
95 | 90 | emit({ message: 'junoSyncCustomDomains' }); |
96 | | - dispatch('junoClose'); |
| 91 | + onclose(); |
97 | 92 | }; |
98 | 93 |
|
99 | 94 | const onFormNext = () => { |
|
124 | 119 | on:junoClose |
125 | 120 | /> |
126 | 121 | {:else if step === 'in_progress'} |
127 | | - <SpinnerModal> |
128 | | - <p>{$i18n.hosting.config_in_progress}</p> |
129 | | - </SpinnerModal> |
| 122 | + <ProgressHosting {progress} withConfig={nonNullish(editConfig)} /> |
130 | 123 | {:else if step === 'auth'} |
131 | 124 | <AddCustomDomainAuth {domainNameInput} {config} next={onAuth} /> |
132 | 125 | {:else} |
|
0 commit comments