Now able to post to mock-api
This commit is contained in:
+13
-4
@@ -1,6 +1,8 @@
|
||||
import { RadiobuttonModel } from '@af/digi-ng/_form/form-radiobutton-group';
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { StaffService } from '@dafa-services/api/staff.service';
|
||||
import { RequiredValidator } from '@dafa-validators/required.validator';
|
||||
import { SocialSecurityNumberValidator } from '@dafa-validators/social-security-number.validator';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
@@ -16,7 +18,7 @@ export class CreateAccountComponent {
|
||||
formGroup: FormGroup;
|
||||
todaysDate = new Date();
|
||||
|
||||
constructor(private formBuilder: FormBuilder) {
|
||||
constructor(private formBuilder: FormBuilder, private staffService: StaffService, private router: Router) {
|
||||
this.formGroup = this.formBuilder.group({
|
||||
firstName: this.formBuilder.control('', [RequiredValidator('Förnamn')]),
|
||||
lastName: this.formBuilder.control('', [RequiredValidator('Efternamn')]),
|
||||
@@ -94,16 +96,23 @@ export class CreateAccountComponent {
|
||||
if (this.formGroup.valid) {
|
||||
const submittableValues = {
|
||||
...this.formGroup.value,
|
||||
fullName: `${this.firstNameControl.value} ${this.lastNameControl.value}`,
|
||||
outOfOffice: this.pendingOutOfOfficeDates,
|
||||
};
|
||||
|
||||
delete submittableValues.outOfOfficeStart;
|
||||
delete submittableValues.outOfOfficeEnd;
|
||||
|
||||
console.warn('Should submit the form...');
|
||||
console.table(submittableValues);
|
||||
const post = this.staffService.createAccount(submittableValues).subscribe({
|
||||
next: id => {
|
||||
this.router.navigate(['/administration', 'personal', id]);
|
||||
},
|
||||
complete: () => {
|
||||
post.unsubscribe();
|
||||
},
|
||||
});
|
||||
|
||||
this.formGroup.reset();
|
||||
// this.formGroup.reset();
|
||||
} else {
|
||||
console.error('Form is invalid, do something...');
|
||||
this._markFormAsDirty();
|
||||
|
||||
+5
-5
@@ -32,7 +32,7 @@
|
||||
|
||||
<dl>
|
||||
<dt>Behörighet</dt>
|
||||
<ng-container *ngIf="detailedStaffData.authorisations.length; else emptyDD">
|
||||
<ng-container *ngIf="detailedStaffData.authorisations?.length; else emptyDD">
|
||||
<dd *ngFor="let item of detailedStaffData.authorisations">
|
||||
{{ item }}
|
||||
</dd>
|
||||
@@ -40,7 +40,7 @@
|
||||
<dt>Aktivt i arbete</dt>
|
||||
<dd>{{ detailedStaffData.active ? 'Ja' : 'Nej' }}</dd>
|
||||
<dt>Frånvaroperiod</dt>
|
||||
<ng-container *ngIf="detailedStaffData.outOfOffice.length; else emptyDD">
|
||||
<ng-container *ngIf="detailedStaffData.outOfOffice?.length; else emptyDD">
|
||||
<dd *ngFor="let date of detailedStaffData.outOfOffice">
|
||||
{{ date.start | localDate }} - {{ date.end | localDate }}
|
||||
</dd>
|
||||
@@ -72,9 +72,9 @@
|
||||
<div class="staff-card__column">
|
||||
<digi-ng-layout-expansion-panel>
|
||||
<h3 style="margin-bottom: 0" data-slot-trigger>
|
||||
Tilldelade deltagare ({{ detailedStaffData.participants.length }})
|
||||
Tilldelade deltagare ({{ detailedStaffData.participants?.length || 0 }})
|
||||
</h3>
|
||||
<ng-container *ngIf="detailedStaffData.participants.length; else noParticipantsInfo">
|
||||
<ng-container *ngIf="detailedStaffData.participants?.length; else noParticipantsInfo">
|
||||
<ul class="staff-card__participants">
|
||||
<li *ngIf="detailedStaffData.participants.length > 1" class="staff-card__participant">
|
||||
<digi-form-checkbox
|
||||
@@ -91,7 +91,7 @@
|
||||
<li *ngFor="let participant of detailedStaffData.participants" class="staff-card__participant">
|
||||
<digi-form-checkbox
|
||||
af-variation="primary"
|
||||
[afLabel]="participant.fullName + ' - ' + participant.id"
|
||||
[afLabel]="participant.fullName"
|
||||
[afValue]="participant.id"
|
||||
[afChecked]="pendingSelectedParticipants.includes(participant.id)"
|
||||
(afOnChange)="handleChangeParticipant(participant.id, $event.detail.target.checked)"
|
||||
|
||||
Reference in New Issue
Block a user