|
@@ -2,6 +2,7 @@ import { ref, Ref } from '@nuxtjs/composition-api'
|
|
|
import VueI18n from 'vue-i18n'
|
|
import VueI18n from 'vue-i18n'
|
|
|
import { QUERY_TYPE } from '~/types/enums'
|
|
import { QUERY_TYPE } from '~/types/enums'
|
|
|
import DataProvider from "~/services/data/dataProvider";
|
|
import DataProvider from "~/services/data/dataProvider";
|
|
|
|
|
+import {ApiResponse} from "~/types/interfaces";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @category composables/form
|
|
* @category composables/form
|
|
@@ -38,7 +39,35 @@ export function useValidator($dataProvider: DataProvider, i18n: VueI18n) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function useHandleSubdomain() {
|
|
|
|
|
+ const subdomainError: Ref<boolean> = ref(false)
|
|
|
|
|
+ const subdomainErrorMessage: Ref<string> = ref('')
|
|
|
|
|
+
|
|
|
|
|
+ const checkSubdomainUnity = async (subdomain: string) => {
|
|
|
|
|
+ const response: ApiResponse = await $dataProvider.invoke({
|
|
|
|
|
+ type: QUERY_TYPE.DEFAULT,
|
|
|
|
|
+ url: '/api/subdomains/?subdomain[]=' + subdomain
|
|
|
|
|
+ })
|
|
|
|
|
+ if (typeof response !== 'undefined') {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ if (response.metadata.totalItems > 0) {
|
|
|
|
|
+ subdomainError.value = true
|
|
|
|
|
+ subdomainErrorMessage.value = i18n.t('this_subdomain_is_already_in_use') as string
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ subdomainError.value = true
|
|
|
|
|
+ subdomainErrorMessage.value = i18n.t('could_not_contact_server_please_try_again') as string
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return {
|
|
|
|
|
+ checkSubdomainUnity,
|
|
|
|
|
+ subdomainError,
|
|
|
|
|
+ subdomainErrorMessage
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
- useHandleSiret
|
|
|
|
|
|
|
+ useHandleSiret,
|
|
|
|
|
+ useHandleSubdomain
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|