mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-06 14:16:41 +00:00
dashboard: enhance error/success messages
This commit is contained in:
parent
13dc94b1e4
commit
2468005e02
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
let isHidden = false
|
let isHidden = false
|
||||||
$: {
|
$: {
|
||||||
if (flash) {
|
isHidden = false
|
||||||
|
if (flash && message) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isHidden = true
|
isHidden = true
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
@ -165,7 +165,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const parseError = (e: Error): string[] => {
|
const parseError = (e: Error): string[] => {
|
||||||
if (!(e instanceof ClientResponseError)) return [e.message]
|
if (!(e instanceof ClientResponseError)) return [`${e}`]
|
||||||
if (e.data.message && keys(e.data.data).length === 0)
|
if (e.data.message && keys(e.data.data).length === 0)
|
||||||
return [e.data.message]
|
return [e.data.message]
|
||||||
return map(e.data.data, (v, k) => (v ? v.message : undefined)).filter(
|
return map(e.data.data, (v, k) => (v ? v.message : undefined)).filter(
|
||||||
|
@ -20,10 +20,15 @@
|
|||||||
// Controls visibility of an error message
|
// Controls visibility of an error message
|
||||||
let errorMessage = ''
|
let errorMessage = ''
|
||||||
|
|
||||||
|
let successMessage = ''
|
||||||
|
|
||||||
// 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()
|
||||||
|
|
||||||
|
errorMessage = ''
|
||||||
|
successMessage = ''
|
||||||
|
|
||||||
// Disable the button to prevent double submissions
|
// Disable the button to prevent double submissions
|
||||||
isButtonDisabled = true
|
isButtonDisabled = true
|
||||||
|
|
||||||
@ -43,9 +48,11 @@
|
|||||||
subdomain: instanceNameValidation,
|
subdomain: instanceNameValidation,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => 'saved')
|
.then(() => {
|
||||||
|
successMessage = 'Instance renamed successfully'
|
||||||
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
errorMessage = error.message
|
errorMessage = client().parseError(error).join('\n')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,42 +61,47 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CardHeader documentation={`/docs/rename-instance`}>Rename Instance</CardHeader>
|
<div class="max-w-lg">
|
||||||
|
<CardHeader documentation={`/docs/rename-instance`}
|
||||||
<p class="mb-8">
|
>Rename Instance</CardHeader
|
||||||
Renaming your instance will cause it to become <strong class="text-error"
|
|
||||||
>inaccessible</strong
|
|
||||||
> by the old instance name. You also may not be able to change it back if someone
|
|
||||||
else choose it.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<AlertBar message={errorMessage} type="error" />
|
|
||||||
|
|
||||||
<form
|
|
||||||
class="flex rename-instance-form-container-query gap-4"
|
|
||||||
on:submit={onRename}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
title="Only letters and dashes are allowed"
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
bind:value={formSubdomain}
|
|
||||||
class="input input-bordered w-full"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button type="submit" class="btn btn-error" disabled={isButtonDisabled}
|
|
||||||
>Rename Instance</button
|
|
||||||
>
|
>
|
||||||
</form>
|
|
||||||
|
|
||||||
<style>
|
<p class="mb-8">
|
||||||
.rename-instance-form-container-query {
|
Renaming your instance will cause it to become <strong class="text-error"
|
||||||
flex-direction: column;
|
>inaccessible</strong
|
||||||
}
|
> by the old instance name. You also may not be able to change it back if someone
|
||||||
|
else choose it.
|
||||||
|
</p>
|
||||||
|
|
||||||
@container (min-width: 400px) {
|
<AlertBar message={successMessage} type="success" flash />
|
||||||
|
<AlertBar message={errorMessage} type="error" />
|
||||||
|
|
||||||
|
<form
|
||||||
|
class="flex rename-instance-form-container-query gap-4"
|
||||||
|
on:submit={onRename}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
title="Only letters and dashes are allowed"
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
bind:value={formSubdomain}
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-error" disabled={isButtonDisabled}
|
||||||
|
>Rename Instance</button
|
||||||
|
>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<style>
|
||||||
.rename-instance-form-container-query {
|
.rename-instance-form-container-query {
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</style>
|
@container (min-width: 400px) {
|
||||||
|
.rename-instance-form-container-query {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</div>
|
||||||
|
@ -18,11 +18,15 @@
|
|||||||
|
|
||||||
// Controls visibility of an error message
|
// Controls visibility of an error message
|
||||||
let errorMessage = ''
|
let errorMessage = ''
|
||||||
|
let successMessage = ''
|
||||||
|
|
||||||
// Update the version number
|
// Update the version number
|
||||||
const handleSave = async (e: Event) => {
|
const handleSave = async (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
errorMessage = ''
|
||||||
|
successMessage = ''
|
||||||
|
|
||||||
// Disable the button to prevent double submissions
|
// Disable the button to prevent double submissions
|
||||||
isButtonDisabled = true
|
isButtonDisabled = true
|
||||||
|
|
||||||
@ -41,7 +45,7 @@
|
|||||||
fields: { version: selectedVersion },
|
fields: { version: selectedVersion },
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return 'saved'
|
successMessage = 'Version updated successfully'
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
errorMessage = error.message
|
errorMessage = error.message
|
||||||
@ -73,6 +77,7 @@
|
|||||||
> of PocketBase.
|
> of PocketBase.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<AlertBar message={successMessage} type="success" flash />
|
||||||
<AlertBar message={errorMessage} type="error" />
|
<AlertBar message={errorMessage} type="error" />
|
||||||
|
|
||||||
<form
|
<form
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
import Ajv, { JSONSchemaType } from 'ajv'
|
import Ajv, { JSONSchemaType } from 'ajv'
|
||||||
import type { JsonObject } from 'type-fest'
|
import type { JsonObject } from 'type-fest'
|
||||||
import {
|
import { LoggerService, PocketBase, RestCommands, RestMethods } from '..'
|
||||||
ClientResponseError,
|
|
||||||
LoggerService,
|
|
||||||
PocketBase,
|
|
||||||
RestCommands,
|
|
||||||
RestMethods,
|
|
||||||
} from '..'
|
|
||||||
|
|
||||||
export type RestHelperConfig = {
|
export type RestHelperConfig = {
|
||||||
client: PocketBase
|
client: PocketBase
|
||||||
@ -55,18 +49,9 @@ export const createRestHelper = (config: RestHelperConfig) => {
|
|||||||
|
|
||||||
dbg({ url, options })
|
dbg({ url, options })
|
||||||
|
|
||||||
try {
|
const res = await client.send(url, options)
|
||||||
const res = await client.send(url, options)
|
dbg(res)
|
||||||
dbg(res)
|
return res
|
||||||
return res
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ClientResponseError) {
|
|
||||||
error(`REST error: ${e.originalError}`)
|
|
||||||
throw e.originalError
|
|
||||||
}
|
|
||||||
error(`REST error: ${e}`)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user