From 88bfc63e5ce56c4ad3fcd59dcb17ffdd9a9f329b Mon Sep 17 00:00:00 2001 From: Brewhouse Digital <66521220+brewhousedigital@users.noreply.github.com> Date: Wed, 18 Oct 2023 03:13:43 -0500 Subject: [PATCH] Dashboard - Danger Zone Confirmations (#321) * Dashboard - Danger Zone Confirmations * Dashboard - Danger Zone Confirmations --- .../[instanceId]/Danger/RenameInstance.svelte | 36 ++++++++++++-- .../[instanceId]/Danger/VersionChange.svelte | 48 +++++++++++++++---- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/packages/dashboard/src/routes/app/instances/[instanceId]/Danger/RenameInstance.svelte b/packages/dashboard/src/routes/app/instances/[instanceId]/Danger/RenameInstance.svelte index 947f99a5..f103c3d0 100644 --- a/packages/dashboard/src/routes/app/instances/[instanceId]/Danger/RenameInstance.svelte +++ b/packages/dashboard/src/routes/app/instances/[instanceId]/Danger/RenameInstance.svelte @@ -4,6 +4,7 @@ import { DOCS_URL } from '$src/env' import { client } from '$src/pocketbase' import { instance } from '../store' + import { slide } from 'svelte/transition' const { renameInstance } = client() @@ -18,6 +19,9 @@ // Controls the disabled state of the button let isButtonDisabled = false + // Controls visibility of an error message + let errorMessage = '' + // TODO: What are the limits for this? const onRename = (e: Event) => { e.preventDefault() @@ -25,12 +29,26 @@ // Disable the button to prevent double submissions isButtonDisabled = true - // TODO: Set up error handling for when the name is wrong - // TODO: Do validations like trim and removing numbers - renameInstance({ instanceId: id, subdomain: formSubdomain }).then( - () => 'saved', + // Remove extra whitespace, and numbers from the subdomain + const instanceNameValidation = formSubdomain.trim().replace(/[0-9]/g, '') + + // Prompt the user to confirm the version change + const confirmVersionChange = confirm( + `Are you sure you want to rename your instance to ${instanceNameValidation}?`, ) + // If they select yes, then update the version in pocketbase + if (confirmVersionChange) { + renameInstance({ + instanceId: id, + subdomain: instanceNameValidation, + }) + .then(() => 'saved') + .catch((error) => { + errorMessage = error.message + }) + } + // Set the button back to normal isButtonDisabled = false } @@ -48,15 +66,25 @@ else choose it.
+ {#if errorMessage} +