|
@@ -5,194 +5,240 @@
|
5
|
5
|
<div class="form">
|
6
|
6
|
<div class="row">
|
7
|
7
|
<div class="section-header">
|
8
|
|
- <h2>Update Agent Info</h2>
|
|
8
|
+ <h2>update agent info</h2>
|
9
|
9
|
</div>
|
10
|
10
|
</div>
|
11
|
|
- <div class="row">
|
12
|
|
- <div class="col">
|
13
|
|
- <float-label>
|
|
11
|
+ <div class="row mb-4">
|
|
12
|
+ <div class="col-md-6">
|
|
13
|
+ <float-label fixed label="username">
|
14
|
14
|
<input
|
15
|
15
|
type="text"
|
16
|
|
- name="name"
|
17
|
|
- class="form-control uniInput"
|
18
|
|
- id="name"
|
19
|
|
- placeholder="USERNAME"
|
|
16
|
+ name="username"
|
|
17
|
+ class="form-control uniinput"
|
|
18
|
+ id="username"
|
|
19
|
+ placeholder="name"
|
20
|
20
|
data-rule="minlen:4"
|
21
|
|
- data-msg="Please enter your name"
|
|
21
|
+ data-msg="please enter your name"
|
22
|
22
|
v-model="agent.user.username"
|
|
23
|
+ v-bind:class="{
|
|
24
|
+ 'is-valid': agent.user.username,
|
|
25
|
+ 'is-invalid':
|
|
26
|
+ !requiredfield(agent.user.username) && usernameload,
|
|
27
|
+ }"
|
|
28
|
+ v-on:keyup="usernameLoad = true"
|
|
29
|
+ v-on:blur="usernameLoad = true"
|
23
|
30
|
/>
|
|
31
|
+ <div class="invalid-feedback">Username is Required!</div>
|
24
|
32
|
</float-label>
|
25
|
33
|
</div>
|
26
|
|
- <div class="col">
|
|
34
|
+ <div class="form-group col-md-6">
|
27
|
35
|
<float-label>
|
28
|
36
|
<input
|
29
|
37
|
type="text"
|
30
|
38
|
name="name"
|
31
|
39
|
class="form-control uniInput"
|
32
|
40
|
id="name"
|
33
|
|
- placeholder="NAME"
|
|
41
|
+ placeholder="Name"
|
34
|
42
|
data-rule="minlen:4"
|
35
|
43
|
data-msg="Please enter your name"
|
36
|
44
|
v-model="agent.name"
|
|
45
|
+ v-bind:class="{
|
|
46
|
+ 'is-valid': agent.name,
|
|
47
|
+ 'is-invalid': !requiredField(agent.name) && nameLoad,
|
|
48
|
+ }"
|
|
49
|
+ v-on:keyup="nameLoad = true"
|
|
50
|
+ v-on:blur="nameLoad = true"
|
37
|
51
|
/>
|
|
52
|
+ <div class="invalid-feedback">Name is Required!</div>
|
38
|
53
|
</float-label>
|
39
|
54
|
</div>
|
40
|
55
|
</div>
|
41
|
56
|
<div class="row mt-4">
|
42
|
|
- <div class="col-md-6">
|
|
57
|
+ <div class="form-group col-md-6">
|
43
|
58
|
<float-label>
|
44
|
59
|
<input
|
45
|
60
|
type="text"
|
46
|
61
|
class="form-control uniInput"
|
47
|
62
|
name="surname"
|
48
|
63
|
id="surname"
|
49
|
|
- placeholder="SURNAME"
|
|
64
|
+ placeholder="Surname"
|
50
|
65
|
data-msg="Please enter your surname"
|
51
|
66
|
v-model="agent.surname"
|
|
67
|
+ v-bind:class="{
|
|
68
|
+ 'is-valid': agent.surname,
|
|
69
|
+ 'is-invalid': !requiredField(agent.surname) && surnameLoad,
|
|
70
|
+ }"
|
|
71
|
+ v-on:keyup="surnameLoad = true"
|
|
72
|
+ v-on:blur="surnameLoad = true"
|
52
|
73
|
/>
|
|
74
|
+ <div class="invalid-feedback">Surname is Required!</div>
|
53
|
75
|
</float-label>
|
54
|
76
|
</div>
|
55
|
|
- <div class="col">
|
|
77
|
+ <div class="form-group col-md-6">
|
56
|
78
|
<float-label>
|
57
|
79
|
<input
|
58
|
80
|
type="text"
|
59
|
81
|
class="form-control uniInput"
|
60
|
82
|
name="email"
|
61
|
83
|
id="email"
|
62
|
|
- placeholder="EMAIL ADDRESS"
|
|
84
|
+ placeholder="Email Address"
|
63
|
85
|
data-msg="Please enter your email address"
|
64
|
86
|
v-model="agent.email"
|
|
87
|
+ v-bind:class="{
|
|
88
|
+ 'is-valid': agent.email,
|
|
89
|
+ 'is-invalid': !validEmail(agent.email) && emailAddressLoad,
|
|
90
|
+ }"
|
|
91
|
+ v-on:keyup="emailAddressLoad = true"
|
|
92
|
+ v-on:blur="emailAddressLoad = true"
|
65
|
93
|
/>
|
|
94
|
+ <div class="invalid-feedback">
|
|
95
|
+ Valid Email address is Required!
|
|
96
|
+ </div>
|
66
|
97
|
</float-label>
|
67
|
98
|
</div>
|
68
|
|
- <!-- <div class="col">
|
69
|
|
- <float-label>
|
70
|
|
- <input
|
71
|
|
- type="text"
|
72
|
|
- name="idnum"
|
73
|
|
- class="form-control uniInput"
|
74
|
|
- id="idnum"
|
75
|
|
- placeholder="ID NUMBER"
|
76
|
|
- data-rule="minlen:4"
|
77
|
|
- data-msg="Please enter your ID number"
|
78
|
|
- />
|
79
|
|
- </float-label>
|
80
|
|
- </div> -->
|
81
|
|
- </div>
|
82
|
|
- <!-- <div class="row mt-4">
|
83
|
|
- <div class="col-md-6">
|
84
|
|
- <float-label>
|
85
|
|
- <input
|
86
|
|
- type="text"
|
87
|
|
- class="form-control uniInput"
|
88
|
|
- name="company"
|
89
|
|
- id="company"
|
90
|
|
- placeholder="COMPANY REG NUMBER"
|
91
|
|
- data-rule="minlen:4"
|
92
|
|
- data-msg="Please enter your company reg number"
|
93
|
|
- />
|
94
|
|
- </float-label>
|
95
|
99
|
</div>
|
96
|
|
- </div> -->
|
97
|
100
|
<div class="row mt-4">
|
98
|
|
- <div class="col">
|
|
101
|
+ <div class="form-group col-md-6">
|
99
|
102
|
<float-label>
|
100
|
103
|
<input
|
101
|
104
|
type="text"
|
102
|
105
|
name="cell"
|
103
|
106
|
class="form-control uniInput"
|
104
|
107
|
id="cell"
|
105
|
|
- placeholder="CELL NUMBER"
|
|
108
|
+ placeholder="Cell Number"
|
106
|
109
|
data-rule="minlen:4"
|
107
|
110
|
data-msg="Please enter your cell number"
|
108
|
111
|
v-model="agent.cellNumber"
|
|
112
|
+ v-bind:class="{
|
|
113
|
+ 'is-valid': agent.cellNumber,
|
|
114
|
+ 'is-invalid':
|
|
115
|
+ validPhoneNumber(agent.cellNumber) &&
|
|
116
|
+ !requiredField(agent.cellNumber) &&
|
|
117
|
+ cellNumberLoad,
|
|
118
|
+ }"
|
|
119
|
+ v-on:keyup="cellNumberLoad = true"
|
|
120
|
+ v-on:blur="cellNumberLoad = true"
|
109
|
121
|
/>
|
|
122
|
+ <div class="invalid-feedback">
|
|
123
|
+ Valid Cell Number is Required!
|
|
124
|
+ </div>
|
110
|
125
|
</float-label>
|
111
|
126
|
</div>
|
112
|
|
- <div class="col">
|
|
127
|
+ <div class="form-group col-md-6">
|
113
|
128
|
<float-label>
|
114
|
129
|
<input
|
115
|
130
|
type="text"
|
116
|
131
|
class="form-control uniInput"
|
117
|
|
- name="landline"
|
118
|
|
- id="landline"
|
119
|
|
- placeholder="TELEPHONE NUMBER"
|
|
132
|
+ name="telephone"
|
|
133
|
+ id="telephone"
|
|
134
|
+ placeholder="Telephone Number"
|
120
|
135
|
data-msg="Please enter your Telephone number"
|
121
|
136
|
v-model="agent.telephone"
|
|
137
|
+ v-bind:class="{
|
|
138
|
+ 'is-valid':
|
|
139
|
+ agent.telephone && validPhoneNumber(agent.telephone),
|
|
140
|
+ 'is-invalid':
|
|
141
|
+ agent.telephone && !validPhoneNumber(agent.telephone),
|
|
142
|
+ }"
|
122
|
143
|
/>
|
123
|
|
- </float-label>
|
124
|
|
- </div>
|
125
|
|
- </div>
|
126
|
|
- <div class="row mt-4">
|
127
|
|
- <div class="col">
|
128
|
|
- <float-label fixed label="AGENCY">
|
129
|
|
- <select
|
130
|
|
- v-model="agent.agencyId"
|
131
|
|
- class="form-control uniSelect"
|
132
|
|
- name=""
|
133
|
|
- id=""
|
134
|
|
- >
|
135
|
|
- <option
|
136
|
|
- v-for="agency in agencies"
|
137
|
|
- :key="agency.id"
|
138
|
|
- :value="agency.id"
|
139
|
|
- >
|
140
|
|
- {{ agency.agencyName }}
|
141
|
|
- </option>
|
142
|
|
- </select>
|
143
|
|
- </float-label>
|
144
|
|
- </div>
|
145
|
|
- </div>
|
146
|
|
- <div v-if="pullUserRole === 'Super Admin'">
|
147
|
|
- <div class="row">
|
148
|
|
- <div class="col">
|
149
|
|
- <div class="section-header">
|
150
|
|
- <h2>Access Control</h2>
|
|
144
|
+ <div class="invalid-feedback">
|
|
145
|
+ Valid telephone number is required!!
|
151
|
146
|
</div>
|
152
|
|
- </div>
|
|
147
|
+ </float-label>
|
153
|
148
|
</div>
|
154
|
|
- <div class="row">
|
|
149
|
+
|
|
150
|
+ <div class="row mt-4">
|
155
|
151
|
<div class="col-md-6">
|
156
|
|
- <float-label label="User Role" style="width: 100%;">
|
|
152
|
+ <float-label fixed label="Agency" style="width: 100%;">
|
157
|
153
|
<select
|
158
|
154
|
class="form-control uniSelect"
|
159
|
|
- id="howMarried"
|
160
|
|
- v-model="agent.user.role"
|
|
155
|
+ v-model="agent.agencyId"
|
|
156
|
+ v-bind:class="{
|
|
157
|
+ 'is-valid': agent.agencyId,
|
|
158
|
+ 'is-invalid':
|
|
159
|
+ !requiredField(agent.agencyId) && inputAgencyLoad,
|
|
160
|
+ }"
|
|
161
|
+ v-on:keyup="inputAgencyLoad = true"
|
|
162
|
+ v-on:blur="inputAgencyLoad = true"
|
161
|
163
|
>
|
|
164
|
+ <option value="">Private User</option>
|
162
|
165
|
<option
|
163
|
|
- v-for="role in getRoles"
|
164
|
|
- :key="role.id"
|
165
|
|
- :value="role.roleName"
|
|
166
|
+ v-for="(item, i) in agencies"
|
|
167
|
+ :key="i"
|
|
168
|
+ :value="item.id"
|
166
|
169
|
>
|
167
|
|
- {{ role.roleName }}
|
|
170
|
+ {{ item.agencyName }}
|
168
|
171
|
</option>
|
169
|
172
|
</select>
|
170
|
173
|
</float-label>
|
171
|
174
|
</div>
|
172
|
|
- <div class="col-md-6">
|
173
|
|
- <input
|
174
|
|
- class="mr-2 mt-3"
|
175
|
|
- name="changePass"
|
176
|
|
- type="checkbox"
|
177
|
|
- v-model="agent.user.loginPasswordChange"
|
178
|
|
- />
|
179
|
|
- <label for="changePass">Change Password on Next Login</label>
|
180
|
|
- </div>
|
181
|
175
|
</div>
|
182
|
|
- </div>
|
183
|
|
- <div class="row">
|
184
|
|
- <div class="col">
|
185
|
|
- <Alert :text="errorMessage" :type="errorOccurred" />
|
|
176
|
+
|
|
177
|
+ <div v-if="pullUserRole === 'Super Admin'">
|
|
178
|
+ <div class="row">
|
|
179
|
+ <div class="col">
|
|
180
|
+ <div class="section-header">
|
|
181
|
+ <h2>Access Control</h2>
|
|
182
|
+ </div>
|
|
183
|
+ </div>
|
|
184
|
+ </div>
|
|
185
|
+
|
|
186
|
+ <div class="row">
|
|
187
|
+ <div class="col-md-6">
|
|
188
|
+ <float-label label="User Role" style="width: 100%;">
|
|
189
|
+ <select
|
|
190
|
+ class="form-control uniSelect"
|
|
191
|
+ id="howMarried"
|
|
192
|
+ v-model="agent.user.role"
|
|
193
|
+ v-bind:class="{
|
|
194
|
+ 'is-valid': agent.user.role,
|
|
195
|
+ 'is-invalid':
|
|
196
|
+ !requiredField(agent.user.role) && userRoleLoad,
|
|
197
|
+ }"
|
|
198
|
+ v-on:keyup="userRoleLoad = true"
|
|
199
|
+ v-on:blur="userRoleLoad = true"
|
|
200
|
+ >
|
|
201
|
+ <option
|
|
202
|
+ v-for="role in getRoles"
|
|
203
|
+ :key="role.id"
|
|
204
|
+ :value="role.roleName"
|
|
205
|
+ >
|
|
206
|
+ {{ role.roleName }}
|
|
207
|
+ </option>
|
|
208
|
+ </select>
|
|
209
|
+ <div class="invalid-feedback">
|
|
210
|
+ User Role is Required!
|
|
211
|
+ </div>
|
|
212
|
+ </float-label>
|
|
213
|
+ </div>
|
|
214
|
+
|
|
215
|
+ <div class="col-md-6">
|
|
216
|
+ <input
|
|
217
|
+ class="mr-2 mt-3"
|
|
218
|
+ name="changePass"
|
|
219
|
+ type="checkbox"
|
|
220
|
+ v-model="agent.user.loginPasswordChange"
|
|
221
|
+ />
|
|
222
|
+ <label for="changePass">Change Password on Next Login</label>
|
|
223
|
+ </div>
|
|
224
|
+ </div>
|
186
|
225
|
</div>
|
187
|
|
- </div>
|
188
|
|
- <div class="row mt-5 mb-5">
|
189
|
|
- <div class="col">
|
190
|
|
- <button class="btn-solid-blue" @click="sendToApi()">SAVE</button>
|
|
226
|
+ <div class="row">
|
|
227
|
+ <div class="col">
|
|
228
|
+ <Alert :text="errorMessage" :type="errorOccurred" />
|
|
229
|
+ </div>
|
191
|
230
|
</div>
|
192
|
|
- <div class="col">
|
193
|
|
- <button class="btn-solid-blue" @click="$router.go(-1)">
|
194
|
|
- CLOSE
|
195
|
|
- </button>
|
|
231
|
+ <div class="row mt-5 mb-5">
|
|
232
|
+ <div class="col">
|
|
233
|
+ <button class="btn-white-border" @click="sendToApi()">
|
|
234
|
+ Save
|
|
235
|
+ </button>
|
|
236
|
+ </div>
|
|
237
|
+ <div class="col">
|
|
238
|
+ <button class="btn-white-border" @click="$router.go(-1)">
|
|
239
|
+ Cancel
|
|
240
|
+ </button>
|
|
241
|
+ </div>
|
196
|
242
|
</div>
|
197
|
243
|
</div>
|
198
|
244
|
</div>
|
|
@@ -208,97 +254,207 @@ import Log from '../../assets/Log'
|
208
|
254
|
import Alert from '../shared/alert'
|
209
|
255
|
|
210
|
256
|
export default {
|
211
|
|
- props: {
|
212
|
|
- agent: {},
|
213
|
|
- },
|
|
257
|
+ name: 'UpdateAgentProfile',
|
214
|
258
|
components: {
|
215
|
259
|
Alert,
|
216
|
260
|
},
|
217
|
261
|
data() {
|
218
|
262
|
return {
|
|
263
|
+ selectedItem: {},
|
|
264
|
+ agent: {},
|
219
|
265
|
errorOccurred: '',
|
220
|
266
|
errorMessage: '',
|
221
|
|
- boolError: false,
|
|
267
|
+ boolMessage: false,
|
|
268
|
+ boolValidationError: false,
|
|
269
|
+ usernameLoad: false,
|
|
270
|
+ nameLoad: false,
|
|
271
|
+ surnameLoad: false,
|
|
272
|
+ emailAddressLoad: false,
|
|
273
|
+ cellNumberLoad: false,
|
|
274
|
+ telephoneNumberLoad: false,
|
|
275
|
+ spouseEmailLoad: false,
|
|
276
|
+ userRoleLoad: false,
|
|
277
|
+ inputAgencyLoad: false,
|
222
|
278
|
}
|
223
|
279
|
},
|
|
280
|
+ props: {},
|
224
|
281
|
created() {
|
225
|
282
|
this.retrieveUserRoles()
|
|
283
|
+ console.log('created')
|
|
284
|
+ this.getIndividual(Log.getUser().id).then(() => {
|
|
285
|
+ if (this.$route.params.agent) {
|
|
286
|
+ this.agent = this.$route.params.agent
|
|
287
|
+
|
|
288
|
+ //if (this.agent.address === null) {
|
|
289
|
+ // this.agent.address = {}
|
|
290
|
+ //}
|
|
291
|
+
|
|
292
|
+ if (
|
|
293
|
+ this.agent.user.role === 'Agent' ||
|
|
294
|
+ this.agent.user.role === 'Agency' ||
|
|
295
|
+ this.agent.user.role === 'Management Agent'
|
|
296
|
+ ) {
|
|
297
|
+ this.getAgentById(this.agent.userId)
|
|
298
|
+ this.agent.agencyId = this.agent[0].agencyId
|
|
299
|
+ }
|
|
300
|
+ } else {
|
|
301
|
+ this.agent = this.indiv
|
|
302
|
+ this.agent.email = this.indiv.emailAddress
|
|
303
|
+ console.log(this.indiv)
|
|
304
|
+ this.agent.user = Log.getUser()
|
|
305
|
+ }
|
|
306
|
+ })
|
226
|
307
|
this.getAgencies()
|
|
308
|
+ console.log('End created')
|
227
|
309
|
},
|
228
|
310
|
computed: {
|
229
|
|
- ...mapGetters('role', ['getRoles']),
|
|
311
|
+ ...mapState('individual', ['indiv']),
|
230
|
312
|
...mapState('timeshare', ['agencies']),
|
|
313
|
+ ...mapState('authentication', ['isLoggedIn', 'user']),
|
|
314
|
+ ...mapGetters({
|
|
315
|
+ user: 'authentication/getUser',
|
|
316
|
+ person: 'authentication/getPerson',
|
|
317
|
+ }),
|
|
318
|
+ ...mapGetters('role', ['getRoles']),
|
|
319
|
+ isLoggedIn() {
|
|
320
|
+ return this.user && this.person
|
|
321
|
+ },
|
231
|
322
|
pullUserRole() {
|
232
|
323
|
return Log.getUser().role
|
233
|
324
|
},
|
234
|
325
|
},
|
235
|
326
|
methods: {
|
|
327
|
+ ...mapActions('individual', ['getIndividual']),
|
236
|
328
|
...mapActions('role', ['retrieveUserRoles']),
|
|
329
|
+ ...mapActions('register', ['getAgentById', 'saveAgent']),
|
237
|
330
|
...mapActions('timeshare', ['getAgencies', 'updateAgent']),
|
238
|
|
- ...mapActions('register', ['saveAgent']),
|
239
|
|
- validPhoneNumber(number) {
|
240
|
|
- const rx = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
|
241
|
|
- return rx.test(String(number))
|
|
331
|
+ onSelectedItemItemChange(item) {
|
|
332
|
+ this.currentUser = item
|
242
|
333
|
},
|
243
|
334
|
sendToApi() {
|
244
|
335
|
this.boolError = false
|
245
|
336
|
this.agent.fullName = this.agent.name + ' ' + this.agent.surname
|
246
|
|
- if (this.agent.telephone !== '') {
|
247
|
|
- if (this.agent.telephone !== null) {
|
248
|
|
- if (!this.validPhoneNumber(this.agent.telephone)) {
|
249
|
|
- this.boolError = true
|
250
|
|
- this.errorOccurred = 'ERROR'
|
251
|
|
- this.errorMessage =
|
252
|
|
- 'The telephone number is not in the correct format.'
|
|
337
|
+ this.agent.emailAddress = this.agent.email
|
|
338
|
+ if (this.validatePage()) {
|
|
339
|
+ if (!this.boolValidationError) {
|
|
340
|
+ if (
|
|
341
|
+ this.agent.user.role === 'Agent' ||
|
|
342
|
+ this.agent.user.role === 'Agency' ||
|
|
343
|
+ this.agent.user.role === 'Managing Agent'
|
|
344
|
+ ) {
|
|
345
|
+ console.log('saveAgent')
|
|
346
|
+ console.log(this.agent)
|
|
347
|
+ this.saveAgent(this.agent)
|
|
348
|
+ .then(() => {
|
|
349
|
+ console.log('saveAgent 1')
|
|
350
|
+ console.log(this.agent)
|
|
351
|
+ this.boolMessage = true
|
|
352
|
+ if (Log.getUser().role === 'Super Admin') {
|
|
353
|
+ console.log(this.agent)
|
|
354
|
+ if (
|
|
355
|
+ this.agent.id ===
|
|
356
|
+ JSON.parse(localStorage.getItem('person')).id
|
|
357
|
+ ) {
|
|
358
|
+ var newPerson = {
|
|
359
|
+ id: JSON.parse(localStorage.getItem('person')).id,
|
|
360
|
+ email: this.agent.email,
|
|
361
|
+ fullname: this.agent.name + ' ' + this.agent.surname,
|
|
362
|
+ name: this.agent.name,
|
|
363
|
+ surname: this.agent.surname,
|
|
364
|
+ }
|
|
365
|
+ localStorage.setItem('person', JSON.stringify(newPerson))
|
|
366
|
+ this.$router.go()
|
|
367
|
+ }
|
|
368
|
+ if (Log.getUser().role === 'Super Admin') {
|
|
369
|
+ this.$router.push('/status/userManagementPage')
|
|
370
|
+ } else {
|
|
371
|
+ this.$router.push('/')
|
|
372
|
+ }
|
|
373
|
+ } else {
|
|
374
|
+ var newPerson = {
|
|
375
|
+ id: JSON.parse(localStorage.getItem('person')).id,
|
|
376
|
+ email: this.agent.email,
|
|
377
|
+ fullname: this.agent.name + ' ' + this.agent.surname,
|
|
378
|
+ name: this.agent.name,
|
|
379
|
+ surname: this.agent.surname,
|
|
380
|
+ }
|
|
381
|
+ localStorage.setItem('person', JSON.stringify(newPerson))
|
|
382
|
+ this.$router.go()
|
|
383
|
+ }
|
|
384
|
+ })
|
|
385
|
+ .catch((err) => {
|
|
386
|
+ console.log(err)
|
|
387
|
+ this.errorOccurred = 'ERRORHTML'
|
|
388
|
+
|
|
389
|
+ this.errorOccurred = 'ERROR'
|
|
390
|
+ this.errorMessage = 'Server Error: CONNECTION_REFUSED'
|
|
391
|
+ console.log(err.status)
|
|
392
|
+ if (err.status) {
|
|
393
|
+ if (err.data.message) {
|
|
394
|
+ this.errorMessage = err.data.message
|
|
395
|
+ } else {
|
|
396
|
+ this.errorMessage = err
|
|
397
|
+ }
|
|
398
|
+ }
|
|
399
|
+ })
|
253
|
400
|
}
|
254
|
401
|
}
|
|
402
|
+ }
|
|
403
|
+ },
|
|
404
|
+ requiredField: function (tfield) {
|
|
405
|
+ if (tfield) {
|
|
406
|
+ return true
|
255
|
407
|
} else {
|
256
|
|
- this.agent.telephone = null
|
|
408
|
+ return false
|
257
|
409
|
}
|
258
|
|
- if (this.agent.cellNumber !== '') {
|
259
|
|
- if (this.agent.cellNumber !== null) {
|
260
|
|
- if (!this.validPhoneNumber(this.agent.cellNumber)) {
|
261
|
|
- this.boolError = true
|
262
|
|
- this.errorOccurred = 'ERROR'
|
263
|
|
- this.errorMessage =
|
264
|
|
- 'The cellphone number is not in the correct format.'
|
265
|
|
- }
|
266
|
|
- }
|
|
410
|
+ },
|
|
411
|
+ validEmail: function (email) {
|
|
412
|
+ var re = /(.+)@(.+){2,}\.(.+){2,}/
|
|
413
|
+ if (email) {
|
|
414
|
+ return re.test(email.toLowerCase())
|
267
|
415
|
} else {
|
268
|
|
- this.agent.cellNumber = null
|
|
416
|
+ return re.test(email)
|
269
|
417
|
}
|
|
418
|
+ },
|
|
419
|
+ validPhoneNumber(number) {
|
|
420
|
+ if (number) {
|
|
421
|
+ const rx = /^\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$/
|
|
422
|
+ // const rx = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
|
|
423
|
+ return rx.test(String(number))
|
|
424
|
+ } else {
|
|
425
|
+ return true
|
|
426
|
+ }
|
|
427
|
+ },
|
|
428
|
+ validatePage: function () {
|
|
429
|
+ console.log('validatePage')
|
|
430
|
+ if (
|
|
431
|
+ this.agent.name &&
|
|
432
|
+ this.agent.surname &&
|
|
433
|
+ this.agent.emailAddress &&
|
|
434
|
+ this.agent.cellNumber &&
|
|
435
|
+ this.agent.user.role &&
|
|
436
|
+ this.validEmail(this.agent.emailAddress) &&
|
|
437
|
+ this.validPhoneNumber(this.agent.cellNumber) &&
|
|
438
|
+ this.validPhoneNumber(this.agent.telephone)
|
|
439
|
+ ) {
|
|
440
|
+ console.log('passed')
|
|
441
|
+ this.errorOccurred = ''
|
|
442
|
+ this.errorMessage = ''
|
|
443
|
+ this.boolValidationError = false
|
270
|
444
|
|
271
|
|
- if (!this.boolError) {
|
272
|
|
- if (
|
273
|
|
- this.agent.user.role === 'Agent' ||
|
274
|
|
- this.agent.user.role === 'Agency' ||
|
275
|
|
- this.agent.user.role === 'Managing Agent'
|
276
|
|
- ) {
|
277
|
|
- this.updateAgent(this.agent).then(() => {
|
278
|
|
- var newPerson = {
|
279
|
|
- id: JSON.parse(localStorage.getItem('person')).id,
|
280
|
|
- email: this.agent.email,
|
281
|
|
- fullname: this.agent.name + ' ' + this.agent.surname,
|
282
|
|
- name: this.agent.name,
|
283
|
|
- surname: this.agent.surnmame,
|
284
|
|
- }
|
285
|
|
- localStorage.setItem('person', JSON.stringify(newPerson))
|
286
|
|
- console.log(newPerson)
|
287
|
|
- this.$router.push('/')
|
288
|
|
- })
|
289
|
|
- } else {
|
290
|
|
- this.saveAgent(this.agent)
|
291
|
|
- .then(() => {
|
292
|
|
- if (Log.getUser().role === 'Super Admin') {
|
293
|
|
- this.$router.push('/status/userManagementPage')
|
294
|
|
- } else {
|
295
|
|
- this.$router.push('/')
|
296
|
|
- }
|
297
|
|
- })
|
298
|
|
- .catch((ex) => {
|
299
|
|
- console.log(ex)
|
300
|
|
- })
|
301
|
|
- }
|
|
445
|
+ return true
|
|
446
|
+ } else {
|
|
447
|
+ console.log('failed')
|
|
448
|
+ this.nameLoad = true
|
|
449
|
+ this.surnameLoad = true
|
|
450
|
+ this.emailAddressLoadLoad = true
|
|
451
|
+ this.cellNumberLoad = true
|
|
452
|
+ this.telephoneLoad = true
|
|
453
|
+ this.userRoleLoad = true
|
|
454
|
+ this.boolValidationError = true
|
|
455
|
+ this.errorOccurred = 'ERROR'
|
|
456
|
+ this.errorMessage = 'Please check form and correct all input fields!'
|
|
457
|
+ return false
|
302
|
458
|
}
|
303
|
459
|
},
|
304
|
460
|
},
|