mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
allow state to be empty
This commit is contained in:
parent
755fb66588
commit
8ee591943f
2 changed files with 4 additions and 65 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import 'antd/dist/antd.compact.css'
|
||||
import { ValidatorConfig } from 'csv-file-validator'
|
||||
import { ChangeEvent, useState } from 'react'
|
||||
import { SyncLoader } from 'react-spinners'
|
||||
import { Button } from '../../../components/elements/Button'
|
||||
|
|
@ -25,70 +24,6 @@ export default function ImportUploader(): JSX.Element {
|
|||
const [type, setType] = useState<UploadImportFileType>()
|
||||
const [uploadState, setUploadState] = useState<UploadState>('none')
|
||||
|
||||
const isUrlValid = (url: string | number | boolean) => {
|
||||
if (typeof url !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(url)
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const isStateValid = (state: string | number | boolean) => {
|
||||
if (typeof state !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
const validStates = ['SUCCEEDED', 'ARCHIVED']
|
||||
return validStates.includes(state.toUpperCase())
|
||||
}
|
||||
|
||||
const csvConfig: ValidatorConfig = {
|
||||
headers: [
|
||||
{
|
||||
name: 'url',
|
||||
inputName: 'url',
|
||||
required: true,
|
||||
unique: true,
|
||||
validate: function (url) {
|
||||
return isUrlValid(url)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'state',
|
||||
inputName: 'state',
|
||||
required: false,
|
||||
optional: true,
|
||||
validate: function (state) {
|
||||
return isStateValid(state)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'labels',
|
||||
inputName: 'labels',
|
||||
required: false,
|
||||
optional: true,
|
||||
isArray: true,
|
||||
},
|
||||
{
|
||||
name: 'saved_at',
|
||||
inputName: 'saved_at',
|
||||
required: false,
|
||||
optional: true,
|
||||
},
|
||||
{
|
||||
name: 'published_at',
|
||||
inputName: 'published_at',
|
||||
required: false,
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const onFinish = (values: unknown) => {
|
||||
console.log(values)
|
||||
}
|
||||
|
|
@ -117,6 +52,7 @@ export default function ImportUploader(): JSX.Element {
|
|||
// validate csv file
|
||||
try {
|
||||
const csvData = await validateCsvFile(file)
|
||||
console.log(csvData.data)
|
||||
if (csvData.inValidData.length > 0) {
|
||||
setErrorMessage(csvData.inValidData[0].message)
|
||||
setUploadState('none')
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ const csvConfig: ValidatorConfig = {
|
|||
required: false,
|
||||
optional: true,
|
||||
validate: function (state) {
|
||||
if (!state) {
|
||||
return true
|
||||
}
|
||||
return isStateValid(state)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue