|
@@ -7,9 +7,11 @@
|
|
|
|
|
|
|
|
<UiForm
|
|
<UiForm
|
|
|
:id="id"
|
|
:id="id"
|
|
|
|
|
+ ref="form"
|
|
|
:model="model"
|
|
:model="model"
|
|
|
:query="query()"
|
|
:query="query()"
|
|
|
- :submitActions="submitActions">
|
|
|
|
|
|
|
+ :submitActions="submitActions"
|
|
|
|
|
+ >
|
|
|
<template #form.input="{entry, updateRepository}">
|
|
<template #form.input="{entry, updateRepository}">
|
|
|
<v-container fluid class="container">
|
|
<v-container fluid class="container">
|
|
|
<v-row>
|
|
<v-row>
|
|
@@ -24,11 +26,10 @@
|
|
|
label="subdomain"
|
|
label="subdomain"
|
|
|
:data="entry['subdomain']"
|
|
:data="entry['subdomain']"
|
|
|
type="string"
|
|
type="string"
|
|
|
- :rules="rules().subdomainRules"
|
|
|
|
|
- :error="subdomainError"
|
|
|
|
|
- :error-message="subdomainErrorMessage"
|
|
|
|
|
- @update="checkSubdomainHook($event, updateRepository)"
|
|
|
|
|
|
|
+ :rules="rules()"
|
|
|
|
|
+ @change="checkSubdomainHook($event); updateRepository(entry['subdomain'], 'subdomain')"
|
|
|
/>
|
|
/>
|
|
|
|
|
+ <span v-if="entry['subdomain'] && subdomainAvailable">Ce sous-domaine est disponible</span>
|
|
|
</v-col>
|
|
</v-col>
|
|
|
|
|
|
|
|
</v-row>
|
|
</v-row>
|
|
@@ -51,12 +52,12 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
-import {defineComponent, computed, useContext, useFetch} from '@nuxtjs/composition-api'
|
|
|
|
|
|
|
+import {defineComponent, computed, useContext, Ref, ref} from '@nuxtjs/composition-api'
|
|
|
import { Repository as VuexRepository } from '@vuex-orm/core/dist/src/repository/Repository'
|
|
import { Repository as VuexRepository } from '@vuex-orm/core/dist/src/repository/Repository'
|
|
|
import { Query, Model } from '@vuex-orm/core'
|
|
import { Query, Model } from '@vuex-orm/core'
|
|
|
-import {QUERY_TYPE, SUBMIT_TYPE} from '~/types/enums'
|
|
|
|
|
|
|
+import {SUBMIT_TYPE} from '~/types/enums'
|
|
|
import { repositoryHelper } from '~/services/store/repository'
|
|
import { repositoryHelper } from '~/services/store/repository'
|
|
|
-import {AnyJson, ApiResponse, MobytUserStatus} from "~/types/interfaces";
|
|
|
|
|
|
|
+import {AnyJson} from "~/types/interfaces";
|
|
|
import {Subdomain} from "~/models/Organization/Subdomain";
|
|
import {Subdomain} from "~/models/Organization/Subdomain";
|
|
|
import {useValidator} from "~/composables/form/useValidator";
|
|
import {useValidator} from "~/composables/form/useValidator";
|
|
|
|
|
|
|
@@ -71,8 +72,10 @@ export default defineComponent({
|
|
|
const {$dataProvider, app:{i18n}} = useContext()
|
|
const {$dataProvider, app:{i18n}} = useContext()
|
|
|
const repository: VuexRepository<Model> = repositoryHelper.getRepository(Subdomain)
|
|
const repository: VuexRepository<Model> = repositoryHelper.getRepository(Subdomain)
|
|
|
const query: Query = repository.query()
|
|
const query: Query = repository.query()
|
|
|
|
|
+ const subdomainAvailable: Ref<boolean | null> = ref(null)
|
|
|
|
|
+ const form = ref(null);
|
|
|
|
|
|
|
|
- const { subdomainError, subdomainErrorMessage, checkSubdomainUnity } = useValidator($dataProvider, i18n).useHandleSubdomain()
|
|
|
|
|
|
|
+ const { checkSubdomainAvailability } = useValidator($dataProvider, i18n).useHandleSubdomain()
|
|
|
|
|
|
|
|
const submitActions = computed(() => {
|
|
const submitActions = computed(() => {
|
|
|
let actions:AnyJson = {}
|
|
let actions:AnyJson = {}
|
|
@@ -80,18 +83,11 @@ export default defineComponent({
|
|
|
return actions
|
|
return actions
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // TODO: unity error message don't show up
|
|
|
|
|
- // TODO: submit is not blocked even when subdomain is invalid
|
|
|
|
|
- const checkSubdomainHook = async (subdomain: string, updateRepository: any) => {
|
|
|
|
|
- const valid = (subdomain?.match(/^[\w\-]{2,60}$/) !== null)
|
|
|
|
|
- console.log('valid: ' + valid)
|
|
|
|
|
- if (!valid) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- await checkSubdomainUnity(subdomain)
|
|
|
|
|
- console.log('unity error: ' + subdomainError.value + ' - ' + subdomainErrorMessage.value)
|
|
|
|
|
- if (!subdomainError.value) {
|
|
|
|
|
- updateRepository(subdomain, 'subdomain')
|
|
|
|
|
|
|
+ const checkSubdomainHook = async (subdomain: string | null) => {
|
|
|
|
|
+ subdomainAvailable.value = null
|
|
|
|
|
+ if (subdomain !== null && subdomain.match(/^[\w\-]{2,60}$/) !== null) {
|
|
|
|
|
+ subdomainAvailable.value = await checkSubdomainAvailability(subdomain);
|
|
|
|
|
+ (form.value as any).validate()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -99,25 +95,20 @@ export default defineComponent({
|
|
|
return {
|
|
return {
|
|
|
model: Subdomain,
|
|
model: Subdomain,
|
|
|
query: () => query,
|
|
query: () => query,
|
|
|
- rules: () => getRules(i18n),
|
|
|
|
|
- panel: 0,
|
|
|
|
|
submitActions,
|
|
submitActions,
|
|
|
- subdomainError,
|
|
|
|
|
- subdomainErrorMessage,
|
|
|
|
|
- checkSubdomainHook
|
|
|
|
|
|
|
+ form,
|
|
|
|
|
+ checkSubdomainHook,
|
|
|
|
|
+ subdomainAvailable,
|
|
|
|
|
+ rules: () => [
|
|
|
|
|
+ (subdomain: string | null) => (subdomain !== null) || i18n.t('please_enter_a_value_for_the_subdomain'),
|
|
|
|
|
+ (subdomain: string | null) => (subdomain !== null && subdomain.length >= 2 && subdomain.length <=60) || i18n.t('subdomain_need_to_have_0_to_60_cars'),
|
|
|
|
|
+ (subdomain: string | null) => (subdomain !== null && subdomain.match(/^[\w\-]+$/) !== null) || i18n.t('subdomain_can_not_contain_spaces_or_special_cars'),
|
|
|
|
|
+ () => (subdomainAvailable.value === true) || i18n.t('this_subdomain_is_already_in_use')
|
|
|
|
|
+ ]
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
|
repositoryHelper.cleanRepository(Subdomain)
|
|
repositoryHelper.cleanRepository(Subdomain)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
-function getRules (i18n: any) {
|
|
|
|
|
- return {
|
|
|
|
|
- subdomainRules: [
|
|
|
|
|
- (subdomain: string) => (subdomain?.length <= 60 && subdomain?.length >= 2) || i18n.t('subdomain_need_to_have_0_to_60_cars'),
|
|
|
|
|
- (subdomain: string) => subdomain?.match(/^[\w\-]+$/) !== null || i18n.t('subdomain_can_not_contain_spaces_or_special_cars'),
|
|
|
|
|
- ]
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
</script>
|
|
</script>
|