mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
added company slug
This commit is contained in:
@ -34,6 +34,23 @@
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$tc('wizard.company_slug')"
|
||||
:error="
|
||||
v$.companyForm.slug.$error &&
|
||||
v$.companyForm.slug.$errors[0].$message
|
||||
"
|
||||
required
|
||||
>
|
||||
<BaseInput
|
||||
v-model="companyForm.slug"
|
||||
:invalid="v$.companyForm.slug.$error"
|
||||
type="text"
|
||||
name="slug"
|
||||
@input="v$.companyForm.slug.$touch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('wizard.country')"
|
||||
:error="
|
||||
@ -57,9 +74,7 @@
|
||||
track-by="name"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 mb-4 md:grid-cols-2 md:mb-6">
|
||||
<BaseInputGroup :label="$t('wizard.state')">
|
||||
<BaseInput
|
||||
v-model="companyForm.address.state"
|
||||
@ -144,9 +159,9 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, reactive } from 'vue'
|
||||
import { ref, computed, onMounted, reactive, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { required, maxLength, helpers } from '@vuelidate/validators'
|
||||
import { required, minLength, maxLength, helpers } from '@vuelidate/validators'
|
||||
import { useVuelidate } from '@vuelidate/core'
|
||||
import { useGlobalStore } from '@/scripts/admin/stores/global'
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
@ -162,6 +177,7 @@ let logoFileName = ref(null)
|
||||
|
||||
const companyForm = reactive({
|
||||
name: null,
|
||||
slug: null,
|
||||
address: {
|
||||
address_street_1: '',
|
||||
address_street_2: '',
|
||||
@ -188,10 +204,28 @@ onMounted(async () => {
|
||||
})?.id
|
||||
})
|
||||
|
||||
const slugValidator = (value) => {
|
||||
return value == slugify(value)
|
||||
}
|
||||
const rules = {
|
||||
companyForm: {
|
||||
name: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
minLength: helpers.withMessage(
|
||||
t('validation.name_min_length', { count: 3 }),
|
||||
minLength(3)
|
||||
),
|
||||
},
|
||||
slug: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
minLength: helpers.withMessage(
|
||||
t('validation.name_min_length', { count: 3 }),
|
||||
minLength(3)
|
||||
),
|
||||
slugValidator: helpers.withMessage(
|
||||
t('validation.invalid_slug'),
|
||||
slugValidator
|
||||
),
|
||||
},
|
||||
address: {
|
||||
country_id: {
|
||||
@ -249,4 +283,24 @@ async function next() {
|
||||
emit('next', 7)
|
||||
}
|
||||
}
|
||||
|
||||
// watcher for if change company name then auto fill company slug value
|
||||
watch(
|
||||
() => companyForm.name,
|
||||
(currentValue) => {
|
||||
companyForm.slug = slugify(currentValue)
|
||||
}
|
||||
)
|
||||
|
||||
function slugify(string) {
|
||||
return string
|
||||
.toString()
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^\w\-]+/g, '')
|
||||
.replace(/\-\-+/g, '-')
|
||||
.replace(/^-+/, '')
|
||||
.replace(/-+$/, '')
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user