diff --git a/packages/web/pages/tools/import/file.tsx b/packages/web/pages/tools/import/file.tsx index e8a353dcf..67f4cf70a 100644 --- a/packages/web/pages/tools/import/file.tsx +++ b/packages/web/pages/tools/import/file.tsx @@ -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() const [uploadState, setUploadState] = useState('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') diff --git a/packages/web/utils/csvValidator.ts b/packages/web/utils/csvValidator.ts index e7c26bb69..7ba863734 100644 --- a/packages/web/utils/csvValidator.ts +++ b/packages/web/utils/csvValidator.ts @@ -39,6 +39,9 @@ const csvConfig: ValidatorConfig = { required: false, optional: true, validate: function (state) { + if (!state) { + return true + } return isStateValid(state) }, },