Skip to content

Instantly share code, notes, and snippets.

@dftpnd
Created August 1, 2017 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dftpnd/e4903ecab2aa3d6ce5d66110c0873928 to your computer and use it in GitHub Desktop.
Save dftpnd/e4903ecab2aa3d6ce5d66110c0873928 to your computer and use it in GitHub Desktop.
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { Cell } from 'sbtsbol-app'
import { errorAdapter, Field, Input } from '@sbtsbol/lib.ui'
import Header from './header'
import { CheckboxUI, DateBox, FormGroupUI, LabelUI, SectionUI, TextBoxUI } from './ui'
const DepartmentCodeInput = errorAdapter(Input.Masked)
const renderDepartmentField = (field) => {
return (
<div>
<DepartmentCodeInput
{...field}
mask={[/\d/, /\d/, /\d/, ' ', '–', ' ', /\d/, /\d/, /\d/]}
maxLength={9}
/>
</div>
)
}
const PassportForm = (props) => {
// Получение филдов
const [
secondName,
firstName,
middleName,
isHaveMiddleName,
number,
issueDate,
departmentCode,
issuePlace
] = props.fields
// Есть ли отчество
const isSetMiddleName = props.form.shortRequestFlow.values[isHaveMiddleName.id]
const departmentInputChange = (event, value) => {
issuePlace.value = 'some value'
}
return (
<SectionUI>
<Header {...props} />
<FormGroupUI>
<LabelUI>{secondName.title}</LabelUI>
<TextBoxUI {...secondName} />
</FormGroupUI>
<FormGroupUI>
<LabelUI>{firstName.title}</LabelUI>
<TextBoxUI {...firstName} />
</FormGroupUI>
<FormGroupUI>
<LabelUI>{middleName.title}</LabelUI>
<TextBoxUI {...middleName} disabled={isSetMiddleName} />
<CheckboxUI md={6} {...isHaveMiddleName} />
</FormGroupUI>
<FormGroupUI>
<LabelUI>{number.title}</LabelUI>
<TextBoxUI md={5} {...number} />
</FormGroupUI>
<FormGroupUI>
<LabelUI>{issueDate.title}</LabelUI>
<DateBox md={5} {...issueDate} />
</FormGroupUI>
<FormGroupUI>
<LabelUI>{departmentCode.title}</LabelUI>
<Cell md={5}>
<Field
{...departmentCode}
component={renderDepartmentField}
name={departmentCode.id}
validate={departmentCode.validators}
onChange={departmentInputChange}
/>
</Cell>
</FormGroupUI>
<FormGroupUI>
<LabelUI>{issuePlace.title}</LabelUI>
<TextBoxUI md={5} {...issuePlace} />
</FormGroupUI>
</SectionUI>
)
}
PassportForm.propTypes = {
fields: PropTypes.array,
form: PropTypes.object
}
PassportForm.defaultProps = {
fields: [],
form: {}
}
const mapStateToProps = (state) => state
export default connect(mapStateToProps)(PassportForm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment