Skip to content

Commit

Permalink
removing comments and redundant code from createDataset files
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Mangan committed Jan 5, 2024
1 parent 97acbe9 commit 4da6060
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 106 deletions.
29 changes: 0 additions & 29 deletions src/dataset/domain/useCases/createDataset.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
// import { DatasetRepository } from '../repositories/DatasetRepository'
// import { AddNewDataset } from '../repositories/DatasetRepository'
// import { Dataset } from '../models/Dataset'

export interface CreateDatasetFormData {
createDatasetTitle: string
}

export class AddNewDataset {
validateCreateDatasetFormData(formData: CreateDatasetFormData): boolean {
// Add validation logic here
return formData.createDatasetTitle.trim() !== ''
}

async submitCreateDatasetFormData(): Promise<string> {
// Add business logic for form submission here
return Promise.resolve('Form submitted successfully!')
}
}

// export async function CreateDataset(formData: CreateDatasetFormData): Promise<AddNewDataset> {
// try {
// const dataset = new AddNewDataset()
// if (!dataset.validateCreateDatasetFormData(formData)) {
// throw new Error('Invalid form data')
// }
// await dataset.submitCreateDatasetFormData()
// return dataset
// } catch (error) {
// throw new Error(`Dataset creation failed`)
// }
// }

export class CreateDataset {
submitDataset = async (formData: CreateDatasetFormData): Promise<string> => {
console.log('Submitting dataset:', formData)
Expand Down
78 changes: 1 addition & 77 deletions src/sections/create-dataset/CreateDatasetContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// containers/FormContainer.tsx

import { createContext, useContext, ReactNode } from 'react'
import CreateDatasetFormPresenter from './CreateDatasetForm'
import { useTranslation } from 'react-i18next'
Expand All @@ -10,10 +8,6 @@ import { SeparationLine } from '../../components/layout/SeparationLine/Separatio
interface CreateDatasetFormProps {
submitDataset: (formData: CreateDatasetFormData) => Promise<string>
validateCreateDatasetFormData: (formData: CreateDatasetFormData) => boolean
// handleCreateDatasetFieldChange: (event: ChangeEvent<HTMLInputElement>) => void
// handleCreateDatasetSubmit: (event: FormEvent<HTMLFormElement>) => void
// submitting: boolean
// submitComplete: boolean
}

const DatasetContext = createContext<CreateDatasetFormProps>({} as CreateDatasetFormProps)
Expand Down Expand Up @@ -41,69 +35,7 @@ export const DatasetProvider: React.FC<DatasetProviderProps> = ({ children }) =>
export const useDataset = () => useContext(DatasetContext)

export function CreateDatasetContainer() {
// const [formData, setFormData] = useState({
// createDatasetTitle: ''
// })
const { t } = useTranslation('createDataset')

// const [submitComplete, setSubmitComplete] = useState(false)

// const [submitting, setSubmitting] = useState(false)

// const handleCreateDatasetFieldChange = (event: ChangeEvent<FormInputElement>): void => {
// const { name, value } = event.target
// setFormData((prevData) => ({
// ...prevData,
// [name]: value
// }))
// }
// async function handleCreateDatasetFormSubmit(event: FormEvent<HTMLFormElement>) {
// event.preventDefault()
// try {
// const addNewDataset = await CreateDataset(formData)

// if (addNewDataset.validateCreateDatasetFormData(formData)) {
// setSubmitting(true)
// // Simulate an asynchronous operation, e.g., API call
// await new Promise((resolve) => setTimeout(resolve, 3000))
// const result = await addNewDataset.submitCreateDatasetFormData()
// console.log(result)
// setSubmitComplete(true)
// onSubmitForm(JSON.stringify(formData))
// } else {
// console.error('Form validation failed')
// }
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// } catch (error: any) {
// console.error('Error submitting form:', error)
// } finally {
// setSubmitting(false)
// }
// }
// const handleCreateDatasetSubmit = async (event: FormEvent<HTMLFormElement>) => {
// event.preventDefault()

// try {
// const addNewDataset = await createDataset(formData)

// if (addNewDataset.validateCreateDatasetFormData(formData)) {
// setSubmitting(true)
// // Simulate an asynchronous operation, e.g., API call
// await new Promise((resolve) => setTimeout(resolve, 3000))
// const result = await addNewDataset.submitCreateDatasetFormData()
// console.log(result)
// setSubmitComplete(true)
// } else {
// console.error('Form validation failed')
// }
// } catch (error: any) {
// console.error('Error submitting form:', error)
// } finally {
// setSubmitting(false)
// }
// onSubmitForm(JSON.stringify(formData))
// }

return (
<>
<article>
Expand All @@ -112,14 +44,7 @@ export function CreateDatasetContainer() {
</header>
<SeparationLine />
<div className={styles.container}>
<CreateDatasetFormPresenter
// submitComplete={submitComplete}
// formData={formData}
// handleCreateDatasetFieldChange={handleCreateDatasetFieldChange}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
// handleCreateDatasetSubmit={handleCreateDatasetFormSubmit}
// submitting={submitting}
/>
<CreateDatasetFormPresenter />
</div>
</article>
</>
Expand All @@ -129,7 +54,6 @@ export function CreateDatasetContainer() {
export const DatasetCreateMaster: React.FC = () => {
return (
<DatasetProvider>
<h1>Dataset Submission Form</h1>
<CreateDatasetContainer />
</DatasetProvider>
)
Expand Down

0 comments on commit 4da6060

Please sign in to comment.