App update validation updates

This commit is contained in:
Dean 2023-06-29 16:51:32 +01:00
parent 8d98f6ac02
commit a5dae87fa9
4 changed files with 27 additions and 6 deletions

View File

@ -348,7 +348,7 @@
name: $store.name, name: $store.name,
url: $store.url, url: $store.url,
icon: $store.icon, icon: $store.icon,
devId: $store.appId, appId: $store.appId,
}} }}
onUpdateComplete={async () => { onUpdateComplete={async () => {
await initialiseApp() await initialiseApp()

View File

@ -16,6 +16,9 @@
export let app export let app
export let onUpdateComplete export let onUpdateComplete
$: appIdParts = app.appId ? app.appId?.split("_") : []
$: appId = appIdParts.slice(-1)[0]
const values = writable({ const values = writable({
name: app.name, name: app.name,
url: app.url, url: app.url,
@ -35,8 +38,20 @@
const setupValidation = async () => { const setupValidation = async () => {
const applications = svelteGet(apps) const applications = svelteGet(apps)
appValidation.name(validation, { apps: applications, currentApp: app }) appValidation.name(validation, {
appValidation.url(validation, { apps: applications, currentApp: app }) apps: applications,
currentApp: {
...app,
appId,
},
})
appValidation.url(validation, {
apps: applications,
currentApp: {
...app,
appId,
},
})
// init validation // init validation
const { url } = $values const { url } = $values
validation.check({ validation.check({
@ -47,7 +62,7 @@
async function updateApp() { async function updateApp() {
try { try {
await apps.update(app.devId, { await apps.update(app.appId, {
name: $values.name?.trim(), name: $values.name?.trim(),
url: $values.url?.trim(), url: $values.url?.trim(),
icon: { icon: {

View File

@ -52,7 +52,13 @@ export const url = (validation, { apps, currentApp } = { apps: [] }) => {
} }
return !apps return !apps
.map(app => app.url) .map(app => app.url)
.some(appUrl => appUrl?.toLowerCase() === value.toLowerCase()) .some(appUrl => {
const url =
appUrl?.[0] === "/"
? appUrl.substring(1, appUrl.length)
: appUrl
return url?.toLowerCase() === value.toLowerCase()
})
} }
) )
.test("valid-url", "Not a valid URL", value => { .test("valid-url", "Not a valid URL", value => {

View File

@ -78,7 +78,7 @@
name: $store.name, name: $store.name,
url: $store.url, url: $store.url,
icon: $store.icon, icon: $store.icon,
devId: $store.appId, appId: $store.appId,
}} }}
onUpdateComplete={async () => { onUpdateComplete={async () => {
await initialiseApp() await initialiseApp()