Angular project using NgRx pattern to manage state of a system

user-update.component.html 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <div class="container" *ngIf="userFormGrp">
  2. <ng-container *ngIf="userState">
  3. <ng-container *ngIf="userState.msgState == msg.FORM_LOADING">
  4. msg.FORM_LOADING
  5. </ng-container>
  6. <ng-container *ngIf="userState.msgState == msg.FORM_LOAD_ERR">
  7. <div class="alert-danger container">
  8. {{ msg.FORM_LOAD_ERR }}
  9. </div>
  10. </ng-container>
  11. <ng-container *ngIf="userState.msgState == msg.FORM_LOAD_ERR">
  12. <div class="alert-danger container">
  13. {{ msg.FORM_LOAD_ERR }}
  14. </div>
  15. </ng-container>
  16. <ng-container *ngIf="userState.msgState == msg.FORM_LOADED">
  17. <div class="card mt-3">
  18. <div class="card-header bg-light">
  19. User informations to modify: <b>ID of user:
  20. {{ userState.currentUser?.id }}</b>
  21. </div>
  22. <div class="card-body">
  23. <form
  24. [formGroup]="userFormGrp"
  25. (ngSubmit)="onUserUpdate(); userFormGrp.reset()"
  26. >
  27. <div class="row">
  28. <div class="col card">
  29. <div class="col-md-auto mb-3">
  30. <label for="id">Firstname</label>
  31. <input
  32. type="text"
  33. class="form-control"
  34. formControlName="firstname"
  35. [ngClass]="{
  36. 'is-invalid':
  37. userFormGrp.controls['firstname'].touched &&
  38. !userFormGrp.controls['firstname'].valid
  39. }"
  40. />
  41. <div class="invalid-feedback">
  42. <span
  43. *ngIf="userFormGrp.controls['firstname'].errors?.['required']"
  44. >required</span
  45. >
  46. <span
  47. *ngIf="userFormGrp.controls['firstname'].errors?.['minlength']"
  48. >min nbr chars 3</span
  49. >
  50. <span
  51. *ngIf="userFormGrp.controls['firstname'].errors?.['maxlength']"
  52. >max nbr chars 20</span
  53. >
  54. </div>
  55. </div>
  56. <div class="col-md-auto mb-3">
  57. <label for="id">Lastname</label>
  58. <input
  59. type="text"
  60. class="form-control"
  61. formControlName="lastname"
  62. [ngClass]="{
  63. 'is-invalid':
  64. userFormGrp.controls['lastname'].touched &&
  65. !userFormGrp.controls['lastname'].valid
  66. }"
  67. />
  68. <div class="invalid-feedback">
  69. <span
  70. *ngIf="userFormGrp.controls['lastname'].errors?.['required']"
  71. >required</span
  72. >
  73. <span
  74. *ngIf="userFormGrp.controls['lastname'].errors?.['minlength']"
  75. >min nbr char 3</span
  76. >
  77. <span
  78. *ngIf="userFormGrp.controls['lastname'].errors?.['maxlength']"
  79. >max nbr char 20</span
  80. >
  81. </div>
  82. </div>
  83. <div class="col-md-auto mb-3">
  84. <label for="email">Email</label>
  85. <input
  86. type="text"
  87. class="form-control"
  88. formControlName="email"
  89. [ngClass]="{
  90. 'is-invalid':
  91. userFormGrp.controls['email'].touched &&
  92. !userFormGrp.controls['email'].valid
  93. }"
  94. />
  95. <div class="invalid-feedback">
  96. <span
  97. *ngIf="userFormGrp.controls['email'].errors?.['required']"
  98. >
  99. required
  100. </span>
  101. <span
  102. *ngIf="userFormGrp.controls['email'].errors?.['email']"
  103. >
  104. not valid
  105. </span>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="col card">
  110. <div formGroupName="address">
  111. <div class="col-md-auto mb-3">
  112. <label for="numRue">Street number</label>
  113. <input
  114. type="number"
  115. class="form-control"
  116. formControlName="numRue"
  117. [ngClass]="{
  118. 'is-invalid':
  119. userFormGrp.controls['address'].get('numRue')
  120. ?.touched &&
  121. !userFormGrp.controls['address'].get('numRue')?.valid
  122. }"
  123. />
  124. <div class="invalid-feedback">
  125. <span
  126. *ngIf="userFormGrp.controls['address'].get('numRue')?.errors?.['required']"
  127. >required</span
  128. >
  129. <span
  130. *ngIf="userFormGrp.controls['address'].get('numRue')?.errors?.['min']"
  131. >street num >0
  132. </span>
  133. </div>
  134. </div>
  135. <div class="col-md-auto mb-3">
  136. <label for="nomRue">Street Name</label>
  137. <input
  138. type="text"
  139. class="form-control"
  140. formControlName="nomRue"
  141. [ngClass]="{
  142. 'is-invalid':
  143. userFormGrp.controls['address'].get('nomRue')
  144. ?.touched &&
  145. !userFormGrp.controls['address'].get('nomRue')?.valid
  146. }"
  147. />
  148. <div class="invalid-feedback">
  149. <span
  150. *ngIf="userFormGrp.controls['address'].get('nomRue')?.errors?.['required']"
  151. >required</span
  152. >
  153. <span
  154. *ngIf="userFormGrp.controls['address'].get('nomRue')?.errors?.['minlength']"
  155. >min chars 3
  156. </span>
  157. <span
  158. *ngIf="userFormGrp.controls['address'].get('nomRue')?.errors?.['maxlength']"
  159. >max chars 15
  160. </span>
  161. </div>
  162. </div>
  163. <div class="col-md-auto mb-3">
  164. <label for="bp">PB</label>
  165. <input
  166. type="number"
  167. class="form-control"
  168. formControlName="bp"
  169. [ngClass]="{
  170. 'is-invalid':
  171. userFormGrp.controls['address'].get('bp')?.touched &&
  172. !userFormGrp.controls['address'].get('bp')?.valid
  173. }"
  174. />
  175. <div class="invalid-feedback">
  176. <span
  177. *ngIf="userFormGrp.controls['address'].get('bp')?.errors?.['required']"
  178. >required</span
  179. >
  180. <span
  181. *ngIf="userFormGrp.controls['address'].get('bp')?.errors?.['min']"
  182. >pb >0
  183. </span>
  184. </div>
  185. </div>
  186. <div class="col-md-auto mb-3">
  187. <label for="city">City</label>
  188. <input
  189. type="text"
  190. class="form-control"
  191. formControlName="ville"
  192. [ngClass]="{
  193. 'is-invalid':
  194. userFormGrp.controls['address'].get('ville')
  195. ?.touched &&
  196. !userFormGrp.controls['address'].get('vile')?.valid
  197. }"
  198. />
  199. <div class="invalid-feedback">
  200. <span
  201. *ngIf="userFormGrp.controls['address'].get('ville')?.errors?.['required']"
  202. >required</span
  203. >
  204. <span
  205. *ngIf="userFormGrp.controls['address'].get('ville')?.errors?.['minlength']"
  206. >min chars 3
  207. </span>
  208. <span
  209. *ngIf="userFormGrp.controls['address'].get('ville')?.errors?.['maxlength']"
  210. >max chars 15
  211. </span>
  212. </div>
  213. </div>
  214. <div class="col-md-auto mb-3">
  215. <label for="pays">Country</label>
  216. <input
  217. type="text"
  218. class="form-control"
  219. formControlName="pays"
  220. [ngClass]="{
  221. 'is-invalid':
  222. userFormGrp.controls['address'].get('pays')
  223. ?.touched &&
  224. !userFormGrp.controls['address'].get('pays')?.valid
  225. }"
  226. />
  227. <div class="invalid-feedback">
  228. <span
  229. *ngIf="userFormGrp.controls['address'].get('pays')?.errors?.['required']"
  230. >required</span
  231. >
  232. <span
  233. *ngIf="userFormGrp.controls['address'].get('pays')?.errors?.['minlength']"
  234. >min chars 3
  235. </span>
  236. <span
  237. *ngIf="userFormGrp.controls['address'].get('pays')?.errors?.['maxlength']"
  238. >max chars 15
  239. </span>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="text-center col-md-auto mt-3">
  246. <button
  247. class="btn btn-outline-primary"
  248. type="submit"
  249. [disabled]="!userFormGrp.valid"
  250. >
  251. update
  252. </button>
  253. </div>
  254. </form>
  255. </div>
  256. </div>
  257. </ng-container>
  258. <ng-container *ngIf="userState.msgState == msg.UPDATED">
  259. <div class="alert-success container p-3 m-3" style="width: 30em">
  260. <span> {{ msg.UPDATED }}</span> &nbsp;&nbsp;
  261. <button class="btn btn-success" (click)="onUpdateOk()">OK</button>
  262. </div>
  263. </ng-container>
  264. </ng-container>
  265. </div>

Powered by TurnKey Linux.