1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00

Handle undefined url

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

View file

@ -51,7 +51,7 @@ 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 => appUrl?.toLowerCase() === value.toLowerCase())
} }
) )
.test("valid-url", "Not a valid URL", value => { .test("valid-url", "Not a valid URL", value => {

View file

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

View file

@ -161,7 +161,11 @@
} }
const viewApp = app => { const viewApp = app => {
window.open(`/app${app.url}`) if (app.url) {
window.open(`/app${app.url}`)
} else {
window.open(`/${app.prodId}`)
}
} }
const editApp = app => { 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 // search prod apps for a url that matches, exclude dev where id is always used
const apps = await getAllApps(CouchDB, { dev: false }) 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) { if (app && app.appId) {
return app.appId return app.appId