From ed56f9b5ef263ecb34067c79466bec4a8404361d Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Mon, 7 Feb 2022 17:01:58 -0300 Subject: [PATCH 1/5] Create new prop customErrorMessage in ProfileEdit --- react/components/AppRouter.tsx | 3 ++- react/components/Profile/ProfileFormBox.tsx | 8 +++++--- react/components/pages/ProfileEdit.tsx | 6 ++++-- react/index.tsx | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/react/components/AppRouter.tsx b/react/components/AppRouter.tsx index 1aa19c9a..13e7a2d6 100644 --- a/react/components/AppRouter.tsx +++ b/react/components/AppRouter.tsx @@ -18,6 +18,7 @@ import Menu from './Menu' interface Props { blockDocument?: boolean + customErrorMessage?: string } class AppRouter extends Component { @@ -59,7 +60,7 @@ class AppRouter extends Component { { path: '/profile/edit', component: () => ( - + ), }, ] diff --git a/react/components/Profile/ProfileFormBox.tsx b/react/components/Profile/ProfileFormBox.tsx index d0920200..7ad01081 100644 --- a/react/components/Profile/ProfileFormBox.tsx +++ b/react/components/Profile/ProfileFormBox.tsx @@ -48,7 +48,7 @@ class ProfileFormBox extends Component { } private handleSubmit = async ({ valid, profile }: any) => { - const { onDataSave, onError } = this.props + const { onDataSave, onError, customErrorMessage } = this.props await this.setStateAsync({ isLoading: true, valid, profile }) try { @@ -70,7 +70,8 @@ class ProfileFormBox extends Component { this.setState({ isLoading: false }) onDataSave() } catch (error) { - onError(error) + console.log(error) + onError(customErrorMessage) } } @@ -132,9 +133,10 @@ interface InnerProps { } interface OutterProps { onDataSave: () => void - onError: (error: any) => void + onError: (customErrorMessage?: string) => void profile: Profile blockDocument?: boolean + customErrorMessage?: string } const enhance = compose( diff --git a/react/components/pages/ProfileEdit.tsx b/react/components/pages/ProfileEdit.tsx index 7a95cf23..60763aa9 100644 --- a/react/components/pages/ProfileEdit.tsx +++ b/react/components/pages/ProfileEdit.tsx @@ -22,7 +22,7 @@ class ProfileEdit extends Component { } public render() { - const { profile, handleError, blockDocument } = this.props + const { profile, handleError, blockDocument, customErrorMessage } = this.props return ( { onDataSave={this.handleGoBack} onError={handleError} blockDocument={blockDocument} + customErrorMessage={customErrorMessage} /> ) } @@ -40,9 +41,10 @@ interface Props extends InjectedContentWrapperProps { profile: Profile history: any blockDocument?: boolean + customErrorMessage?: string } -const enhance = compose( +const enhance = compose( graphql(GET_PROFILE), branch( ({ data }) => data.profile == null, diff --git a/react/index.tsx b/react/index.tsx index 14cb6d5f..664429e0 100644 --- a/react/index.tsx +++ b/react/index.tsx @@ -7,6 +7,7 @@ import { logGeneralErrors } from './utils/splunk' interface Props { blockDocument?: boolean + customErrorMessage?: string } class MyAccount extends Component { @@ -20,7 +21,7 @@ class MyAccount extends Component { return (
- +
) From dd54f22a16b3584a187ad8037e1d12671c59c6b6 Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 8 Feb 2022 10:59:49 -0300 Subject: [PATCH 2/5] Create new prop removeMaskDocument --- react/components/AppRouter.tsx | 3 ++- react/components/Profile/ProfileFormBox.tsx | 4 +++- react/components/pages/ProfileEdit.tsx | 6 ++++-- react/index.tsx | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/react/components/AppRouter.tsx b/react/components/AppRouter.tsx index 13e7a2d6..d5d9738e 100644 --- a/react/components/AppRouter.tsx +++ b/react/components/AppRouter.tsx @@ -19,6 +19,7 @@ import Menu from './Menu' interface Props { blockDocument?: boolean customErrorMessage?: string + removeMaskDocument: boolean } class AppRouter extends Component { @@ -60,7 +61,7 @@ class AppRouter extends Component { { path: '/profile/edit', component: () => ( - + ), }, ] diff --git a/react/components/Profile/ProfileFormBox.tsx b/react/components/Profile/ProfileFormBox.tsx index 7ad01081..4c87d3a5 100644 --- a/react/components/Profile/ProfileFormBox.tsx +++ b/react/components/Profile/ProfileFormBox.tsx @@ -70,7 +70,8 @@ class ProfileFormBox extends Component { this.setState({ isLoading: false }) onDataSave() } catch (error) { - console.log(error) + console.error(error) + this.setState({ isLoading: false }) onError(customErrorMessage) } } @@ -137,6 +138,7 @@ interface OutterProps { profile: Profile blockDocument?: boolean customErrorMessage?: string + removeMaskDocument: boolean } const enhance = compose( diff --git a/react/components/pages/ProfileEdit.tsx b/react/components/pages/ProfileEdit.tsx index 60763aa9..b98b186e 100644 --- a/react/components/pages/ProfileEdit.tsx +++ b/react/components/pages/ProfileEdit.tsx @@ -22,7 +22,7 @@ class ProfileEdit extends Component { } public render() { - const { profile, handleError, blockDocument, customErrorMessage } = this.props + const { profile, handleError, blockDocument, customErrorMessage, removeMaskDocument } = this.props return ( { onError={handleError} blockDocument={blockDocument} customErrorMessage={customErrorMessage} + removeMaskDocument={removeMaskDocument} /> ) } @@ -42,9 +43,10 @@ interface Props extends InjectedContentWrapperProps { history: any blockDocument?: boolean customErrorMessage?: string + removeMaskDocument: boolean } -const enhance = compose( +const enhance = compose( graphql(GET_PROFILE), branch( ({ data }) => data.profile == null, diff --git a/react/index.tsx b/react/index.tsx index 664429e0..1117406b 100644 --- a/react/index.tsx +++ b/react/index.tsx @@ -8,6 +8,7 @@ import { logGeneralErrors } from './utils/splunk' interface Props { blockDocument?: boolean customErrorMessage?: string + removeMaskDocument: boolean } class MyAccount extends Component { @@ -21,7 +22,7 @@ class MyAccount extends Component { return (
- +
) From c6610532aa52821eb9b7e35cb567a3e5010c7933 Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 8 Feb 2022 11:44:43 -0300 Subject: [PATCH 3/5] Create removeMaskDocument validate --- react/components/Profile/ProfileFormBox.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/react/components/Profile/ProfileFormBox.tsx b/react/components/Profile/ProfileFormBox.tsx index 4c87d3a5..cd5f1b80 100644 --- a/react/components/Profile/ProfileFormBox.tsx +++ b/react/components/Profile/ProfileFormBox.tsx @@ -81,7 +81,10 @@ class ProfileFormBox extends Component { } private submit = (profile: ProfileInput) => { - const { updateProfile } = this.props + const { updateProfile, removeMaskDocument } = this.props + + if (removeMaskDocument && profile?.document) + profile.document = profile.document.replace(/\D/g, '') return updateProfile({ variables: { profile } }) } From b20014793417ba3fedcf2f668ae30851913370a2 Mon Sep 17 00:00:00 2001 From: Tiago Granelli Date: Fri, 11 Feb 2022 09:31:15 -0300 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1abfdb52..0a6f1aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +# Added + +- Props `customErrorMessage` and `removeMaskDocument` + ## [1.24.0] - 2021-11-09 ### Removed From cf2f08f20fafc29bacc5dffef3d5eea7fef5ebee Mon Sep 17 00:00:00 2001 From: Tiago Granelli Date: Fri, 11 Feb 2022 09:37:29 -0300 Subject: [PATCH 5/5] Update README.md --- docs/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/README.md b/docs/README.md index 3f585e7c..dae94063 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,6 +38,36 @@ Now, create the file `store/interfaces.json` and define some interfaces: } } ``` +If you want to change the default alert message in MyAccount, use prop `customErrorMessage` + +```json +"my-account": { + "props": { "customErrorMessage": "My custom error message" }, + "blocks": [ + ] + } +``` + +| Prop name | Type | Description | Default value | +| --------------- | --------- | ----------------------------------------------------------- | ------------- | +| `customErrorMessage` | `string` | Change the default generic error message in MyAccount | `undefined` | + +--- +If you want to remove the mask from the document when saving the document in MyAccount, use prop `removeMaskDocument` + +```json +"my-account": { + "props": { "removeMaskDocument": true }, + "blocks": [ + ] + } +``` + +| Prop name | Type | Description | Default value | +| --------------- | --------- | ----------------------------------------------------------- | ------------- | +| `removeMaskDocument` | `boolean` | Remove mask in document field in MyAccount | `undefined` | + +--- If you want to block the editing of the document in the my account form, use the props `blockDocument`