Skip to content

Commit

Permalink
feat update member admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Jan 10, 2024
1 parent 89f500c commit 1bd7c5a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 97 deletions.
8 changes: 8 additions & 0 deletions src/app/pages/club/club.page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<ng-container *ngIf="club$ | async as club">
<ion-header [translucent]="true">
<ion-toolbar>
<ion-buttons slot="secondary">
<ion-button *ngIf="!allowEdit" (click)="edit()"
>{{"common.edit" | translate}}</ion-button
>
<ion-button *ngIf="allowEdit" (click)="edit()"
>{{"common.cancel" | translate}}</ion-button
>
</ion-buttons>
<ion-title>{{club?.name}}</ion-title>
<ion-buttons slot="primary">
<ion-button (click)="close()"
Expand Down
10 changes: 10 additions & 0 deletions src/app/pages/club/club.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class ClubPage implements OnInit {

alertTeamSelection = [];

allowEdit: boolean = false;


constructor(
private readonly modalCtrl: ModalController,
public navParams: NavParams,
Expand All @@ -69,6 +72,13 @@ export class ClubPage implements OnInit {
this.subscribeMember.unsubscribe();
}
}
edit() {
if (this.allowEdit) {
this.allowEdit = false;
} else {
this.allowEdit = true;
}
}

getClub(clubId: string) {
const calculateAge = (dateOfBirth) => {
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/member/member.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class MemberPage implements OnInit {
position: "bottom",
});
await toast.present();
this.close();
} else {
await this.toastActionCanceled();
}
Expand Down
12 changes: 0 additions & 12 deletions src/app/pages/team-list/team-list.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,10 @@ export class TeamListPage implements OnInit {

ngOnInit() {
this.teamList$ = this.fbService.getTeamList();
/*this.teamList$.subscribe({
next: (data) => {
console.log("ClubList Data received");
this.cdr.detectChanges();
},
error: (err) => console.error("ClubList Error in subscription:", err),
complete: () => console.log("ClubList Observable completed"),
});*/
}

ngOnDestroy() {}

getAvailableTeamList() {
// console.log("getAvailableTeamList");
}

async openModal(team: Team) {
// const presentingElement = await this.modalCtrl.getTop();
const modal = await this.modalCtrl.create({
Expand Down
5 changes: 2 additions & 3 deletions src/app/pages/team/team-detail/team.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
</ion-item>
</ion-list>

<ion-list [inset]="true" *ngIf="team['teamRequests'].length > 0">
<!-- <ion-list [inset]="true" *ngIf="team['teamRequests'].length > 0">
<ion-list-header>
<ion-label> {{"common.requests" | translate}} </ion-label>

</ion-list-header>
<ion-item *ngFor="let request of team['teamRequests']" detail="true">
<ion-avatar slot="start">
Expand All @@ -50,7 +49,7 @@
>
<ion-label> {{request?.email}} </ion-label>
</ion-item>
</ion-list>
</ion-list>-->

<ion-list [inset]="true">
<ion-list-header>
Expand Down
156 changes: 75 additions & 81 deletions src/app/pages/team/team-detail/team.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class TeamPage implements OnInit {

team$: Observable<any>;
subscribeMember: Subscription;
subscribeAdmin: Subscription;

user$: Observable<User>;
user: User;
Expand All @@ -69,28 +70,22 @@ export class TeamPage implements OnInit {
private readonly authService: AuthService,
private cdr: ChangeDetectorRef,
private translate: TranslateService
) {}
) { }

ngOnInit() {
this.team = this.navParams.get("data");
this.team$ = of(this.team);

this.team$ = this.getTeam(this.team.id);
/*this.team$.subscribe({
next: (data) => {
console.log(">> Tean Data");
console.log(data);
this.cdr.detectChanges();
},
error: (err) => console.error("Team Error in subscription:", err),
complete: () => console.log("team Observable completed"),
});*/
}

ngOnDestroy() {
if (this.subscribeMember) {
this.subscribeMember.unsubscribe();
}
if (this.subscribeAdmin) {
this.subscribeAdmin.unsubscribe();
}
}

getTeam(teamId: string) {
Expand Down Expand Up @@ -190,8 +185,12 @@ export class TeamPage implements OnInit {
}

async removeAdmin(admin) {
await this.fbService.deleteTeamAdmin(this.team.id, admin.id);
await this.toastActionSaved();
await this.fbService.deleteTeamAdmin(this.team.id, admin.id).then(() => {
this.toastActionSaved();
})
.catch((err) => {
this.toastActionError(err);
});
}

async removeMember(member) {
Expand All @@ -205,16 +204,16 @@ export class TeamPage implements OnInit {
});
}

/* async deleteTeamRequest(request) {
await this.fbService.deleteUserTeamRequest(request.teamId, request.id);
await this.toastActionSaved();
} */

async approveTeamRequest(request) {
console.log(request);
await this.fbService.approveUserTeamRequest(request.teamId, request.id);
await this.toastActionSaved();
await this.fbService.approveUserTeamRequest(request.teamId, request.id).then(() => {
this.toastActionSaved();
})
.catch((err) => {
this.toastActionError(err);
});
}

async openMember(member: Profile) {
console.log("openMember");
const modal = await this.modalCtrl.create({
Expand All @@ -234,85 +233,80 @@ export class TeamPage implements OnInit {
}
}
addMember() {
let memberSelect = [];
this.team$.forEach(async (team) => {
console.log(team);
this.subscribeMember = this.fbService
.getTeamRef(this.team.id)
.pipe(
take(1),
tap((team: any) => {
console.log(team.clubRef.id);
}),
switchMap((team: any) => {
if (!team) return of([]);
return this.fbService.getClubMemberRefs(team.clubRef.id);
}),
switchMap((members) => {
this.team$.pipe(
take(1), // Take only the first emission
tap(team => console.log('Team:', team)),
switchMap(team => {
// If team does not exist or there are no team members, complete the stream
if (!team || !team.clubRef || !team.clubRef.id) return of(null);

// Fetch club members
return this.fbService.getClubMemberRefs(team.clubRef.id).pipe(
switchMap(members => {
if (!members.length) return of([]);

// Fetch each member's user profile
const memberDetails$ = members.map((member) =>
const memberDetails$ = members.map(member =>
this.userProfileService.getUserProfileById(member.id).pipe(
take(1),
catchError(() =>
of({ ...member, firstName: "Unknown", lastName: "Unknown" })
of({ ...member, firstName: 'Unknown', lastName: 'Unknown' })
)
)
);

return combineLatest(memberDetails$);
}),
map((memberProfiles) =>
memberProfiles.filter((member) => member !== undefined)
)
)
.subscribe(async (memberDetails) => {
console.log("Club Members:", memberDetails);
// Handle the fetched member details
for (let member of memberDetails) {
if (!team.teamMembers.find((element) => element.id == member.id)) {
memberSelect.push({
type: "checkbox",
name: member.id,
label: member.firstName + " " + member.lastName,
value: member,
checked: false,
});
}
}
const alert = await this.alertCtrl.create({
header: "Administrator hinzufügen",
inputs: memberSelect,
buttons: [
{
text: "Abbrechen",
handler: () => {
console.log("Cancel clicked");
},
},
{
text: "Hinzufügen",
handler: (teamMemberList) => {
console.log(teamMemberList);
for (const member of teamMemberList) {
this.approveTeamRequest({teamId: this.team.id, id: member.id})
}
},
map(memberProfiles =>
memberProfiles.filter(member => member !== undefined)
),
map(memberProfiles => memberProfiles.filter(member =>
!team.teamMembers.find(element => element.id === member.id)
)),
map(filteredMembers => filteredMembers.map(member => ({
type: 'checkbox',
name: member.id,
label: `${member.firstName} ${member.lastName}`,
value: member,
checked: false,
})))
);
}),
catchError(err => {
console.error('Error in addMember:', err);
return of(null);
})
).subscribe(async (memberSelect:any) => {
if (memberSelect && memberSelect.length > 0) {
const alert = await this.alertCtrl.create({
header: 'Administrator hinzufügen',
inputs: memberSelect,
buttons: [
{
text: 'Abbrechen',
handler: () => console.log('Cancel clicked'),
},
{
text: 'Hinzufügen',
handler: (teamMemberList) => {
console.log(teamMemberList);
for (const member of teamMemberList) {
this.approveTeamRequest({ teamId: this.team.id, id: member.id });
}
},
],
});
if (memberSelect.length > 0) {
await alert.present();
}
},
],
});
await alert.present();
}
});
}


async addAdministrator() {
let memberSelect = [];

this.subscribeMember = this.team$
this.subscribeAdmin = this.team$
.pipe(
take(1),
tap((team) => {
Expand Down Expand Up @@ -346,7 +340,7 @@ export class TeamPage implements OnInit {
],
});
await alert.present();
}else{
} else {
alert("no members")
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/app/services/firebase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class FirebaseService {
);
}
async approveUserTeamRequest(teamId: string, userId: string): Promise<any> {
// trigger create event on backend -> not handled
// trigger create event on backend -> not handled, because no status field for approve
await setDoc(
doc(this.firestore, `teams/${teamId}/requests/${userId}`),
{},
Expand All @@ -339,6 +339,7 @@ export class FirebaseService {
}
);
// then trigger update event on backend --> handled
// --> only "modify" event is handled
return setDoc(
doc(this.firestore, `teams/${teamId}/requests/${userId}`),
{
Expand Down

0 comments on commit 1bd7c5a

Please sign in to comment.