123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import FormatSelector from './FormatSelector'
- import { TextInput } from '../../form'
- import BlockInstanceInputs from './BlockInstanceInputs'
- import { emptyBlockInstance } from '../utils'
- import ExerciseInstanceInputs from './ExerciseInstanceInputs'
- import { TBlock } from '../types'
- interface IBlockInputs {
- onChange: GenericEventHandler
- value: TBlock
- name: string
- }
- const BlockInputs = ({ onChange, value, name }: IBlockInputs) => {
- return (
- <>
- <TextInput
- name={`${name}.title`}
- label='Title'
- value={value.title}
- onChange={onChange}
- />
- <TextInput
- name={`${name}.description`}
- label='Description'
- value={value.description ?? ''}
- onChange={onChange}
- />
- <TextInput
- name={`${name}.duration`}
- label='Duration'
- value={value.duration ?? ''}
- type='number'
- onChange={onChange}
- />
- <FormatSelector
- name={`${name}.format`}
- value={value.format}
- onChange={onChange}
- />
- <TextInput
- name={`${name}.rest`}
- label='Rest'
- value={value.rest ?? ''}
- type='number'
- onChange={onChange}
- />
- <label>Blocks</label>
- {value.blocks && value.blocks.length > 0 && (
- <BlockInstanceInputs
- name={`${name}.blocks`}
- value={value.blocks}
- onChange={onChange}
- />
- )}
- <button
- onClick={event => {
- event.preventDefault()
- const newBlock = emptyBlockInstance({
- order: value.blocks ? value.blocks.length : 0
- })
- onChange({
- target: {
- type: 'custom',
- name: `${name}.blocks`,
- value: value.blocks ? [...value.blocks, newBlock] : [newBlock]
- }
- })
- }}
- type='button'
- >
- Add block
- </button>
- <label>Exercises</label>
- {value.exercises && value.exercises.length > 0 && (
- <ExerciseInstanceInputs
- name={`${name}.blocks`}
- value={value.exercises}
- onChange={onChange}
- />
- )}
- <button
- onClick={event => {
- event.preventDefault()
- const newExercise = empty({
- order: value.blocks ? value.blocks.length : 0
- })
- onChange({
- target: {
- type: 'custom',
- name: `${name}.blocks`,
- value: value.blocks ? [...value.blocks, newBlock] : [newBlock]
- }
- })
- }}
- type='button'
- >
- Add exercise
- </button>
- </>
- )
- }
- export default BlockInputs
|