Browse Source

fix: vaidation helper function

pull/6420/head
sreehari jayaraj 1 year ago
parent
commit
d757e1d056
  1. 16
      packages/nc-gui/components/account/Token.vue

16
packages/nc-gui/components/account/Token.vue

@ -77,7 +77,7 @@ loadTokens()
const isModalOpen = ref(false)
const tokenDesc = ref('')
const tokenToCopy = ref('')
const isNotValidTokenName = ref(false)
const isValidTokenName = ref(false)
const deleteToken = async (token: string): Promise<void> => {
try {
@ -93,10 +93,16 @@ const deleteToken = async (token: string): Promise<void> => {
tokenDesc.value = ''
}
const validateTokenName = (tokenName: string | undefined) => {
if (!tokenName) return false
return tokenName.length < 255
}
const generateToken = async () => {
isNotValidTokenName.value = !selectedTokenData.value.description?.length || selectedTokenData.value.description?.length > 255
isValidTokenName.value = validateTokenName(selectedTokenData.value.description)
if (isNotValidTokenName.value) return
if (!isValidTokenName.value) return
try {
await api.orgTokens.create(selectedTokenData.value)
showNewTokenModal.value = false
@ -145,7 +151,7 @@ const errorMessage = computed(() => {
const handleCancel = () => {
showNewTokenModal.value = false
isNotValidTokenName.value = false
isValidTokenName.value = false
}
</script>
@ -191,7 +197,7 @@ const handleCancel = () => {
placeholder="Token Name"
data-testid="nc-token-input"
/>
<span v-if="isNotValidTokenName" class="text-red-500 text-xs font-light mt-1.5 ml-1">{{ errorMessage }} </span>
<span v-if="!isValidTokenName" class="text-red-500 text-xs font-light mt-1.5 ml-1">{{ errorMessage }} </span>
</div>
<div class="flex gap-2 justify-start">
<NcButton v-if="!isLoading" type="secondary" size="small" @click="handleCancel">

Loading…
Cancel
Save