ui: for removing app

This commit is contained in:
Andras Bacsai
2022-07-26 13:32:39 +00:00
parent c53acbcd95
commit b3ebaa1fca

View File

@@ -34,17 +34,21 @@
let containers: any; let containers: any;
let PRMRSecrets: any; let PRMRSecrets: any;
let applicationSecrets: any; let applicationSecrets: any;
let loading = true; let loading = {
init: true,
removing: false
};
async function refreshSecrets() { async function refreshSecrets() {
const data = await get(`/applications/${id}/secrets`); const data = await get(`/applications/${id}/secrets`);
PRMRSecrets = [...data.secrets]; PRMRSecrets = [...data.secrets];
} }
async function removeApplication(container: any) { async function removeApplication(container: any) {
try { try {
loading.removing = true;
await post(`/applications/${id}/stop/preview`, { await post(`/applications/${id}/stop/preview`, {
pullmergeRequestId: container.pullmergeRequestId pullmergeRequestId: container.pullmergeRequestId
}); });
toast.push('Preview stopped.'); return window.location.reload();
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} }
@@ -69,7 +73,7 @@
} }
onMount(async () => { onMount(async () => {
try { try {
loading = true; loading.init = true;
const response = await get(`/applications/${id}/previews`); const response = await get(`/applications/${id}/previews`);
containers = response.containers; containers = response.containers;
PRMRSecrets = response.PRMRSecrets; PRMRSecrets = response.PRMRSecrets;
@@ -77,7 +81,7 @@
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} finally { } finally {
loading = false; loading.init = false;
} }
}); });
</script> </script>
@@ -133,7 +137,7 @@
</a> </a>
{/if} {/if}
</div> </div>
{#if loading} {#if loading.init}
<Loading /> <Loading />
{:else} {:else}
<div class="mx-auto max-w-6xl px-6 pt-4"> <div class="mx-auto max-w-6xl px-6 pt-4">
@@ -193,8 +197,12 @@
</div> </div>
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
<button <button
class="bg-coollabs hover:bg-coollabs-100" class:bg-coollabs={!loading.removing}
on:click={() => removeApplication(container)}>Remove Application</button class:hover:bg-coollabs-100={!loading.removing}
disabled={loading.removing}
on:click={() => removeApplication(container)}
>{loading.removing ? 'Removing...' : 'Remove Application'}
></button
> >
</div> </div>
{/each} {/each}