Skip to content

Commit 8549bce

Browse files
authored
Add retry button in ViewLogs modal (#2805)
* Add retry button in ViewLogs modal * lint * remove fallback
1 parent f3cf45e commit 8549bce

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

src/lib/components/domains/viewLogsModal.svelte

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,80 @@
22
import { Modal } from '$lib/components';
33
import { Logs } from '@appwrite.io/pink-svelte';
44
import { app } from '$lib/stores/app';
5-
import type { Models } from '@appwrite.io/console';
5+
import { ProxyRuleStatus, type Models } from '@appwrite.io/console';
6+
import { Button } from '$lib/elements/forms';
7+
import { getApexDomain } from '$lib/helpers/tlds';
8+
import { isCloud } from '$lib/system';
9+
import { sdk } from '$lib/stores/sdk';
10+
import { page } from '$app/state';
11+
import { Dependencies } from '$lib/constants';
12+
import { invalidate } from '$app/navigation';
13+
import { addNotification } from '$lib/stores/notifications';
14+
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
615
716
let {
817
show = $bindable(false),
9-
selectedProxyRule
18+
selectedProxyRule,
19+
domainsList
1020
}: {
1121
show: boolean;
1222
selectedProxyRule: Models.ProxyRule;
23+
domainsList?: Models.DomainsList;
1324
} = $props();
25+
26+
let error = $state(null);
27+
28+
async function retryDomain() {
29+
error = null;
30+
31+
try {
32+
const apexDomain = getApexDomain(selectedProxyRule.domain);
33+
const domain = domainsList?.domains.find((d) => d.domain === apexDomain);
34+
if (isCloud && domain) {
35+
await sdk.forConsole.domains.updateNameservers({
36+
domainId: domain.$id
37+
});
38+
}
39+
} catch {
40+
// Ignore error
41+
}
42+
43+
try {
44+
selectedProxyRule = await sdk
45+
.forProject(page.params.region, page.params.project)
46+
.proxy.updateRuleVerification({ ruleId: selectedProxyRule.$id });
47+
48+
await invalidate(Dependencies.DOMAINS);
49+
show = false;
50+
addNotification({
51+
type: 'success',
52+
message: 'Domain verified successfully'
53+
});
54+
trackEvent(Submit.DomainUpdateVerification);
55+
} catch (e) {
56+
error = e.message;
57+
trackError(e, Submit.DomainUpdateVerification);
58+
}
59+
}
60+
61+
$effect(() => {
62+
if (!show) {
63+
error = null;
64+
}
65+
});
1466
</script>
1567

16-
<Modal title="Certificate logs" bind:show size="m" hideFooter>
68+
<Modal
69+
title="Certificate logs"
70+
size="m"
71+
bind:show
72+
bind:error
73+
onSubmit={retryDomain}
74+
hideFooter={selectedProxyRule.status !== ProxyRuleStatus.Unverified}>
1775
<Logs logs={selectedProxyRule.logs} theme={$app.themeInUse} showScrollButton height="250px" />
76+
<svelte:fragment slot="footer">
77+
{#if selectedProxyRule.status === ProxyRuleStatus.Unverified}
78+
<Button submit>Retry</Button>
79+
{/if}
80+
</svelte:fragment>
1881
</Modal>

src/routes/(console)/project-[region]-[project]/functions/function-[function]/domains/table.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
{/if}
227227

228228
{#if showLogs}
229-
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} />
229+
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} domainsList={organizationDomains} />
230230
{/if}
231231

232232
<style>

src/routes/(console)/project-[region]-[project]/settings/domains/table.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
{/if}
232232

233233
{#if showLogs}
234-
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} />
234+
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} domainsList={organizationDomains} />
235235
{/if}
236236

237237
<style>

src/routes/(console)/project-[region]-[project]/sites/site-[site]/domains/table.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
{/if}
227227

228228
{#if showLogs}
229-
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} />
229+
<ViewLogsModal bind:show={showLogs} {selectedProxyRule} domainsList={organizationDomains} />
230230
{/if}
231231

232232
<style>

0 commit comments

Comments
 (0)