You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

registerIndividual.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <main id="main" style="padding-top: 10px; padding-bottom: 50px;">
  3. <div class="form">
  4. <div v-if="boolMessage" class="row">
  5. <div class="col">
  6. <alert
  7. :text="'Register Success! You\'ll be redirected shortly.'"
  8. :type="'SUCCESS'"
  9. />
  10. </div>
  11. </div>
  12. <div v-if="boolValidationError" class="row">
  13. <div class="col">
  14. <alert :text="errorMessage" :type="errorOccurred" />
  15. </div>
  16. </div>
  17. <h3 class="card-title text-center">User Details</h3>
  18. <div class="row">
  19. <div class="col-sm-12 col-md-6">
  20. <div class="form-group">
  21. <float-label label="Name" style="width: 100%;">
  22. <input
  23. type="text"
  24. id="inputName"
  25. class="form-control uniInput my-2"
  26. v-model="indivUser.name"
  27. v-bind:class="{
  28. 'is-valid': indivUser.name,
  29. 'is-invalid': !requiredField(indivUser.name) && nameLoad,
  30. }"
  31. v-on:keyup="nameLoad = true"
  32. v-on:blur="nameLoad = true"
  33. placeholder="Name"
  34. />
  35. <div class="invalid-feedback">Name is required!</div>
  36. </float-label>
  37. </div>
  38. <div class="form-group">
  39. <float-label label="Surname" style="width: 100%;">
  40. <input
  41. type="text"
  42. id="inputSurname"
  43. class="form-control uniInput my-2"
  44. v-model="indivUser.surname"
  45. v-bind:class="{
  46. 'is-valid': indivUser.surname,
  47. 'is-invalid':
  48. !requiredField(indivUser.surname) && surnameLoad,
  49. }"
  50. v-on:keyup="surnameLoad = true"
  51. v-on:blur="surnameLoad = true"
  52. placeholder="Surname"
  53. />
  54. <div class="invalid-feedback">Surname is required!</div>
  55. </float-label>
  56. </div>
  57. <div class="form-group">
  58. <float-label label="Email" style="width: 100%;">
  59. <input
  60. type="email"
  61. id="inputEmail"
  62. v-model="indivUser.email"
  63. class="form-control uniInput my-2"
  64. v-bind:class="{
  65. 'is-valid': indivUser.email,
  66. 'is-invalid': !validEmail(indivUser.email) && emailLoad,
  67. }"
  68. v-on:keyup="emailLoad = true"
  69. v-on:blur="emailLoad = true"
  70. placeholder="Email"
  71. />
  72. <div class="invalid-feedback">
  73. Valid email address is required!
  74. </div>
  75. </float-label>
  76. </div>
  77. </div>
  78. <div class="col-sm-12 col-md-6">
  79. <div class="form-group">
  80. <float-label label="Cellphone Number" style="width: 100%;">
  81. <input
  82. type="text"
  83. id="inputCellNumber"
  84. name="inputCellNumber"
  85. v-model="indivUser.cellNumber"
  86. class="form-control uniInput my-2"
  87. v-bind:class="{
  88. 'is-valid': indivUser.cellNumber,
  89. 'is-invalid':
  90. !requiredField(indivUser.cellNumber) && cellNumberLoad,
  91. }"
  92. v-on:keyup="cellNumberLoad = true"
  93. v-on:blur="cellNumberLoad = true"
  94. placeholder="Cellphone Number"
  95. />
  96. <div class="invalid-feedback">Cellphone number is required!</div>
  97. </float-label>
  98. </div>
  99. <div class="form-group">
  100. <float-label label="Landline Number" style="width: 100%;">
  101. <input
  102. type="text"
  103. id="inputTelephone"
  104. v-model="indivUser.telephone"
  105. class="form-control uniInput my-2"
  106. v-bind:class="{ 'is-valid': indivUser.telephone }"
  107. placeholder="Landline Number"
  108. />
  109. </float-label>
  110. </div>
  111. </div>
  112. </div>
  113. <hr />
  114. <div class="row">
  115. <div class="col-sm-12">
  116. <float-label label="Username" style="width: 100%;">
  117. <input
  118. type="text"
  119. id="inputUsername"
  120. v-model="indivUser.username"
  121. class="form-control uniInput my-2"
  122. v-bind:class="{
  123. 'is-valid': indivUser.username,
  124. 'is-invalid':
  125. !requiredField(indivUser.username) && usernameLoad,
  126. }"
  127. v-on:keyup="usernameLoad = true"
  128. v-on:blur="usernameLoad = true"
  129. placeholder="Username"
  130. />
  131. <div class="invalid-feedback">Username is required!</div>
  132. </float-label>
  133. </div>
  134. </div>
  135. <div class="row">
  136. <div class="col-sm-12 col-md-6">
  137. <float-label label="Password" style="width: 100%;">
  138. <input
  139. type="password"
  140. placeholder="Password "
  141. v-model="indivUser.password"
  142. id="inputPassword"
  143. class="form-control uniInput my-2"
  144. v-bind:class="{
  145. 'is-valid': indivUser.password,
  146. 'is-invalid':
  147. !requiredField(indivUser.password) && passwordLoad,
  148. }"
  149. v-on:keyup="passwordLoad = true"
  150. v-on:blur="passwordLoad = true"
  151. />
  152. <div class="invalid-feedback">Password is required!</div>
  153. </float-label>
  154. </div>
  155. <div class="col">
  156. <float-label label="Confirm Password" style="width: 100%;">
  157. <input
  158. type="password"
  159. placeholder="Confirm Password"
  160. v-model="indivUser.confirmPassword"
  161. id="inputConfirmPassword"
  162. class="form-control uniInput my-2"
  163. v-bind:class="{
  164. 'is-valid': indivUser.confirmPassword,
  165. 'is-invalid':
  166. !validConfirm(indivUser.confirmPassword) &&
  167. confirmPasswordLoad,
  168. }"
  169. v-on:keyup="confirmPasswordLoad = true"
  170. v-on:blur="confirmPasswordLoad = true"
  171. />
  172. <div class="invalid-feedback">
  173. Password and Confirm password must be the same!
  174. </div>
  175. </float-label>
  176. </div>
  177. </div>
  178. <div class="row">
  179. <div class="col">
  180. <label for="tc">
  181. <router-link to="/termsConditionsView">
  182. Terms & Conditions
  183. </router-link>
  184. </label>
  185. <input name="tc" type="checkbox" class="ml-3 mt-2" v-model="terms" />
  186. </div>
  187. </div>
  188. <button
  189. v-if="terms"
  190. class="btn-white-border"
  191. v-on:click="SubmitData()"
  192. type="submit"
  193. >
  194. SUBMIT
  195. </button>
  196. <button
  197. :data-target="'#myNewUserModal'"
  198. data-toggle="modal"
  199. @click="navigate()"
  200. class="btn-white-border"
  201. style="float: right;"
  202. type="submit"
  203. >
  204. Cancel
  205. </button>
  206. <button
  207. hidden
  208. :data-target="'#myModalAgency'"
  209. data-toggle="modal"
  210. ref="dataToggle"
  211. ></button>
  212. </div>
  213. </main>
  214. </template>
  215. <script>
  216. /* eslint-disable */
  217. import { mapState, mapActions } from 'vuex'
  218. import carousel from 'vue-owl-carousel'
  219. import alert from '../shared/alert'
  220. import Log from '../../assets/Log'
  221. export default {
  222. components: {
  223. carousel,
  224. alert,
  225. },
  226. props: {
  227. RegisterHeader: { type: String, default: undefined },
  228. },
  229. name: 'PrivateIndividual',
  230. data() {
  231. return {
  232. isPasswordShown: 'password',
  233. selectItems: [{ text: 'password', value: 0 }],
  234. showPassword: false,
  235. boolMessage: false,
  236. terms: false,
  237. indivUser: {
  238. name: '',
  239. surname: '',
  240. email: '',
  241. cellNumber: '',
  242. telephone: '',
  243. username: '',
  244. password: '',
  245. confirmPassword: '',
  246. },
  247. boolValidationError: false,
  248. nameLoad: false,
  249. surnameLoad: false,
  250. emailLoad: false,
  251. cellNumberLoad: false,
  252. telephoneLoad: false,
  253. usernameLoad: false,
  254. passwordLoad: false,
  255. confirmPasswordLoad: false,
  256. errorOccurred: '',
  257. errorMessage: '',
  258. }
  259. },
  260. computed: {
  261. ...mapState('register', ['registerIndividual']),
  262. Header() {
  263. return this.RegisterHeader
  264. ? 'Agency Administrator Details'
  265. : 'Private Individual'
  266. },
  267. },
  268. methods: {
  269. ...mapActions('register', [
  270. 'getIndividual',
  271. 'saveIndividual',
  272. 'updateIndividual',
  273. 'clearIndividual',
  274. ]),
  275. navigate() {
  276. if (Log.getUser().role !== 'Super Admin') {
  277. this.$router.push('/user/login')
  278. }
  279. },
  280. togglePassword() {
  281. this.showPassword = true
  282. this.isPasswordShown = 'text'
  283. },
  284. passwordToggled() {
  285. this.showPassword = false
  286. this.isPasswordShown = 'password'
  287. },
  288. SubmitData() {
  289. this.indivUser.acceptedTerms = this.terms
  290. if (this.validatePage()) {
  291. this.saveIndividual(this.indivUser)
  292. .then((res) => {
  293. this.boolMessage = true
  294. setTimeout(() => {
  295. if (Log.getUser().role !== 'Super Admin') {
  296. this.$router.push('/user/login')
  297. } else {
  298. this.$refs.dataToggle.click()
  299. this.$router.go()
  300. }
  301. }, 500)
  302. })
  303. .catch((err) => {
  304. console.log(err)
  305. this.boolValidationError = true
  306. this.errorOccurred = 'ERROR'
  307. this.errorMessage = 'Server Error: CONNECTION_REFUSED'
  308. if (err) {
  309. if (err.data.message) {
  310. this.errorMessage = err.data.message
  311. } else {
  312. this.errorMessage = 'Error.'
  313. }
  314. }
  315. })
  316. }
  317. },
  318. Close() {
  319. this.$router.push('/user/login')
  320. },
  321. validatePage: function () {
  322. console.log('validatePage')
  323. if (
  324. this.indivUser.name &&
  325. this.indivUser.surname &&
  326. this.indivUser.email &&
  327. this.indivUser.cellNumber &&
  328. this.indivUser.username &&
  329. this.indivUser.password &&
  330. this.indivUser.password === this.indivUser.confirmPassword
  331. ) {
  332. this.errorOccurred = ''
  333. this.errorMessage = ''
  334. this.boolValidationError = false
  335. return true
  336. } else {
  337. this.boolValidationError = true
  338. ;(this.nameLoad = true),
  339. (this.surnameLoad = true),
  340. (this.emailLoad = true),
  341. (this.cellNumberLoad = true),
  342. (this.telephoneLoad = true),
  343. (this.usernameLoad = true),
  344. (this.passwordLoad = true),
  345. (this.confirmPasswordLoad = true),
  346. (this.errorOccurred = 'ERROR')
  347. this.errorMessage = 'Please check form and correct all input fields!'
  348. return false
  349. }
  350. },
  351. requiredField: function (tfield) {
  352. if (tfield) {
  353. return true
  354. } else {
  355. return false
  356. }
  357. },
  358. validEmail: function (email) {
  359. var re = /(.+)@(.+){2,}\.(.+){2,}/
  360. if (email) {
  361. return re.test(email.toLowerCase())
  362. } else {
  363. return re.test(email)
  364. }
  365. },
  366. validConfirm: function (tfield) {
  367. if (this.requiredField(tfield)) {
  368. if (tfield === this.indivUser.password) {
  369. return true
  370. } else {
  371. return false
  372. }
  373. } else {
  374. return false
  375. }
  376. },
  377. },
  378. }
  379. </script>
  380. <style lang="scss" scoped>
  381. .btn-disabled {
  382. font-family: 'Muli';
  383. font-size: 15px;
  384. letter-spacing: 1px;
  385. display: inline-block;
  386. padding: 10px 32px;
  387. border-radius: 2px;
  388. transition: 0.5s;
  389. margin: 10px;
  390. color: #fff;
  391. background: grey;
  392. border-color: black;
  393. color: black;
  394. cursor: not-allowed;
  395. }
  396. .btn-disabled :hover {
  397. background: grey;
  398. border-color: black;
  399. color: black;
  400. cursor: not-allowed;
  401. }
  402. </style>