mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-05 21:56:48 +00:00
dashboard: enhance error/success messages
This commit is contained in:
parent
13dc94b1e4
commit
2468005e02
@ -19,7 +19,8 @@
|
||||
|
||||
let isHidden = false
|
||||
$: {
|
||||
if (flash) {
|
||||
isHidden = false
|
||||
if (flash && message) {
|
||||
setTimeout(() => {
|
||||
isHidden = true
|
||||
}, 5000)
|
||||
|
@ -165,7 +165,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
|
||||
)
|
||||
|
||||
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)
|
||||
return [e.data.message]
|
||||
return map(e.data.data, (v, k) => (v ? v.message : undefined)).filter(
|
||||
|
@ -20,10 +20,15 @@
|
||||
// Controls visibility of an error message
|
||||
let errorMessage = ''
|
||||
|
||||
let successMessage = ''
|
||||
|
||||
// TODO: What are the limits for this?
|
||||
const onRename = (e: Event) => {
|
||||
e.preventDefault()
|
||||
|
||||
errorMessage = ''
|
||||
successMessage = ''
|
||||
|
||||
// Disable the button to prevent double submissions
|
||||
isButtonDisabled = true
|
||||
|
||||
@ -43,9 +48,11 @@
|
||||
subdomain: instanceNameValidation,
|
||||
},
|
||||
})
|
||||
.then(() => 'saved')
|
||||
.then(() => {
|
||||
successMessage = 'Instance renamed successfully'
|
||||
})
|
||||
.catch((error) => {
|
||||
errorMessage = error.message
|
||||
errorMessage = client().parseError(error).join('\n')
|
||||
})
|
||||
}
|
||||
|
||||
@ -54,42 +61,47 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<CardHeader documentation={`/docs/rename-instance`}>Rename Instance</CardHeader>
|
||||
|
||||
<p class="mb-8">
|
||||
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
|
||||
<div class="max-w-lg">
|
||||
<CardHeader documentation={`/docs/rename-instance`}
|
||||
>Rename Instance</CardHeader
|
||||
>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.rename-instance-form-container-query {
|
||||
flex-direction: column;
|
||||
}
|
||||
<p class="mb-8">
|
||||
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>
|
||||
|
||||
@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 {
|
||||
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
|
||||
let errorMessage = ''
|
||||
let successMessage = ''
|
||||
|
||||
// Update the version number
|
||||
const handleSave = async (e: Event) => {
|
||||
e.preventDefault()
|
||||
|
||||
errorMessage = ''
|
||||
successMessage = ''
|
||||
|
||||
// Disable the button to prevent double submissions
|
||||
isButtonDisabled = true
|
||||
|
||||
@ -41,7 +45,7 @@
|
||||
fields: { version: selectedVersion },
|
||||
})
|
||||
.then(() => {
|
||||
return 'saved'
|
||||
successMessage = 'Version updated successfully'
|
||||
})
|
||||
.catch((error) => {
|
||||
errorMessage = error.message
|
||||
@ -73,6 +77,7 @@
|
||||
> of PocketBase.
|
||||
</div>
|
||||
|
||||
<AlertBar message={successMessage} type="success" flash />
|
||||
<AlertBar message={errorMessage} type="error" />
|
||||
|
||||
<form
|
||||
|
@ -1,12 +1,6 @@
|
||||
import Ajv, { JSONSchemaType } from 'ajv'
|
||||
import type { JsonObject } from 'type-fest'
|
||||
import {
|
||||
ClientResponseError,
|
||||
LoggerService,
|
||||
PocketBase,
|
||||
RestCommands,
|
||||
RestMethods,
|
||||
} from '..'
|
||||
import { LoggerService, PocketBase, RestCommands, RestMethods } from '..'
|
||||
|
||||
export type RestHelperConfig = {
|
||||
client: PocketBase
|
||||
@ -55,18 +49,9 @@ export const createRestHelper = (config: RestHelperConfig) => {
|
||||
|
||||
dbg({ url, options })
|
||||
|
||||
try {
|
||||
const res = await client.send(url, options)
|
||||
dbg(res)
|
||||
return res
|
||||
} catch (e) {
|
||||
if (e instanceof ClientResponseError) {
|
||||
error(`REST error: ${e.originalError}`)
|
||||
throw e.originalError
|
||||
}
|
||||
error(`REST error: ${e}`)
|
||||
throw e
|
||||
}
|
||||
const res = await client.send(url, options)
|
||||
dbg(res)
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user