case insensitive regex for app names

This commit is contained in:
Martin McKeaveney 2021-02-23 18:37:37 +00:00
parent d250afe9c0
commit 03512da423
1 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,6 @@
<script> <script>
import { writable, get as svelteGet } from "svelte/store" import { writable, get as svelteGet } from "svelte/store"
import { notifier } from "builderStore/store/notifications"
import { import {
store, store,
automationStore, automationStore,
@ -61,7 +62,15 @@
const existingAppNames = svelteGet(hostingStore).deployedAppNames const existingAppNames = svelteGet(hostingStore).deployedAppNames
infoValidation.applicationName = string() infoValidation.applicationName = string()
.required("Your application must have a name.") .required("Your application must have a name.")
.notOneOf(existingAppNames) .test(
"non-existing-app-name",
"App with same name already exists. Please try another app name.",
value =>
!existingAppNames.some(appName =>
new RegExp(appName, "ig").test(value)
)
)
steps = [buildStep(Info), buildStep(User)] steps = [buildStep(Info), buildStep(User)]
validationSchemas = [infoValidation, userValidation] validationSchemas = [infoValidation, userValidation]
} }
@ -120,6 +129,11 @@
template, template,
}) })
const appJson = await appResp.json() const appJson = await appResp.json()
if (!appResp.ok) {
throw new Error(appJson.message)
}
analytics.captureEvent("App Created", { analytics.captureEvent("App Created", {
name: $createAppStore.values.applicationName, name: $createAppStore.values.applicationName,
appId: appJson._id, appId: appJson._id,
@ -150,6 +164,8 @@
$goto(`/${appJson._id}`) $goto(`/${appJson._id}`)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
notifier.danger(error)
submitting = false
} }
} }