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

Loading…
Cancel
Save