update borrow + fix invite

This commit is contained in:
_Bastler
2021-10-27 17:07:44 +02:00
parent 59ac345933
commit 925a03fd46
45 changed files with 2792 additions and 398 deletions
+71
View File
@@ -0,0 +1,71 @@
import { Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { MatchingValidator } from '../../../utils/matching.validator';
import { InviteService } from '../../../services/invites.service';
import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-invite-edit',
templateUrl: './invite.edit.html',
styleUrls: [ './invite.edit.scss' ]
})
export class InviteEditComponent {
form: FormGroup;
error: string;
working: boolean = false;
success: boolean = false;
invite: any;
constructor(
private inviteService: InviteService,
private formBuilder: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<InviteEditComponent>,
public dialog: MatDialog) {
this.form = this.formBuilder.group({
message: [ '', Validators.nullValidator ],
note: [ '', Validators.nullValidator ],
});
this.invite = data;
this.form.get("message").setValue(this.invite.message);
this.form.get("note").setValue(this.invite.note);
}
save() {
if (this.form.valid && !this.working) {
this.working = true;
this.invite.message = this.form.get("message").value;
this.invite.note = this.form.get("note").value;
this.inviteService.update(this.invite).subscribe((result: any) => {
this.working = false;
this.dialogRef.close(result);
}, (error) => {
this.working = false;
if (error.status == 406) {
this.error = "INVALID_CODE";
} if (error.status == 410) {
this.error = "ALREADY_REDEEMED";
} else if (error.status == 409) {
let errors = {};
for (let code of error.error) {
errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]);
}
}
})
}
}
}