@raona/components
Version:
React components used at Raona to work with SPFx
61 lines (60 loc) • 4.09 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var react_1 = require("react");
// import { IDropdownOption, keyframes } from 'office-ui-fabric-react';
// import {TypedHash, Bind} from'@raona/sp';
var formik_1 = require("formik");
// import {FieldsGroup, FormField} from '../../../entities';
var FormStep_1 = require("./FormStep");
var Bind_1 = require("@raona/sp/dist/decorators/Bind");
var FormContainer = /** @class */ (function (_super) {
__extends(FormContainer, _super);
function FormContainer() {
return _super !== null && _super.apply(this, arguments) || this;
}
FormContainer.prototype.getInitialFormattedValues = function (initialFormValues, a, b) {
return initialFormValues[b.id] ? b.type === 'SPPeople' ? (a[b.id] = [], initialFormValues[b.id].map(function (user) { a[b.id].push(user.secondaryText); })) :
b.type === 'ChoiceGroup' ? a[b.id] = initialFormValues[b.id].key :
a[b.id] = initialFormValues[b.id]
: a[b.id] = '';
};
FormContainer.prototype.render = function () {
var _this = this;
var _a = this.props, fieldGroups = _a.fieldGroups, context = _a.context, setValues = _a.setValues, deleteFile = _a.deleteFile, showErrors = _a.showErrors, handleValidation = _a.handleValidation, stepErrors = _a.stepErrors, initialFormValues = _a.initialFormValues, formattedValues = _a.formattedValues, formWrapperClassName = _a.formWrapperClassName, formInnerWrapperClassName = _a.formInnerWrapperClassName;
var initialValues = fieldGroups.reduce(function (obj, group) {
obj = group.fields.reduce(function (a, b) { return (initialFormValues && _this.getInitialFormattedValues(initialFormValues, a, b), a); }, obj);
return obj;
}, {});
return (React.createElement("div", { className: formWrapperClassName },
React.createElement(formik_1.Formik, { initialValues: initialValues, validate: handleValidation, onSubmit: function (x) { return x; } }, function (_a) {
var touched = _a.touched, handleBlur = _a.handleBlur, values = _a.values, setFieldValue = _a.setFieldValue;
return (React.createElement(formik_1.Form, null,
React.createElement(FormStep_1.FormStep, { fieldGroups: fieldGroups, context: context, setValues: setValues, setFieldValue: setFieldValue, handleBlur: handleBlur, touched: touched, values: values, formErrors: stepErrors, deleteFile: deleteFile, showErrors: showErrors, formattedValues: formattedValues, formInnerWrapperClassName: formInnerWrapperClassName })));
})));
};
__decorate([
Bind_1.Bind()
], FormContainer.prototype, "getInitialFormattedValues", null);
return FormContainer;
}(react_1.Component));
exports.FormContainer = FormContainer;
;