Skip to content

Commit 6a41318

Browse files
committed
add logic of getting leader projects & modals for errors
1 parent 12cf11f commit 6a41318

3 files changed

Lines changed: 77 additions & 6 deletions

File tree

projects/social_platform/src/app/auth/services/auth.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
RegisterResponse,
1212
} from "../models/http.model";
1313
import { User, UserRole } from "../models/user.model";
14+
import { Project } from "@office/models/project.model";
15+
import { ApiPagination } from "@office/models/api-pagination.model";
1416

1517
/**
1618
* Сервис аутентификации и управления пользователями
@@ -123,6 +125,14 @@ export class AuthService {
123125
);
124126
}
125127

128+
/**
129+
* Получить проекты где пользователь leader
130+
* @returns Observable проектов внутри профиля
131+
*/
132+
getLeaderProjects(): Observable<ApiPagination<Project>> {
133+
return this.apiService.get(`${this.AUTH_USERS_URL}/projects/leader/`);
134+
}
135+
126136
/**
127137
* Получить роли, которые может изменить текущий пользователь
128138
* @returns Observable с массивом изменяемых ролей

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ <h3 class="text-body-12 lists__title">выберите проект и роль
538538
<div class="project__item--info">
539539
<app-avatar [url]="project.imageAddress" [size]="40"></app-avatar>
540540
<p class="text-body-12">
541-
{{ project.name | truncate: 20 }}
541+
{{ project.name ?? "Проект без названия" | truncate: 20 }}
542542
</p>
543543
</div>
544544
<app-input
@@ -601,6 +601,53 @@ <h3 class="text-body-12 lists__title">выберите проект и роль
601601
</div>
602602
</app-modal>
603603

604+
<app-modal
605+
[open]="showActiveInviteModal"
606+
(openChange)="showActiveInviteModal = !showActiveInviteModal"
607+
>
608+
<div class="cancel" style="padding: 0px; width: 300px">
609+
<div class="cancel__top">
610+
<p class="cancel__title text-body-14">
611+
У данного участника уже есть активное приглашение в проект
612+
</p>
613+
</div>
614+
615+
<i appIcon icon="straight-face" appSquare="50" style="margin: 36px 0px"></i>
616+
617+
<app-button
618+
style="width: 100%"
619+
customTypographyClass="text-body-12"
620+
size="big"
621+
(click)="routingToMyProjects()"
622+
>перейти в проекты</app-button
623+
>
624+
</div>
625+
</app-modal>
626+
627+
<app-modal
628+
[open]="showNoInProgramModal"
629+
(openChange)="showNoInProgramModal = !showNoInProgramModal"
630+
>
631+
<div class="cancel" style="padding: 0px; width: 300px">
632+
<div class="cancel__top">
633+
<p class="cancel__title text-body-14">
634+
Пользователь не зарегистрирован в программе, поэтому нельзя отправить приглашение
635+
в данный проект
636+
</p>
637+
</div>
638+
639+
<i appIcon icon="sad-smile" appSquare="50" style="margin: 36px 0px"></i>
640+
641+
<app-button
642+
style="width: 100%"
643+
customTypographyClass="text-body-12"
644+
size="big"
645+
(click)="routingToMyProjects()"
646+
>перейти в проекты</app-button
647+
>
648+
</div>
649+
</app-modal>
650+
604651
<app-modal
605652
[open]="showSuccessInviteModal"
606653
(openChange)="showSuccessInviteModal = !showSuccessInviteModal"

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ActivatedRoute, Router, RouterModule } from "@angular/router";
99
import { AuthService } from "@auth/services";
1010
import { AvatarComponent } from "@ui/components/avatar/avatar.component";
1111
import { TooltipComponent } from "@ui/components/tooltip/tooltip.component";
12-
import { concatMap, filter, map, of, Subscription, tap } from "rxjs";
12+
import { concatMap, EMPTY, filter, map, Observable, of, Subscription, tap } from "rxjs";
1313
import { User } from "@auth/models/user.model";
1414
import { Collaborator } from "@office/models/collaborator.model";
1515
import { ProjectService } from "@office/services/project.service";
@@ -35,6 +35,7 @@ import { TruncatePipe } from "projects/core/src/lib/pipes/truncate.pipe";
3535
import { ControlErrorPipe, ValidationService } from "@corelib";
3636
import { ErrorMessage } from "@error/models/error-message";
3737
import { InviteService } from "@office/services/invite.service";
38+
import { ApiPagination } from "@office/models/api-pagination.model";
3839

3940
@Component({
4041
selector: "app-detail",
@@ -134,6 +135,8 @@ export class DeatilComponent implements OnInit, OnDestroy {
134135
showApproveSkillModal = false;
135136
showSendInviteModal = false;
136137
showNoProjectsModal = false;
138+
showActiveInviteModal = false;
139+
showNoInProgramModal = false;
137140
showSuccessInviteModal = false;
138141
readAllModal = false;
139142

@@ -400,9 +403,17 @@ export class DeatilComponent implements OnInit, OnDestroy {
400403
next: () => {
401404
this.showSendInviteModal = false;
402405
this.showSuccessInviteModal = true;
406+
403407
this.inviteForm.reset();
404408
this.selectedProjectId = null;
405409
},
410+
error: err => {
411+
if (err.error.user[0].includes("проект относится к программе")) {
412+
this.showNoInProgramModal = true;
413+
} else if (err.error.user[0].includes("активное приглашение")) {
414+
this.showActiveInviteModal = true;
415+
}
416+
},
406417
});
407418
}
408419

@@ -537,17 +548,20 @@ export class DeatilComponent implements OnInit, OnDestroy {
537548

538549
this.isInProfileInfo();
539550

540-
this.subscriptions.push(profileDataSub$);
551+
const profileLeaderProjectsSub$ = this.authService.getLeaderProjects().subscribe({
552+
next: (projects: ApiPagination<Project>) => {
553+
this.profileProjects.set(projects.results);
554+
},
555+
});
556+
557+
this.subscriptions.push(profileDataSub$, profileLeaderProjectsSub$);
541558
}
542559
}
543560

544561
private isInProfileInfo(): void {
545562
const profileInfoSub$ = this.authService.profile.subscribe({
546563
next: profile => {
547564
this.profile = profile;
548-
this.profileProjects.set(
549-
this.profile?.projects.filter(project => project.leader === this.profile?.id)
550-
);
551565

552566
if (this.info() && this.listType === "project") {
553567
this.isInProject = this.info()

0 commit comments

Comments
 (0)