Allow SMTP config to be cleared

This commit is contained in:
Mel O'Hagan 2022-05-12 16:57:54 +01:00
parent 827f78f8a0
commit db2cfd077f
2 changed files with 28 additions and 3 deletions

View File

@ -68,6 +68,26 @@
} }
} }
async function clearSmtp() {
// Delete the SMTP config
try {
await API.deleteConfig({
id: smtpConfig._id,
rev: smtpConfig._rev,
})
smtpConfig = {
config: {},
}
await admin.getChecklist()
notifications.success(`Settings cleared`)
analytics.captureEvent(Events.SMTP.SAVED)
} catch (error) {
notifications.error(
`Failed to clear email settings, reason: ${error?.message || "Unknown"}`
)
}
}
async function fetchSmtp() { async function fetchSmtp() {
loading = true loading = true
try { try {
@ -156,8 +176,9 @@
</div> </div>
{/if} {/if}
</Layout> </Layout>
<div> <div class="spectrum-ButtonGroup spectrum-Settings-buttonGroup">
<Button cta on:click={saveSmtp}>Save</Button> <Button cta on:click={saveSmtp}>Save</Button>
<Button secondary on:click={clearSmtp}>Clear</Button>
</div> </div>
<Divider /> <Divider />
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
@ -186,4 +207,8 @@
grid-gap: var(--spacing-l); grid-gap: var(--spacing-l);
align-items: center; align-items: center;
} }
.spectrum-Settings-buttonGroup {
gap: var(--spectrum-global-dimension-static-size-200);
align-items: flex-end;
}
</style> </style>

View File

@ -21,13 +21,13 @@ export const buildConfigEndpoints = API => ({
}, },
/** /**
* Deletes a global config * Deletes a global config
* @param id the id of the config to delete * @param id the id of the config to delete
* @param rev the revision of the config to delete * @param rev the revision of the config to delete
*/ */
deleteConfig: async ({ id, rev }) => { deleteConfig: async ({ id, rev }) => {
return await API.delete({ return await API.delete({
url: `/api/global/configs/${id}/${rev}` url: `/api/global/configs/${id}/${rev}`,
}) })
}, },