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} +