function headNodeValidate()

in frontend/src/old-pages/Configure/HeadNode.tsx [65:177]


function headNodeValidate() {
  const subnetPath = [...headNodePath, 'Networking', 'SubnetId']
  const subnetValue = getState(subnetPath)

  const rootVolumeSizePath = [
    ...headNodePath,
    'LocalStorage',
    'RootVolume',
    'Size',
  ]
  const rootVolumeValue = getState(rootVolumeSizePath)

  const instanceTypePath = [...headNodePath, 'InstanceType']
  const instanceTypeValue = getState(instanceTypePath)

  const actionsPath = [...headNodePath, 'CustomActions']

  const onStartPath = [...actionsPath, 'OnNodeStart']
  const onStart = getState(onStartPath)

  const onConfiguredPath = [...actionsPath, 'OnNodeConfigured']
  const onConfigured = getState(onConfiguredPath)

  const onUpdatedPath = [...actionsPath, 'OnNodeUpdated']
  const onUpdated = getState(onUpdatedPath)

  let valid = true

  if (!subnetValue) {
    setState(
      [...errorsPath, 'subnet'],
      i18next.t('wizard.headNode.validation.selectSubnet'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'subnet'])
  }

  if (!instanceTypeValue) {
    setState(
      [...errorsPath, 'instanceType'],
      i18next.t('wizard.headNode.validation.selectInstanceType'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'instanceType'])
  }

  if (rootVolumeValue === '') {
    setState(
      [...errorsPath, 'rootVolume'],
      i18next.t('wizard.headNode.validation.setRootVolumeSize'),
    )
    valid = false
  } else if (
    rootVolumeValue &&
    (!Number.isInteger(rootVolumeValue) || rootVolumeValue < 35)
  ) {
    setState(
      [...errorsPath, 'rootVolume'],
      i18next.t('wizard.headNode.validation.rootVolumeMinimum'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'rootVolume'])
  }

  if (
    onStart &&
    getState([...onStartPath, 'Args']) &&
    !getState([...onStartPath, 'Script'])
  ) {
    setState(
      [...errorsPath, 'onStart'],
      i18next.t('wizard.headNode.validation.scriptWithArgs'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'onStart'])
  }

  if (
    onConfigured &&
    getState([...onConfiguredPath, 'Args']) &&
    !getState([...onConfiguredPath, 'Script'])
  ) {
    setState(
      [...errorsPath, 'onConfigured'],
      i18next.t('wizard.headNode.validation.scriptWithArgs'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'onConfigured'])
  }

  if (
    onUpdated &&
    getState([...onUpdatedPath, 'Args']) &&
    !getState([...onUpdatedPath, 'Script'])
  ) {
    setState(
      [...errorsPath, 'onUpdated'],
      i18next.t('wizard.headNode.validation.scriptWithArgs'),
    )
    valid = false
  } else {
    clearState([...errorsPath, 'onUpdated'])
  }

  setState([...errorsPath, 'validated'], true)

  return valid
}