diff --git a/account/resources/content/account-page/AccountPage.js b/account/resources/content/account-page/AccountPage.js index d376574..b96bd2f 100644 --- a/account/resources/content/account-page/AccountPage.js +++ b/account/resources/content/account-page/AccountPage.js @@ -1,5 +1,6 @@ -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* * Copyright 2018 Red Hat, Inc. and/or its affiliates. * @@ -15,8 +16,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope * See the License for the specific language governing permissions and * limitations under the License. */ -import * as React from "../../../../common/keycloak/web_modules/react.js"; -import { ActionGroup, Button, Form, FormGroup, TextInput, InputGroup, Grid, GridItem, ExpandableSection, ValidatedOptions, PageSection, PageSectionVariants, Text, TextVariants, TextContent } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js"; +import * as React from "../../../keycloak.v2/web_modules/react.js"; +import { ActionGroup, Button, Form, FormGroup, TextInput, InputGroup, Grid, GridItem, ExpandableSection, ValidatedOptions, PageSection, PageSectionVariants, Text, TextVariants, TextContent } from "../../../keycloak.v2/web_modules/@patternfly/react-core.js"; import { AccountServiceContext } from "../../account-service/AccountServiceContext.js"; import { Msg } from "../../widgets/Msg.js"; import { ContentPage } from "../ContentPage.js"; @@ -24,27 +25,19 @@ import { ContentAlert } from "../ContentAlert.js"; import { LocaleSelector } from "../../widgets/LocaleSelectors.js"; import { KeycloakContext } from "../../keycloak-service/KeycloakContext.js"; import { AIACommand } from "../../util/AIACommand.js"; -import { ExternalLinkSquareAltIcon } from "../../../../common/keycloak/web_modules/@patternfly/react-icons.js"; - +import { ExternalLinkSquareAltIcon } from "../../../keycloak.v2/web_modules/@patternfly/react-icons.js"; /** * @author Stan Silvert ssilvert@redhat.com (C) 2018 Red Hat Inc. */ export class AccountPage extends React.Component { constructor(props, context) { super(props); - _defineProperty(this, "context", void 0); - _defineProperty(this, "isRegistrationEmailAsUsername", features.isRegistrationEmailAsUsername); - _defineProperty(this, "isEditUserNameAllowed", features.isEditUserNameAllowed); - _defineProperty(this, "isDeleteAccountAllowed", features.deleteAccountAllowed); - _defineProperty(this, "isUpdateEmailFeatureEnabled", features.updateEmailFeatureEnabled); - _defineProperty(this, "isUpdateEmailActionEnabled", features.updateEmailActionEnabled); - _defineProperty(this, "DEFAULT_STATE", { errors: { username: '', @@ -60,37 +53,34 @@ export class AccountPage extends React.Component { attributes: {} } }); - _defineProperty(this, "state", this.DEFAULT_STATE); - _defineProperty(this, "handleCancel", () => { this.fetchPersonalInfo(); }); - _defineProperty(this, "handleChange", (value, event) => { const target = event.currentTarget; const name = target.name; this.setState({ - errors: { ...this.state.errors, + errors: { + ...this.state.errors, [name]: target.validationMessage }, - formFields: { ...this.state.formFields, + formFields: { + ...this.state.formFields, [name]: value } }); }); - _defineProperty(this, "handleSubmit", event => { event.preventDefault(); const form = event.target; const isValid = form.checkValidity(); - if (isValid) { - const reqData = { ...this.state.formFields + const reqData = { + ...this.state.formFields }; this.context.doPost("/", reqData).then(() => { ContentAlert.success('accountUpdatedMessage'); - if (locale !== this.state.formFields.attributes.locale[0]) { window.location.reload(); } @@ -102,21 +92,19 @@ export class AccountPage extends React.Component { return acc; }, {}); this.setState({ - errors: { ...validationMessages + errors: { + ...validationMessages }, formFields: this.state.formFields }); } }); - _defineProperty(this, "handleDelete", keycloak => { new AIACommand(keycloak, "delete_account").execute(); }); - _defineProperty(this, "handleEmailUpdate", keycloak => { new AIACommand(keycloak, "UPDATE_EMAIL").execute(); }); - _defineProperty(this, "UsernameInput", () => /*#__PURE__*/React.createElement(TextInput, { isRequired: true, type: "text", @@ -127,7 +115,6 @@ export class AccountPage extends React.Component { onChange: this.handleChange, validated: this.state.errors.username !== '' ? ValidatedOptions.error : ValidatedOptions.default })); - _defineProperty(this, "RestrictedUsernameInput", () => /*#__PURE__*/React.createElement(TextInput, { isReadOnly: true, type: "text", @@ -135,16 +122,13 @@ export class AccountPage extends React.Component { name: "username", value: this.state.formFields.username })); - this.context = context; this.fetchPersonalInfo(); } - fetchPersonalInfo() { this.context.doGet("/").then(response => { this.setState(this.DEFAULT_STATE); const formFields = response.data; - if (!formFields.attributes) { formFields.attributes = { locale: [locale] @@ -152,14 +136,13 @@ export class AccountPage extends React.Component { } else if (!formFields.attributes.locale) { formFields.attributes.locale = [locale]; } - - this.setState({ ...{ + this.setState({ + ...{ formFields: formFields } }); }); } - render() { const fields = this.state.formFields; return /*#__PURE__*/React.createElement(ContentPage, { @@ -180,14 +163,13 @@ export class AccountPage extends React.Component { fieldId: "user-name", helperTextInvalid: this.state.errors.username, validated: this.state.errors.username !== "" ? ValidatedOptions.error : ValidatedOptions.default - }, this.isEditUserNameAllowed && /*#__PURE__*/React.createElement(this.UsernameInput, null), !this.isEditUserNameAllowed && /*#__PURE__*/React.createElement(this.RestrictedUsernameInput, null)), !this.isUpdateEmailFeatureEnabled && fields.email != undefined && /*#__PURE__*/React.createElement(FormGroup, { + }, this.isEditUserNameAllowed && /*#__PURE__*/React.createElement(this.UsernameInput, null), !this.isEditUserNameAllowed && /*#__PURE__*/React.createElement(this.RestrictedUsernameInput, null)), !this.isUpdateEmailFeatureEnabled && /*#__PURE__*/React.createElement(FormGroup, { label: Msg.localize('email'), fieldId: "email-address", helperTextInvalid: this.state.errors.email, validated: this.state.errors.email !== "" ? ValidatedOptions.error : ValidatedOptions.default }, /*#__PURE__*/React.createElement(TextInput, { isRequired: true, - isReadOnly: true, type: "email", id: "email-address", name: "email", @@ -212,14 +194,13 @@ export class AccountPage extends React.Component { iconPosition: "right" }, /*#__PURE__*/React.createElement(Msg, { msgKey: "updateEmail" - }))))), fields.firstName != undefined && /*#__PURE__*/React.createElement(FormGroup, { + }))))), /*#__PURE__*/React.createElement(FormGroup, { label: Msg.localize("firstName"), fieldId: "first-name", helperTextInvalid: this.state.errors.firstName, validated: this.state.errors.firstName !== "" ? ValidatedOptions.error : ValidatedOptions.default }, /*#__PURE__*/React.createElement(TextInput, { isRequired: true, - isReadOnly: true, type: "text", id: "first-name", name: "firstName", @@ -227,14 +208,13 @@ export class AccountPage extends React.Component { value: fields.firstName, onChange: this.handleChange, validated: this.state.errors.firstName !== "" ? ValidatedOptions.error : ValidatedOptions.default - })), fields.lastName != undefined && /*#__PURE__*/React.createElement(FormGroup, { + })), /*#__PURE__*/React.createElement(FormGroup, { label: Msg.localize("lastName"), fieldId: "last-name", helperTextInvalid: this.state.errors.lastName, validated: this.state.errors.lastName !== "" ? ValidatedOptions.error : ValidatedOptions.default }, /*#__PURE__*/React.createElement(TextInput, { isRequired: true, - isReadOnly: true, type: "text", id: "last-name", name: "lastName", @@ -251,8 +231,10 @@ export class AccountPage extends React.Component { value: fields.attributes.locale || "", onChange: value => this.setState({ errors: this.state.errors, - formFields: { ...this.state.formFields, - attributes: { ...this.state.formFields.attributes, + formFields: { + ...this.state.formFields, + attributes: { + ...this.state.formFields.attributes, locale: [value] } } @@ -261,13 +243,12 @@ export class AccountPage extends React.Component { type: "submit", id: "save-btn", variant: "primary", - isDisabled: true, + isDisabled: Object.values(this.state.errors).filter(e => e !== "").length !== 0 }, /*#__PURE__*/React.createElement(Msg, { msgKey: "doSave" })), /*#__PURE__*/React.createElement(Button, { id: "cancel-btn", variant: "link", - isDisabled: true, onClick: this.handleCancel }, /*#__PURE__*/React.createElement(Msg, { msgKey: "doCancel" @@ -297,10 +278,7 @@ export class AccountPage extends React.Component { span: 2 })))))); } - } - _defineProperty(AccountPage, "contextType", AccountServiceContext); - ; //# sourceMappingURL=AccountPage.js.map