Skip to content

Commit

Permalink
Merge pull request #6807 from TheThingsNetwork/fix/collab-validation
Browse files Browse the repository at this point in the history
Fix collaborator validation
  • Loading branch information
kschiffer committed Jan 8, 2024
2 parents 96cf13c + 316f017 commit 4822a0c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/webui/containers/collaborator-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import React, { useCallback, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { defineMessages } from 'react-intl'
import { isEmpty } from 'lodash'

import Form from '@ttn-lw/components/form'
import Notification from '@ttn-lw/components/notification'
Expand All @@ -35,7 +36,11 @@ import { userId as collaboratorIdRegexp } from '@ttn-lw/lib/regexp'

import useCollaboratorData from './hooks'

const isNotEmpty = collaborator => collaborator === ''
const emptyCollaboratorCheck = collab =>
!(collab === '') &&
!(collab === undefined) &&
!(collab === null) &&
!(collab instanceof Object && Object.values(collab).every(val => !Boolean(val) || isEmpty(val)))

const collaboratorOrganizationSchema = Yup.object().shape({
organization_id: Yup.string().matches(collaboratorIdRegexp, sharedMessages.validateAlphanum),
Expand All @@ -54,7 +59,7 @@ const validationSchema = Yup.object().shape({
otherwise: schema => schema.concat(collaboratorUserSchema),
}),
})
.test('is not empty', sharedMessages.validateRequired, isNotEmpty),
.test('collaborator is not empty', sharedMessages.validateRequired, emptyCollaboratorCheck),
rights: Yup.array().min(1, sharedMessages.validateRights),
})

Expand Down

0 comments on commit 4822a0c

Please sign in to comment.