diff --git a/actions/questionnaireActions.js b/actions/questionnaireActions.js index dc2c34e..20f2064 100644 --- a/actions/questionnaireActions.js +++ b/actions/questionnaireActions.js @@ -155,6 +155,22 @@ export const getQuestionnaire = ({ dispatch, id }) => code: response.data.head_person !== null && response.data.head_person.identity_document !== null ? response.data.head_person.identity_document.citizenship_code : 643, }; + if(questionnaire.head_person.assignment_date !== null) + { + if(moment(questionnaire.head_person.assignment_date).isValid()) + { + questionnaire.head_person.assignment_date = moment.utc(moment.utc(questionnaire.head_person.assignment_date).format('YYYY-MM-DD')); + } + } + + if(questionnaire.head_person.credentials_dateend !== null) + { + if(moment(questionnaire.head_person.credentials_dateend).isValid()) + { + questionnaire.head_person.credentials_dateend = moment.utc(moment.utc(questionnaire.head_person.credentials_dateend).format('YYYY-MM-DD')); + } + } + const signatory_person_identity_document = questionnaire.signatory_person.identity_document; questionnaire.signatory_person = { ...questionnaire.signatory_person, ...response.data.signatory_person }; if(questionnaire.signatory_person.identity_document === null) @@ -167,6 +183,22 @@ export const getQuestionnaire = ({ dispatch, id }) => code: response.data.signatory_person !== null && response.data.signatory_person.identity_document !== null ? response.data.signatory_person.identity_document.citizenship_code : 643, }; + if(questionnaire.signatory_person.assignment_date !== null) + { + if(moment(questionnaire.signatory_person.assignment_date).isValid()) + { + questionnaire.signatory_person.assignment_date = moment.utc(moment.utc(questionnaire.signatory_person.assignment_date).format('YYYY-MM-DD')); + } + } + + if(questionnaire.signatory_person.credentials_dateend !== null) + { + if(moment(questionnaire.signatory_person.credentials_dateend).isValid()) + { + questionnaire.signatory_person.credentials_dateend = moment.utc(moment.utc(questionnaire.signatory_person.credentials_dateend).format('YYYY-MM-DD')); + } + } + for(let i in response.data.founder_persons) { questionnaire.founder_persons[i] = response.data.founder_persons[i]; diff --git a/components/CalendarDatePicker/index.js b/components/CalendarDatePicker/index.js index 0762ac0..8b5a63e 100644 --- a/components/CalendarDatePicker/index.js +++ b/components/CalendarDatePicker/index.js @@ -25,14 +25,25 @@ export default class CalendarDatePicker extends React.Component }; } - _handle_onChange = (date) => + _handle_onChange = (date, raw) => { - ////console.log("CalendarDatePicker", "_handle_onChange", date); +// console.log("CalendarDatePicker", "_handle_onChange", { date, raw }); const { readonly } = this.state; if(this.props.onChange !== undefined) { - this.props.onChange(date.getTime !== undefined ? date.toJSON() : ""); + if(!readonly) + { + if(moment(date).isValid()) + { + this.props.onChange(date, raw); + } + else + { + this.props.onChange(null, null); + } + } +// this.props.onChange(date.getTime !== undefined ? date.toJSON() : "", date.getTime !== undefined ? raw : null); /* if(!readonly) { @@ -92,6 +103,37 @@ export default class CalendarDatePicker extends React.Component this.setState({ readonly: true }); } + _parse = (str) => + { + const { min, max } = this.props; + const date = moment(str, 'DD.MM.YYYY'); + + if(date.isValid()) + { + if(min !== undefined) + { + const min_to_compare = moment(moment(min).format("YYYY-MM-DD 00:00:00")); + if(date < min_to_compare) + { + return null; + } + } + + if(max !== undefined) + { + const max_to_compare = moment(moment(max).format("YYYY-MM-DD 00:00:00")); + if(date > max_to_compare) + { + return null; + } + } + + return date.toDate(); + } + + return null; + } + render() { const { id, placeholder, value, min, max, disabled, plain, style, required, className } = this.props; @@ -111,14 +153,14 @@ export default class CalendarDatePicker extends React.Component onFocus={ this._handle_onFocus } onBlur={ this._handle_onBlur } //onKeyDown={ this._handle_onKeyDown } - parse={ str => { return moment(str, 'DD.MM.YYYY').toDate() } } + parse={ this._parse } id={ id } placeholder={ placeholder } - value={ value !== "" && value !== null ? new Date(value) : null } - min={ min } - max={ max } + value={ value !== "" && value !== undefined && value !== null ? new Date(Date.parse(moment(value).utc().format('YYYY-MM-DD 00:00:00'))) : null } + min={ min !== undefined ? new Date(Date.parse(moment(min).format('YYYY-MM-DD 00:00:00'))) : undefined } + max={ max !== undefined ? new Date(Date.parse(moment(max).format('YYYY-MM-DD 00:00:00'))) : undefined } onChange={ this._handle_onChange } - inputProps={{ required }} + inputProps={{ required }} />
{ event.stopPropagation(); event.preventDefault(); } }/> @@ -136,14 +178,14 @@ export default class CalendarDatePicker extends React.Component onFocus={ this._handle_onFocus } onBlur={ this._handle_onBlur } //onKeyDown={ this._handle_onKeyDown } - parse={ str => { return moment(str, 'DD.MM.YYYY').toDate() } } + parse={ this._parse } id={ id } placeholder={ placeholder } - value={ input_value !== undefined ? input_value : value !== "" && value !== null ? new Date(value) : null } - min={ min } - max={ max } + value={ input_value !== undefined ? input_value : value !== "" && value !== undefined && value !== null ? new Date(Date.parse(moment(value, "YYYY-MM-DD").format('YYYY-MM-DD 00:00:00'))) : null } + min={ min !== undefined ? new Date(Date.parse(moment(min).format('YYYY-MM-DD 00:00:00'))) : undefined } + max={ max !== undefined ? new Date(Date.parse(moment(max).format('YYYY-MM-DD 00:00:00'))) : undefined } onChange={ this._handle_onChange } - inputProps={{ required }} + inputProps={{ required }} />
) diff --git a/components/questionnaire/forms/Form_3_Signer/index.js b/components/questionnaire/forms/Form_3_Signer/index.js index eec1dbb..df2760a 100644 --- a/components/questionnaire/forms/Form_3_Signer/index.js +++ b/components/questionnaire/forms/Form_3_Signer/index.js @@ -777,7 +777,7 @@ class Form_3_Signer extends QuestionnaireForm max={ moment().toDate() } id={ "head_person.identity_document.issuedate" } value={ this._checkStrValue(head_person.identity_document.issuedate) !== "" ? this._checkStrValue(head_person.identity_document.issuedate) : null } - onChange={ (date) => { this._removeError("head_person.identity_document.issuedate"); this._handle_onTextFieldChange("head_person.identity_document.issuedate", date); } } + onChange={ (date, raw) => { this._removeError("head_person.identity_document.issuedate"); this._handle_onDateFieldChange("head_person.identity_document.issuedate", date, raw); } } required={ true } disabled={ checking } /> @@ -920,10 +920,10 @@ class Form_3_Signer extends QuestionnaireForm max={ moment().toDate() } id={ "head_person.assignment_date" } value={ this._checkStrValue(head_person.assignment_date) !== "" ? this._checkStrValue(head_person.assignment_date) : null } - onChange={ (date) => { this._removeError([ "head_person.assignment_date", "head_person.assignment_date_invalid" ]); this._handle_onTextFieldChange("head_person.assignment_date", date) } } + onChange={ (date, raw) => { this._removeError([ "head_person.assignment_date", "head_person.assignment_date_invalid" ]); this._handle_onDateFieldChange("head_person.assignment_date", date, raw) } } required={ true } disabled={ checking } - style={{maxWidth: "320px"}} + style={{ maxWidth: "320px" }} />
{ this._removeError([ "head_person.credentials_dateend", "head_person.credentials_dateend_invalid" ]); this._handle_onTextFieldChange("head_person.credentials_dateend", date) } } + onChange={ (date, raw) => { this._removeError([ "head_person.credentials_dateend", "head_person.credentials_dateend_invalid" ]); this._handle_onDateFieldChange("head_person.credentials_dateend", date, raw) } } required={ true } disabled={ checking } style={{maxWidth: "320px"}} @@ -1081,7 +1081,7 @@ class Form_3_Signer extends QuestionnaireForm max={ moment().toDate() } id={ "main.individual_executive_docdate" } value={ this._checkStrValue(main.individual_executive_docdate) !== "" ? this._checkStrValue(main.individual_executive_docdate) : null } - onChange={ (date) => { this._removeError("main.individual_executive_docdate"); this._handle_onTextFieldChange("main.individual_executive_docdate", date); } } + onChange={ (date, raw) => { this._removeError("main.individual_executive_docdate"); this._handle_onDateFieldChange("main.individual_executive_docdate", date, raw); } } required={ true } disabled={ checking } /> @@ -1283,7 +1283,7 @@ class Form_3_Signer extends QuestionnaireForm max={ moment().toDate() } id={ "signatory_person.identity_document.issuedate" } value={ this._checkStrValue(signatory_person.identity_document.issuedate) !== "" ? this._checkStrValue(signatory_person.identity_document.issuedate) : null } - onChange={ (date) => { this._removeError("signatory_person.identity_document.issuedate"); this._handle_onTextFieldChange("signatory_person.identity_document.issuedate", date); } } + onChange={ (date, raw) => { this._removeError("signatory_person.identity_document.issuedate"); this._handle_onDateFieldChange("signatory_person.identity_document.issuedate", date, raw); } } required={ true } disabled={ checking } /> @@ -1491,7 +1491,7 @@ class Form_3_Signer extends QuestionnaireForm max={ moment().toDate() } id={ "signatory_person.docdate" } value={ this._checkStrValue(signatory_person.docdate) !== "" ? this._checkStrValue(signatory_person.docdate) : null } - onChange={ (date) => { this._removeError("signatory_person.docdate"); this._handle_onTextFieldChange("signatory_person.docdate", date); } } + onChange={ (date, raw) => { this._removeError("signatory_person.docdate"); this._handle_onDateFieldChange("signatory_person.docdate", date, raw); } } required={ true } disabled={ checking } /> diff --git a/components/questionnaire/forms/Form_4_Shareholders/index.js b/components/questionnaire/forms/Form_4_Shareholders/index.js index ccd20be..ba48eb0 100644 --- a/components/questionnaire/forms/Form_4_Shareholders/index.js +++ b/components/questionnaire/forms/Form_4_Shareholders/index.js @@ -250,7 +250,7 @@ class ShareholderForm extends React.Component max={ moment().toDate() } id={ `founder_persons[${ index }].identity_document.issuedate` } value={ this._checkStrValue(shareholder.identity_document.issuedate) !== "" ? this._checkStrValue(shareholder.identity_document.issuedate) : null } - onChange={ (date) => { this._removeError("identity_document.issuedate"); this._handle_onTextFieldChange(`founder_persons[${ index }].identity_document.issuedate`, date) } } + onChange={ (date, raw) => { this._removeError("identity_document.issuedate"); this._handle_onDateFieldChange(`founder_persons[${ index }].identity_document.issuedate`, date, raw) } } required={ true } disabled={ checking } /> @@ -303,7 +303,7 @@ class ShareholderForm extends React.Component max={ moment().subtract(18, 'years').toDate() } id={ `founder_persons[${ index }].birthdate` } value={ this._checkStrValue(shareholder.birthdate) !== "" ? this._checkStrValue(shareholder.birthdate) : moment().subtract(18, 'years').toDate() } - onChange={ (date) => { this._removeError("birthdate"); this._handle_onTextFieldChange(`founder_persons[${ index }].birthdate`, date) } } + onChange={ (date, raw) => { this._removeError("birthdate"); this._handle_onDateFieldChange(`founder_persons[${ index }].birthdate`, date, raw) } } required={ true } disabled={ checking } /> diff --git a/components/questionnaire/forms/QuestionnaireForm.js b/components/questionnaire/forms/QuestionnaireForm.js index 719432c..9b7fc18 100644 --- a/components/questionnaire/forms/QuestionnaireForm.js +++ b/components/questionnaire/forms/QuestionnaireForm.js @@ -7,6 +7,7 @@ import numeral from "numeral"; import pluralize from 'pluralize-ru'; import { SpinnerCircular } from 'spinners-react'; import debounce from 'debounce-promise'; +import moment from 'moment'; import { set as _set, get as _get } from 'lodash'; import { updateQuestionnaire, getAddress, getSuggests, resetQuestionnaire, questionnaireSetSign } from "../../../actions"; @@ -102,14 +103,35 @@ export default class QuestionnaireForm extends React.Component _handle_onTextFieldChange = (name, value) => { - ////console.log("QuestionnaireForm", "_handle_onTextFieldChange", { name, value }); - +// console.log("QuestionnaireForm", "_handle_onTextFieldChange", { name, value }); const update = { ...this.state }; _set(update, name, value); this._updateQuestionnaire(update); } + _handle_onDateFieldChange = (name, value, raw) => + { +// console.log("QuestionnaireForm", "_handle_onDateFieldChange", { name, value, raw }); + + try + { +// console.log("DIFF 1", moment.utc(raw, 'DD.MM.YYYY').format('YYYY-MM-DD')); +// console.log("DIFF 2", moment(raw, 'DD.MM.YYYY').utc().format('YYYY-MM-DD')); + + const date = moment.utc(raw, 'DD.MM.YYYY').format('YYYY-MM-DD'); +// console.log("QuestionnaireForm", "_handle_onDateFieldChange", { date }); + + const update = { ...this.state }; + _set(update, name, date); + this._updateQuestionnaire(update); + } + catch(e) + { + console.error(e); + } + } + _handle_onCheckboxFieldChange = (name, value) => { //console.log("QuestionnaireForm", "_handle_onCheckboxFieldChange", { name, value }); diff --git a/pages/_app.js b/pages/_app.js index 6656cd0..3262afc 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -56,19 +56,10 @@ const WrappedApp = (props) => window.widgetUserLogin = ${ props.acc !== null ? `"${ props.acc }"` : "undefined" }; window.widgetUserEmail = ${ props.email !== null ? `"${ props.email }"` : "undefined" }; window.widgetUserPayload = ${ props.acc !== null ? `{ "acc_number": "${ props.acc }" }` : "undefined" }; + window.widgetOperatorName = true; window.widgetStyleParams = { "headerBackgroundColor": "#1c01a9", "messageToWidgetBackgroundColor": "#3d21f8" }; - console.log("widget", { - "widgetHost": window.widgetHost, - "widgetServiceId": window.widgetServiceId, - "widgetChannelId": window.widgetChannelId, - "widgetUserLogin": window.widgetUserLogin, - "widgetUserEmail": window.widgetUserEmail, - "widgetUserPayload": window.widgetUserPayload, - "widgetStyleParams": window.widgetStyleParams, - }); - const script = document.createElement('script'); script.id = "autofaqWidget"; script.type = "text/javascript";