Skip to content

Commit

Permalink
fix: temporary validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Sep 8, 2023
1 parent e113137 commit 0708100
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
72 changes: 34 additions & 38 deletions src/features/AddModelDialog/AddModelDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,48 @@ export const AddModelDialog = ({
}>({ field: false, formation: false })
const [metadata, setMetadata] = useState<Partial<MetadataProps>>()

// const [description, setDescription] = useState<string>()
// const [field, setField] = useState<string[]>()
// const [zone, setZone] = useState<string[]>()
// const [formation, setFormation] = useState<string[]>()
// const [analogue, setAnalogue] = useState<string[]>()
// const [fieldError, setFieldError] = useState<boolean>(false)
// const [formationError, setFormationError] = useState<boolean>(false)

function toggleINIFileContent() {
setFileDisplay(!isFileDisplay)
}

const INIFileContent = () => <p>Not implemented yet...</p>

const validateInput = (values: string[] | undefined, target: string) => {
// const value = e.selectedItems
// console.log('Kjører: Value => ' + values + ' target => ' + target)

values === undefined || !typeof Object
? setValidationError({ ...validationError, [target]: true })
: setValidationError({ ...validationError, [target]: false })
// onChange(metadata)
const validateInput = (
// input: { values: string[] | undefined; target: string }[]
input: { [target: string]: string[] | undefined }
) => {
Object.entries(input).map(([target, value]) =>
setValidationError({ ...validationError, [target]: value !== undefined })
)
// input.forEach((input) => {
// console.log('Kjører: ' + input.target)
// if (!input.values)
// setValidationError({ ...validationError, [input.target]: true })
//
// if (input.values === undefined) {
// setValidationError({ ...validationError, [input.target]: true })
// console.log('Undefined Error')
// console.log(validationError)
// } else if (input.values.length === 0) {
// setValidationError({ ...validationError, [input.target]: true })
// console.log('Length 0 Error')
// console.log(validationError)
// } else {
// setValidationError({ ...validationError, [input.target]: false })
// console.log('Ingen Error')
// console.log(validationError)
// }
// })
}

const submit = () => {
/**
*
console.log('Metadata' + metadata)
console.log('Field: ' + metadata?.field)
console.log('Formation: ' + metadata?.formation)
console.log('Type Formation: ' + typeof metadata?.formation)
console.log('Type Field: ' + typeof metadata?.field)
*/

validateInput(metadata?.field, 'field')

validateInput(metadata?.formation, 'formation')
/**
*
console.log('Field error: ' + validationError.field)
console.log('Formation error: ' + validationError.formation)
*/

// confirm()
console.log(metadata)
validateInput([
{ values: metadata?.field, target: 'field' },
{ values: metadata?.formation, target: 'formation' },
])
validateInput()
console.log(validationError)
}

return (
Expand All @@ -93,7 +89,7 @@ console.log('Formation error: ' + validationError.formation)
/>
{isFileDisplay && <INIFileContent />}
<ModelMetadata
onValidate={validateInput}
// onValidate={validateInput}
validationError={validationError}
metadata={metadata}
setMetadata={setMetadata}
Expand Down
6 changes: 3 additions & 3 deletions src/features/ModelMetadata/ModelMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import MetadataProps from '../AddModelDialog/AddModelDialog'
import * as Styled from './ModelMetadata.styled'

export const ModelMetadata = ({
onValidate,
// onValidate,
validationError,
metadata,
setMetadata,
}: {
onValidate: (values: string[], target: string) => void
// onValidate: (values: string[], target: string) => void
validationError: { field: boolean; formation: boolean }
metadata: Partial<MetadataProps> | undefined
setMetadata: (metadata: Partial<MetadataProps>) => void
Expand All @@ -29,8 +29,8 @@ export const ModelMetadata = ({
}

const handleInput = (e: AutocompleteChanges<string>, target: string) => {
onValidate(e.selectedItems, target)
setMetadata({ ...metadata, [target]: e.selectedItems })
// onValidate(e.selectedItems, target)
}

return (
Expand Down

0 comments on commit 0708100

Please sign in to comment.