diff options
author | 2022-06-27 18:21:31 +0200 | |
---|---|---|
committer | 2022-06-27 17:21:31 +0100 | |
commit | 0bf13689d53bd493fb4d0a4213c1801013b5aa8a (patch) | |
tree | 2b5ae44e4f1aa73b49c011954ff1cb47e3959bad /src/containers/settings/EditUserScreen.js | |
parent | chore: recommend specific vscode extensions to setup development [skip ci] (#... (diff) | |
download | ferdium-app-0bf13689d53bd493fb4d0a4213c1801013b5aa8a.tar.gz ferdium-app-0bf13689d53bd493fb4d0a4213c1801013b5aa8a.tar.zst ferdium-app-0bf13689d53bd493fb4d0a4213c1801013b5aa8a.zip |
chore: transform containers/settings from js to tsx (#384)
Diffstat (limited to 'src/containers/settings/EditUserScreen.js')
-rw-r--r-- | src/containers/settings/EditUserScreen.js | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/src/containers/settings/EditUserScreen.js b/src/containers/settings/EditUserScreen.js deleted file mode 100644 index baa2d7b71..000000000 --- a/src/containers/settings/EditUserScreen.js +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | import { defineMessages, injectIntl } from 'react-intl'; | ||
5 | |||
6 | import UserStore from '../../stores/UserStore'; | ||
7 | import Form from '../../lib/Form'; | ||
8 | import EditUserForm from '../../components/settings/user/EditUserForm'; | ||
9 | import ErrorBoundary from '../../components/util/ErrorBoundary'; | ||
10 | |||
11 | import { required, email, minLength } from '../../helpers/validation-helpers'; | ||
12 | |||
13 | const messages = defineMessages({ | ||
14 | firstname: { | ||
15 | id: 'settings.user.form.firstname', | ||
16 | defaultMessage: 'First Name', | ||
17 | }, | ||
18 | lastname: { | ||
19 | id: 'settings.user.form.lastname', | ||
20 | defaultMessage: 'Last Name', | ||
21 | }, | ||
22 | email: { | ||
23 | id: 'settings.user.form.email', | ||
24 | defaultMessage: 'Email', | ||
25 | }, | ||
26 | accountTypeLabel: { | ||
27 | id: 'settings.user.form.accountType.label', | ||
28 | defaultMessage: 'Account type', | ||
29 | }, | ||
30 | accountTypeIndividual: { | ||
31 | id: 'settings.user.form.accountType.individual', | ||
32 | defaultMessage: 'Individual', | ||
33 | }, | ||
34 | accountTypeNonProfit: { | ||
35 | id: 'settings.user.form.accountType.non-profit', | ||
36 | defaultMessage: 'Non-Profit', | ||
37 | }, | ||
38 | accountTypeCompany: { | ||
39 | id: 'settings.user.form.accountType.company', | ||
40 | defaultMessage: 'Company', | ||
41 | }, | ||
42 | currentPassword: { | ||
43 | id: 'settings.user.form.currentPassword', | ||
44 | defaultMessage: 'Current password', | ||
45 | }, | ||
46 | newPassword: { | ||
47 | id: 'settings.user.form.newPassword', | ||
48 | defaultMessage: 'New password', | ||
49 | }, | ||
50 | }); | ||
51 | |||
52 | class EditUserScreen extends Component { | ||
53 | componentWillUnmount() { | ||
54 | this.props.actions.user.resetStatus(); | ||
55 | } | ||
56 | |||
57 | onSubmit(userData) { | ||
58 | const { update } = this.props.actions.user; | ||
59 | |||
60 | update({ userData }); | ||
61 | |||
62 | document.querySelector('#form').scrollIntoView({ behavior: 'smooth' }); | ||
63 | } | ||
64 | |||
65 | prepareForm(user) { | ||
66 | const { intl } = this.props; | ||
67 | |||
68 | const config = { | ||
69 | fields: { | ||
70 | firstname: { | ||
71 | label: intl.formatMessage(messages.firstname), | ||
72 | placeholder: intl.formatMessage(messages.firstname), | ||
73 | value: user.firstname, | ||
74 | validators: [required], | ||
75 | }, | ||
76 | lastname: { | ||
77 | label: intl.formatMessage(messages.lastname), | ||
78 | placeholder: intl.formatMessage(messages.lastname), | ||
79 | value: user.lastname, | ||
80 | validators: [required], | ||
81 | }, | ||
82 | email: { | ||
83 | label: intl.formatMessage(messages.email), | ||
84 | placeholder: intl.formatMessage(messages.email), | ||
85 | value: user.email, | ||
86 | validators: [required, email], | ||
87 | }, | ||
88 | accountType: { | ||
89 | value: user.accountType, | ||
90 | validators: [required], | ||
91 | label: intl.formatMessage(messages.accountTypeLabel), | ||
92 | options: [ | ||
93 | { | ||
94 | value: 'individual', | ||
95 | label: intl.formatMessage(messages.accountTypeIndividual), | ||
96 | }, | ||
97 | { | ||
98 | value: 'non-profit', | ||
99 | label: intl.formatMessage(messages.accountTypeNonProfit), | ||
100 | }, | ||
101 | { | ||
102 | value: 'company', | ||
103 | label: intl.formatMessage(messages.accountTypeCompany), | ||
104 | }, | ||
105 | ], | ||
106 | }, | ||
107 | organization: { | ||
108 | label: intl.formatMessage(messages.accountTypeCompany), | ||
109 | placeholder: intl.formatMessage(messages.accountTypeCompany), | ||
110 | value: user.organization, | ||
111 | }, | ||
112 | oldPassword: { | ||
113 | label: intl.formatMessage(messages.currentPassword), | ||
114 | type: 'password', | ||
115 | validators: [minLength(6)], | ||
116 | }, | ||
117 | newPassword: { | ||
118 | label: intl.formatMessage(messages.newPassword), | ||
119 | type: 'password', | ||
120 | validators: [minLength(6)], | ||
121 | }, | ||
122 | }, | ||
123 | }; | ||
124 | |||
125 | return new Form(config); | ||
126 | } | ||
127 | |||
128 | render() { | ||
129 | const { user } = this.props.stores; | ||
130 | |||
131 | if (user.getUserInfoRequest.isExecuting) { | ||
132 | return <div>Loading...</div>; | ||
133 | } | ||
134 | |||
135 | const form = this.prepareForm(user.data); | ||
136 | |||
137 | return ( | ||
138 | <ErrorBoundary> | ||
139 | <EditUserForm | ||
140 | // user={user.data} | ||
141 | status={user.actionStatus} | ||
142 | form={form} | ||
143 | isSaving={user.updateUserInfoRequest.isExecuting} | ||
144 | onSubmit={d => this.onSubmit(d)} | ||
145 | /> | ||
146 | </ErrorBoundary> | ||
147 | ); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | EditUserScreen.propTypes = { | ||
152 | stores: PropTypes.shape({ | ||
153 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
154 | }).isRequired, | ||
155 | actions: PropTypes.shape({ | ||
156 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
157 | }).isRequired, | ||
158 | }; | ||
159 | |||
160 | export default injectIntl( | ||
161 | inject('stores', 'actions')(observer(EditUserScreen)), | ||
162 | ); | ||