|
|
@@ -23,9 +23,11 @@
|
|
|
field="subdomain"
|
|
|
label="subdomain"
|
|
|
:data="entry['subdomain']"
|
|
|
- @update="updateRepository"
|
|
|
type="string"
|
|
|
:rules="rules().subdomainRules"
|
|
|
+ :error="subdomainError"
|
|
|
+ :error-message="subdomainErrorMessage"
|
|
|
+ @update="checkSubdomainHook($event, updateRepository)"
|
|
|
/>
|
|
|
</v-col>
|
|
|
|
|
|
@@ -49,13 +51,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import {defineComponent, computed, useContext} from '@nuxtjs/composition-api'
|
|
|
+import {defineComponent, computed, useContext, useFetch} from '@nuxtjs/composition-api'
|
|
|
import { Repository as VuexRepository } from '@vuex-orm/core/dist/src/repository/Repository'
|
|
|
import { Query, Model } from '@vuex-orm/core'
|
|
|
-import { SUBMIT_TYPE} from '~/types/enums'
|
|
|
+import {QUERY_TYPE, SUBMIT_TYPE} from '~/types/enums'
|
|
|
import { repositoryHelper } from '~/services/store/repository'
|
|
|
-import {AnyJson} from "~/types/interfaces";
|
|
|
+import {AnyJson, ApiResponse, MobytUserStatus} from "~/types/interfaces";
|
|
|
import {Subdomain} from "~/models/Organization/Subdomain";
|
|
|
+import {useValidator} from "~/composables/form/useValidator";
|
|
|
|
|
|
export default defineComponent({
|
|
|
props: {
|
|
|
@@ -65,23 +68,43 @@ export default defineComponent({
|
|
|
}
|
|
|
},
|
|
|
setup () {
|
|
|
- const {app:{i18n}} = useContext()
|
|
|
+ const {$dataProvider, app:{i18n}} = useContext()
|
|
|
const repository: VuexRepository<Model> = repositoryHelper.getRepository(Subdomain)
|
|
|
const query: Query = repository.query()
|
|
|
|
|
|
+ const { subdomainError, subdomainErrorMessage, checkSubdomainUnity } = useValidator($dataProvider, i18n).useHandleSubdomain()
|
|
|
+
|
|
|
const submitActions = computed(() => {
|
|
|
let actions:AnyJson = {}
|
|
|
actions[SUBMIT_TYPE.SAVE_AND_BACK] = { path: `/parameters/communication` }
|
|
|
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')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** todo Computed properties needs to be returned as functions until nuxt3 : https://github.com/nuxt-community/composition-api/issues/207 **/
|
|
|
return {
|
|
|
model: Subdomain,
|
|
|
query: () => query,
|
|
|
rules: () => getRules(i18n),
|
|
|
panel: 0,
|
|
|
- submitActions
|
|
|
+ submitActions,
|
|
|
+ subdomainError,
|
|
|
+ subdomainErrorMessage,
|
|
|
+ checkSubdomainHook
|
|
|
}
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
@@ -92,8 +115,8 @@ export default defineComponent({
|
|
|
function getRules (i18n: any) {
|
|
|
return {
|
|
|
subdomainRules: [
|
|
|
- (subdomain: string) => (subdomain?.length <= 60) || i18n.t('subdomain_need_to_have_less_than_60_cars'),
|
|
|
- (subdomain: string) => (true) || i18n.t('this_subdomain_is_already_used'),
|
|
|
+ (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'),
|
|
|
]
|
|
|
}
|
|
|
}
|