import { isRoleValid } from "@staticdeploy/core" ; import set from "lodash/set" ; import { IInternalFormValues } from "./IFormValues" ; export default function validate ( values ) { const errors = { } ; if ( ! values . name ) { errors . name = "Required" ; } if ( values . roles ) { values . roles . forEach ( ( role , index ) => { if ( ! role ) { set ( errors , [ "roles" , index ] , "Required" ) ; } else if ( ! isRoleValid ( role ) ) { set ( errors , [ "roles" , index ] , "Invalid role" ) ; } } ) ; } return errors ; }