Skip to content

Commit fec6a97

Browse files
committed
add delete collaborator from project for leader
1 parent 8477849 commit fec6a97

5 files changed

Lines changed: 90 additions & 9 deletions

File tree

projects/social_platform/src/app/office/features/info-card/info-card.component.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,25 @@
171171
</div>
172172
} }
173173
</div>
174-
} @else if (type === 'members') {
174+
} @else if (type === 'members') { @if (leaderId !== info?.userId) {
175+
<div class="card__info--program">
176+
<app-button
177+
customTypographyClass="text-body-6"
178+
size="extra-small"
179+
[disabled]="true"
180+
style="opacity: 0.5"
181+
>выдать роль</app-button
182+
>
183+
<app-button
184+
customTypographyClass="text-body-6"
185+
size="extra-small"
186+
color="red"
187+
appearance="outline"
188+
(click)="removeCollaboratorFromProject(info?.userId)"
189+
>удалить</app-button
190+
>
191+
</div>
192+
} @else {
175193
<app-button
176194
[routerLink]="'/office/profile/' + info?.userId"
177195
customTypographyClass="text-body-6"
@@ -180,7 +198,7 @@
180198
>
181199
профиль
182200
</app-button>
183-
} @else {
201+
} } @else {
184202
<div class="card__invite-actions">
185203
<app-button
186204
(click)="onAcceptInvite($event, info?.inviteId!)"

projects/social_platform/src/app/office/features/info-card/info-card.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @format */
22

3-
import { Component, EventEmitter, inject, Input, OnInit, Output } from "@angular/core";
3+
import { Component, EventEmitter, inject, Input, OnInit, Output, signal } from "@angular/core";
44
import { IndustryService } from "@services/industry.service";
55
import { IconComponent, ButtonComponent } from "@ui/components";
66
import { AvatarComponent } from "@ui/components/avatar/avatar.component";
@@ -34,7 +34,7 @@ import { YearsFromBirthdayPipe } from "@corelib";
3434
RouterLink,
3535
],
3636
})
37-
export class InfoCardComponent implements OnInit {
37+
export class InfoCardComponent {
3838
private readonly inviteService = inject(InviteService);
3939
private readonly subscriptionService = inject(SubscriptionService);
4040
public readonly industryService = inject(IndustryService);
@@ -47,10 +47,13 @@ export class InfoCardComponent implements OnInit {
4747
@Input() canDelete?: boolean | null = false;
4848
@Input() isSubscribed?: boolean | null = false;
4949
@Input() profileId?: number;
50+
@Input() leaderId?: number;
51+
@Input() loggedUserId?: number;
5052

5153
@Output() onAcceptingInvite = new EventEmitter<number>();
5254
@Output() onRejectingInvite = new EventEmitter<number>();
5355
@Output() onCreate = new EventEmitter<void>();
56+
@Output() onRemoveCollaborator = new EventEmitter<number>();
5457

5558
// Состояние компонента
5659
isUnsubscribeModalOpen = false;
@@ -61,7 +64,9 @@ export class InfoCardComponent implements OnInit {
6164
iconHovered = false;
6265
draftProjectHovered = false;
6366

64-
ngOnInit(): void {}
67+
removeCollaboratorFromProject(userId: number): void {
68+
this.onRemoveCollaborator.emit(userId);
69+
}
6570

6671
/**
6772
* Определяет, нужно ли показывать информацию о проекте

projects/social_platform/src/app/office/projects/detail/services/project-data.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ export class ProjectDataService {
2828
filter(vacancies => !!vacancies)
2929
);
3030
}
31+
32+
getProjectLeaderId() {
33+
return this.project$.pipe(map(project => project?.leader));
34+
}
35+
36+
getProjectId() {
37+
return this.project$.pipe(map(project => project?.id));
38+
}
3139
}

projects/social_platform/src/app/office/projects/detail/team/team.component.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
@if(team) { @if (team.length) {
44
<div class="project__team">
55
@for (collaborator of team; track $index) {
6-
<app-info-card [info]="collaborator" type="members"></app-info-card>
6+
<app-info-card
7+
[leaderId]="leaderId()"
8+
[loggedUserId]="loggedUserId()"
9+
[info]="collaborator"
10+
type="members"
11+
(onRemoveCollaborator)="removeCollaboratorFromProject($event)"
12+
></app-info-card>
713
}
814
</div>
915
} }

projects/social_platform/src/app/office/projects/detail/team/team.component.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/** @format */
22

33
import { CommonModule } from "@angular/common";
4-
import { Component, inject, OnDestroy, OnInit } from "@angular/core";
4+
import { Component, inject, OnDestroy, OnInit, signal } from "@angular/core";
55
import { IconComponent } from "@uilib";
66
import { ProjectDataService } from "../services/project-data.service";
77
import { InfoCardComponent } from "@office/features/info-card/info-card.component";
88
import { Subscription } from "rxjs";
99
import { Project } from "@office/models/project.model";
10+
import { ProjectService } from "@office/services/project.service";
11+
import { AuthService } from "@auth/services";
1012

1113
/**
1214
* Компонент страницы команды в деательной информации о проекте
@@ -19,11 +21,15 @@ import { Project } from "@office/models/project.model";
1921
standalone: true,
2022
})
2123
export class ProjectTeamComponent implements OnInit, OnDestroy {
22-
// сервис для работы с данными детальной информации проекта
2324
private readonly projectDataService = inject(ProjectDataService);
25+
private readonly projectService = inject(ProjectService);
26+
private readonly authService = inject(AuthService);
2427

2528
// массив пользователей в команде
2629
team?: Project["collaborators"];
30+
projectId = signal<number>(0);
31+
loggedUserId = signal<number>(0);
32+
leaderId = signal<number>(0);
2733

2834
// массив подписок
2935
subscriptions: Subscription[] = [];
@@ -37,10 +43,48 @@ export class ProjectTeamComponent implements OnInit, OnDestroy {
3743
});
3844

3945
teamSub$ && this.subscriptions.push(teamSub$);
46+
47+
const projectId$ = this.projectDataService.getProjectId().subscribe({
48+
next: projectId => {
49+
if (projectId) {
50+
this.projectId.set(projectId);
51+
}
52+
},
53+
});
54+
55+
if (location.href.includes("/team")) {
56+
const leaderId$ = this.projectDataService.getProjectLeaderId().subscribe({
57+
next: leaderId => {
58+
if (leaderId) {
59+
this.leaderId.set(leaderId);
60+
}
61+
},
62+
});
63+
64+
const currentProfileId$ = this.authService.profile.subscribe({
65+
next: profile => {
66+
if (profile) {
67+
this.loggedUserId.set(profile.id);
68+
}
69+
},
70+
});
71+
72+
this.subscriptions.push(leaderId$, currentProfileId$);
73+
}
74+
75+
this.subscriptions.push(projectId$);
4076
}
4177

4278
ngOnDestroy(): void {
43-
// отписка от поток, которые не нужны
4479
this.subscriptions.forEach($ => $.unsubscribe());
4580
}
81+
82+
removeCollaboratorFromProject(userId: number): void {
83+
const index = this.team?.findIndex(p => p.userId === userId);
84+
if (index !== -1) {
85+
this.team?.splice(index!, 1);
86+
}
87+
88+
this.projectService.removeColloborator(this.projectId(), userId).subscribe();
89+
}
4690
}

0 commit comments

Comments
 (0)