mirror of
https://github.com/pockethost/pockethost.git
synced 2025-07-05 12:22:29 +00:00
Dashboard - Danger Zone Confirmations (#321)
* Dashboard - Danger Zone Confirmations * Dashboard - Danger Zone Confirmations
This commit is contained in:
parent
4177263800
commit
88bfc63e5c
@ -4,6 +4,7 @@
|
|||||||
import { DOCS_URL } from '$src/env'
|
import { DOCS_URL } from '$src/env'
|
||||||
import { client } from '$src/pocketbase'
|
import { client } from '$src/pocketbase'
|
||||||
import { instance } from '../store'
|
import { instance } from '../store'
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
|
||||||
const { renameInstance } = client()
|
const { renameInstance } = client()
|
||||||
|
|
||||||
@ -18,6 +19,9 @@
|
|||||||
// Controls the disabled state of the button
|
// Controls the disabled state of the button
|
||||||
let isButtonDisabled = false
|
let isButtonDisabled = false
|
||||||
|
|
||||||
|
// Controls visibility of an error message
|
||||||
|
let errorMessage = ''
|
||||||
|
|
||||||
// TODO: What are the limits for this?
|
// TODO: What are the limits for this?
|
||||||
const onRename = (e: Event) => {
|
const onRename = (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -25,12 +29,26 @@
|
|||||||
// Disable the button to prevent double submissions
|
// Disable the button to prevent double submissions
|
||||||
isButtonDisabled = true
|
isButtonDisabled = true
|
||||||
|
|
||||||
// TODO: Set up error handling for when the name is wrong
|
// Remove extra whitespace, and numbers from the subdomain
|
||||||
// TODO: Do validations like trim and removing numbers
|
const instanceNameValidation = formSubdomain.trim().replace(/[0-9]/g, '')
|
||||||
renameInstance({ instanceId: id, subdomain: formSubdomain }).then(
|
|
||||||
() => 'saved',
|
// 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
|
// Set the button back to normal
|
||||||
isButtonDisabled = false
|
isButtonDisabled = false
|
||||||
}
|
}
|
||||||
@ -48,15 +66,25 @@
|
|||||||
else choose it.
|
else choose it.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{#if errorMessage}
|
||||||
|
<div in:slide class="alert alert-error mb-4">
|
||||||
|
<i class="fa-regular fa-circle-exclamation"></i>
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<form
|
<form
|
||||||
class="flex rename-instance-form-container-query gap-4"
|
class="flex rename-instance-form-container-query gap-4"
|
||||||
on:submit={onRename}
|
on:submit={onRename}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
title="Only letters and dashes are allowed"
|
||||||
|
required
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={formSubdomain}
|
bind:value={formSubdomain}
|
||||||
class="input input-bordered w-full"
|
class="input input-bordered w-full"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-error" disabled={isButtonDisabled}
|
<button type="submit" class="btn btn-error" disabled={isButtonDisabled}
|
||||||
>Rename Instance</button
|
>Rename Instance</button
|
||||||
>
|
>
|
||||||
|
@ -4,14 +4,22 @@
|
|||||||
import { DOCS_URL } from '$src/env'
|
import { DOCS_URL } from '$src/env'
|
||||||
import { client } from '$src/pocketbase'
|
import { client } from '$src/pocketbase'
|
||||||
import { instance } from '../store'
|
import { instance } from '../store'
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
|
||||||
$: ({ id, maintenance } = $instance)
|
$: ({ id, maintenance, version } = $instance)
|
||||||
|
|
||||||
let version = $instance.version
|
// Create a copy of the version
|
||||||
|
let instanceVersion = version
|
||||||
|
$: {
|
||||||
|
instanceVersion = version
|
||||||
|
}
|
||||||
|
|
||||||
// Controls the disabled state of the button
|
// Controls the disabled state of the button
|
||||||
let isButtonDisabled = false
|
let isButtonDisabled = false
|
||||||
|
|
||||||
|
// Controls visibility of an error message
|
||||||
|
let errorMessage = ''
|
||||||
|
|
||||||
// Update the version number
|
// Update the version number
|
||||||
const handleSave = async (e: Event) => {
|
const handleSave = async (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -19,12 +27,26 @@
|
|||||||
// Disable the button to prevent double submissions
|
// Disable the button to prevent double submissions
|
||||||
isButtonDisabled = true
|
isButtonDisabled = true
|
||||||
|
|
||||||
// Save to the database
|
// Prompt the user to confirm the version change
|
||||||
client()
|
const confirmVersionChange = confirm(
|
||||||
.saveVersion({ instanceId: id, version: version })
|
`Are you sure you want to change the version to ${instanceVersion}?`,
|
||||||
.then(() => {
|
)
|
||||||
return 'saved'
|
|
||||||
})
|
// If they select yes, then update the version in pocketbase
|
||||||
|
if (confirmVersionChange) {
|
||||||
|
// Save to the database
|
||||||
|
client()
|
||||||
|
.saveVersion({ instanceId: id, version: instanceVersion })
|
||||||
|
.then(() => {
|
||||||
|
return 'saved'
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
errorMessage = error.message
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// If they hit cancel, reset the version number back to what it was initially
|
||||||
|
instanceVersion = version
|
||||||
|
}
|
||||||
|
|
||||||
// Set the button back to normal
|
// Set the button back to normal
|
||||||
isButtonDisabled = false
|
isButtonDisabled = false
|
||||||
@ -46,13 +68,21 @@
|
|||||||
> should work.
|
> should work.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{#if errorMessage}
|
||||||
|
<div in:slide class="alert alert-error mb-4">
|
||||||
|
<i class="fa-regular fa-circle-exclamation"></i>
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<form
|
<form
|
||||||
class="flex change-version-form-container-query gap-4"
|
class="flex change-version-form-container-query gap-4"
|
||||||
on:submit={handleSave}
|
on:submit={handleSave}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
required
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={version}
|
bind:value={instanceVersion}
|
||||||
class="input input-bordered w-full"
|
class="input input-bordered w-full"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user