Handle undefined url

This commit is contained in:
Rory Powell 2022-01-26 13:39:40 +00:00
parent f66a8b888f
commit 3d533d9f13
4 changed files with 14 additions and 4 deletions

View File

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

View File

@ -41,7 +41,11 @@
)
function getUrl(app) {
return `/app${app.url}`
if (app.url) {
return `/app${app.url}`
} else {
return `/${app.prodId}`
}
}
</script>

View File

@ -161,7 +161,11 @@
}
const viewApp = app => {
window.open(`/app${app.url}`)
if (app.url) {
window.open(`/app${app.url}`)
} else {
window.open(`/${app.prodId}`)
}
}
const editApp = app => {

View File

@ -43,7 +43,9 @@ async function getAppIdFromUrl(ctx) {
// search prod apps for a url that matches, exclude dev where id is always used
const apps = await getAllApps(CouchDB, { dev: false })
const app = apps.filter(a => a.url.toLowerCase() === possibleAppUrl)[0]
const app = apps.filter(
a => a.url && a.url.toLowerCase() === possibleAppUrl
)[0]
if (app && app.appId) {
return app.appId