rework error alerts
This commit is contained in:
@ -25,17 +25,11 @@
|
||||
// (sadly we can't use a reactive binding because reasons I guess)
|
||||
defaults.subscribe(d => local.is_default = local.id === d[local.credential.type])
|
||||
|
||||
let error, alert;
|
||||
let alert;
|
||||
async function saveCredential() {
|
||||
try {
|
||||
await invoke('save_credential', {record: local});
|
||||
dispatch('update');
|
||||
showDetails = false;
|
||||
}
|
||||
catch (e) {
|
||||
if (error) alert.shake();
|
||||
error = e;
|
||||
}
|
||||
await invoke('save_credential', {record: local});
|
||||
dispatch('update');
|
||||
showDetails = false;
|
||||
}
|
||||
|
||||
let deleteModal;
|
||||
@ -51,14 +45,14 @@
|
||||
async function deleteCredential() {
|
||||
try {
|
||||
if (!record.isNew) {
|
||||
|
||||
await invoke('delete_credential', {id: record.id});
|
||||
}
|
||||
dispatch('update');
|
||||
}
|
||||
catch (e) {
|
||||
if (error) alert.shake();
|
||||
error = e;
|
||||
showDetails = true;
|
||||
// wait for showDetails to take effect and the alert to be rendered
|
||||
window.setTimeout(() => alert.setError(e), 0);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -95,17 +89,13 @@
|
||||
|
||||
|
||||
{#if showDetails}
|
||||
{#if error}
|
||||
<div class="px-6">
|
||||
<ErrorAlert bind:this={alert}>{error}</ErrorAlert>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<form
|
||||
transition:slide|local={{duration: 200}}
|
||||
class=" px-6 pb-4 space-y-4"
|
||||
on:submit|preventDefault={saveCredential}
|
||||
on:submit|preventDefault={() => alert.run(saveCredential)}
|
||||
>
|
||||
<ErrorAlert bind:this={alert} />
|
||||
|
||||
<div class="grid grid-cols-[auto_1fr] items-center gap-4">
|
||||
{#if record.isNew}
|
||||
<span class="justify-self-end">Name</span>
|
||||
@ -131,7 +121,7 @@
|
||||
|
||||
<div class="flex justify-between">
|
||||
<label class="label cursor-pointer justify-self-start space-x-4">
|
||||
<span class="label-text">Default for type</span>
|
||||
<span class="label-text">Default AWS access key</span>
|
||||
<input type="checkbox" class="toggle toggle-accent" bind:checked={local.is_default}>
|
||||
</label>
|
||||
{#if isModified}
|
||||
|
Reference in New Issue
Block a user