added accept and decline functions
This commit is contained in:
parent
50a73f50ef
commit
51fded7271
@ -11,7 +11,7 @@
|
||||
</div>
|
||||
<div class="group-buttons d-flex align-items-center">
|
||||
<button (click)="onAccept(candidate.id)" class="btn btn-primary">Accept</button>
|
||||
<button (click)="onDecline(candidate.id)" class="btn btn-primary">Decline</button>
|
||||
<button (click)="onDecline(candidate.id)" class="btn btn-primary ml-2">Decline</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
|
||||
import { User } from 'src/app/user/interfaces/user.interface';
|
||||
|
||||
@Component({
|
||||
@ -9,6 +9,8 @@ import { User } from 'src/app/user/interfaces/user.interface';
|
||||
export class GroupCandidatesComponent implements OnInit {
|
||||
|
||||
@Input() candidates: User[];
|
||||
@Output() accept = new EventEmitter<string>();
|
||||
@Output() decline = new EventEmitter<string>();
|
||||
|
||||
constructor() { }
|
||||
|
||||
@ -17,11 +19,11 @@ export class GroupCandidatesComponent implements OnInit {
|
||||
}
|
||||
|
||||
onAccept(id: string): void {
|
||||
|
||||
this.accept.emit(id);
|
||||
}
|
||||
|
||||
onDecline(id: string): void {
|
||||
|
||||
this.decline.emit(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<div *ngIf="group$ | async as group" class="mt-5 d-flex justify-content-center">
|
||||
<div class="edit-group-wrapper">
|
||||
<div class="d-flex justify-content-end">
|
||||
<button *ngIf="group.admin.id === userId" (click)="onDelete()" class="btn btn-primary">Delete group</button>
|
||||
<button *ngIf="group.admin.id !== userId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button>
|
||||
<button *ngIf="group.admin.id === currentUserId" (click)="onDelete()" class="btn btn-primary">Delete group</button>
|
||||
<button *ngIf="group.admin.id !== currentUserId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button>
|
||||
</div>
|
||||
<div class="group-main-data mb-5">
|
||||
<h3>Group info:</h3>
|
||||
@ -21,11 +21,17 @@
|
||||
</div>
|
||||
<div class="mb-5 border p-3">
|
||||
<h3>Users:</h3>
|
||||
<app-group-users [groupUsers]="group.users"></app-group-users>
|
||||
<app-group-users
|
||||
[groupUsers]="group.users"
|
||||
[adminId]="group.admin.id"></app-group-users>
|
||||
</div>
|
||||
<div *ngIf="group.admin.id === userId && group.groupCandidates" class="mb-5 border p-3">
|
||||
<div *ngIf="group.admin.id === currentUserId && group.groupCandidates" class="mb-5 border p-3">
|
||||
<h3>Group candidates:</h3>
|
||||
<app-group-candidates [candidates]="groupCandidates$ | async"></app-group-candidates>
|
||||
<app-group-candidates
|
||||
[candidates]="groupCandidates$ | async"
|
||||
(accept)="onCandidateAccept($event)"
|
||||
(decline)="onCandidateDecline($event)"
|
||||
></app-group-candidates>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -15,7 +15,7 @@ export class GroupEditComponent implements OnInit {
|
||||
|
||||
group$: Observable<Group>;
|
||||
groupCandidates$: Observable<User[]>;
|
||||
userId: string;
|
||||
currentUserId: string;
|
||||
groupId: number;
|
||||
|
||||
constructor(private groupService: GroupService,
|
||||
@ -24,7 +24,7 @@ export class GroupEditComponent implements OnInit {
|
||||
private router: Router) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userId = localStorage.getItem('userId');
|
||||
this.currentUserId = localStorage.getItem('userId');
|
||||
this.groupId = this.activatedRoute.snapshot.params['groupId'];
|
||||
this.group$ = this.groupService.getGroup(this.groupId);
|
||||
this.groupCandidates$ = this.groupCandidateService.getList(this.groupId);
|
||||
@ -42,4 +42,17 @@ export class GroupEditComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onCandidateAccept(userId: string) {
|
||||
this.groupCandidateService.accept(this.groupId, userId).subscribe(() => {
|
||||
this.group$ = this.groupService.getGroup(this.groupId);
|
||||
this.groupCandidates$ = this.groupCandidateService.getList(this.groupId);
|
||||
});
|
||||
}
|
||||
|
||||
onCandidateDecline(userId: string) {
|
||||
this.groupCandidateService.decline(this.groupId, userId).subscribe(() => {
|
||||
this.groupCandidates$ = this.groupCandidateService.getList(this.groupId);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-buttons d-flex align-items-center">
|
||||
<button (click)="onDeleteUser(user.id)" class="btn btn-primary">Delete</button>
|
||||
<button *ngIf="currentUserId == adminId && user.id != adminId" (click)="onDeleteUser(user.id)" class="btn btn-primary">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -9,12 +9,14 @@ import { User } from 'src/app/user/interfaces/user.interface';
|
||||
export class GroupUsersComponent implements OnInit {
|
||||
|
||||
@Input() groupUsers: User[];
|
||||
@Input() adminId: string;
|
||||
@Output() deleteUser = new EventEmitter<string>();
|
||||
currentUserId: string;
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
this.currentUserId = localStorage.getItem('userId');
|
||||
}
|
||||
|
||||
onDeleteUser(id: string): void {
|
||||
|
@ -24,7 +24,11 @@ export class GroupCandidateService {
|
||||
return this.http.post<void>(environment.host + environment.apiEndpoints.groupCandidates.joinRequest, joinRequest);
|
||||
}
|
||||
|
||||
delete(): Observable<void> {
|
||||
return this.http.delete<void>(`${environment.host}${environment.apiEndpoints.groupCandidates.delete}/${localStorage.getItem('userId')}`);
|
||||
accept(groupId: number, userId: string): Observable<void> {
|
||||
return this.http.get<void>(`${environment.host}${environment.apiEndpoints.groupCandidates.accept}/${groupId}/${userId}`);
|
||||
}
|
||||
|
||||
decline(groupId: number, userId: string): Observable<void> {
|
||||
return this.http.delete<void>(`${environment.host}${environment.apiEndpoints.groupCandidates.decline}/${groupId}/${userId}`);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ export const environment = {
|
||||
groupCandidates: {
|
||||
getList: 'api/groupCandidates/list',
|
||||
joinRequest: 'api/groupCandidates/join-request',
|
||||
delete: 'api/groupCandidates/delete'
|
||||
accept: 'api/groupCandidates/accept',
|
||||
decline: 'api/groupCandidates/decline'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user