Skip to content

Commit

Permalink
feat update code for onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Jan 9, 2024
1 parent 7f55743 commit af82a13
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/app/pages/auth/login/login.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class LoginPage implements OnInit {
message = await lastValueFrom(
this.translate.get("login.error__network_connection")
);
} else if (err.code == "auth/invalid-login-credentials") {
message = await lastValueFrom(
this.translate.get("login.error__invalid-login-credentials")
);

} else {
console.log("Error");
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/club/club.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
color="primary"
name="help-circle-outline"
></ion-icon>
<ion-label class="ion-text-wrap" (click)="openMember(request)"
<ion-label class="ion-text-wrap" (click)="openRequestMember(request)"
>{{request.firstName}} {{request.lastName}} {{request?.email}}
</ion-label>
</ion-item>
Expand Down
26 changes: 24 additions & 2 deletions src/app/pages/club/club.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,29 @@ export class ClubPage implements OnInit {
if (role === "confirm") {
}
}
async approveClubRequest(user) {

async openRequestMember(member: Profile) {
console.log("open Request Member");
const modal = await this.modalCtrl.create({
component: MemberPage,
presentingElement: await this.modalCtrl.getTop(),
canDismiss: true,
showBackdrop: true,
componentProps: {
data: member,
isRequest: true,
clubId: this.club.id
},
});
modal.present();

const { data, role } = await modal.onWillDismiss();

if (role === "confirm") {
}
}

/*async approveClubRequest(user) {
console.log(user);
const alert = await this.alertCtrl.create({
message: (
Expand Down Expand Up @@ -361,7 +383,7 @@ export class ClubPage implements OnInit {
console.log(user);
await this.fbService.deleteUserClubRequest(user.clubId, user.id);
await this.toastActionSaved();
}
}*/

async toastActionSaved() {
const toast = await this.toastCtrl.create({
Expand Down
19 changes: 18 additions & 1 deletion src/app/pages/member/member.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ion-label> {{"profile.generally" | translate}} </ion-label>
</ion-list-header>

<ion-item>
<ion-item *ngIf="!isRequest">
<ion-avatar slot="start">
<img
alt="{{userProfile.firstName}}"
Expand Down Expand Up @@ -64,7 +64,24 @@
</ion-input>
</ion-item>
</ion-list>


<ng-container *ngIf="isRequest">

<ion-button expand="block" shape="round" color="success" (click)="approveClubRequest(userProfile)">
Approve Request
</ion-button>

<ion-button expand="block" shape="round" color="danger" (click)="deleteClubRequest(userProfile)">
Delete Request
</ion-button>

</ng-container>



</ng-container>

</ion-content>

<ng-template #loading>
Expand Down
174 changes: 171 additions & 3 deletions src/app/pages/member/member.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { Component, Input, OnInit } from "@angular/core";
import { ModalController, NavParams } from "@ionic/angular";
import { Observable, of } from "rxjs";
import { AlertController, ModalController, NavParams, ToastController } from "@ionic/angular";
import { TranslateService } from "@ngx-translate/core";
import {
Observable,
Subscription,
catchError,
combineLatest,
finalize,
first,
forkJoin,
lastValueFrom,
map,
of,
startWith,
switchMap,
take,
tap,
} from "rxjs";
import { Team } from "src/app/models/team";
import { Profile } from "src/app/models/user";
import { FirebaseService } from "src/app/services/firebase.service";
import { UserProfileService } from "src/app/services/firebase/user-profile.service";

@Component({
Expand All @@ -11,18 +29,47 @@ import { UserProfileService } from "src/app/services/firebase/user-profile.servi
})
export class MemberPage implements OnInit {
@Input("data") userProfile: Profile;
@Input("isRequest") isRequest: boolean;
@Input("clubId") clubId: string;
userProfile$: Observable<Profile>;
skeleton = new Array(12);

teamAdminList$: Observable<Team[]>;

alertTeamSelection = [];

constructor(
private readonly modalCtrl: ModalController,
private readonly alertCtrl: AlertController,
private readonly toastCtrl: ToastController,
private readonly profileService: UserProfileService,
private navParams: NavParams
private readonly fbService: FirebaseService,
private navParams: NavParams,
private translate: TranslateService
) {}

ngOnInit() {
this.isRequest = this.navParams.get("isRequest");
this.clubId = this.navParams.get("clubId");
this.userProfile = this.navParams.get("data");
this.userProfile$ = of(this.userProfile);
this.userProfile$ = this.getUserProfile(this.userProfile.id);

this.teamAdminList$ = this.fbService.getTeamAdminList();
this.teamAdminList$.forEach((teamList) => {
for (const team of teamList) {
this.alertTeamSelection.push(
{
label: team.name,
type: 'checkbox',
value: team.id,
checked: false
}
)
}
return teamList;
});

}

getUserProfile(id) {
Expand All @@ -43,4 +90,125 @@ export class MemberPage implements OnInit {
},
});*/
}

async approveClubRequest(user) {
console.log(user);
const alert = await this.alertCtrl.create({
message: (
(await lastValueFrom(
this.translate.get("club.want_to_add__user__to_club_string")
)) ?? ""
).replace("{userName}", `${user.firstName} ${user.lastName}`),
subHeader: "",
buttons: [
{
text: await lastValueFrom(this.translate.get("common.yes")),
role: "confirm",
},
{
text: await lastValueFrom(this.translate.get("common.cancel")),
role: "cancel",
},
],
htmlAttributes: { "aria-label": "alert dialog" },
});
await alert.present();
const { role, data } = await alert.onDidDismiss();

if (role == "confirm") {
await this.fbService.approveUserClubRequest(this.clubId, user.id);
const toast = await this.toastCtrl.create({
message: await lastValueFrom(
this.translate.get("club.success__user_added")
),
color: "primary",
duration: 1500,
position: "bottom",
});
await toast.present();

await this.assignTeamAlert(user);
} else {
await this.toastActionCanceled();
}
}

async assignTeamAlert(user) {
console.log(user);
const alert = await this.alertCtrl.create({
header: await lastValueFrom(this.translate.get("club.select__team")),
message: (
(await lastValueFrom(
this.translate.get("club.want_to_add__user__to_team_string")
)) ?? ""
).replace("{userName}", `${user.firstName} ${user.lastName}`),
inputs: this.alertTeamSelection,
buttons: [
{
text: await lastValueFrom(this.translate.get("club.add")),
role: "confirm",
},
{
text: await lastValueFrom(this.translate.get("common.cancel")),
role: "cancel",
},
],
htmlAttributes: { "aria-label": "alert dialog selcting teams" },
});
await alert.present();
const { role, data } = await alert.onDidDismiss();
console.log(data);

if (role == "confirm") {
for (const teamId of data.values) {
await this.fbService.approveUserTeamRequest(teamId, user.id);
}
const toast = await this.toastCtrl.create({
message: (
(await lastValueFrom(
this.translate.get("club.success__added_user_to_team_string")
)) ?? ""
)
.replace("{userName}", `${user.firstName} ${user.lastName}`)
.replace("length", `${data.values.length}`),
color: "primary",
duration: 1500,
position: "bottom",
});
await toast.present();
} else {
await this.toastActionCanceled();
}
}

async deleteClubRequest(user) {
console.log(user);
await this.fbService.deleteUserClubRequest(this.clubId, user.id);
await this.toastActionSaved();
this.close();
}

async toastActionSaved() {
const toast = await this.toastCtrl.create({
message: await lastValueFrom(this.translate.get("common.success__saved")),
duration: 1500,
position: "bottom",
color: "success",
});

await toast.present();
}

async toastActionCanceled() {
const toast = await this.toastCtrl.create({
message: await lastValueFrom(this.translate.get("club.action__canceled")),
duration: 1500,
position: "bottom",
color: "danger",
});
await toast.present();
}



}
41 changes: 38 additions & 3 deletions src/app/pages/onboarding/onboarding.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,17 @@ export class OnboardingPage implements OnInit {
{
text: await lastValueFrom(this.translate.get("common.yes")),
handler: async (data: any) => {
await this.fbService.setClubRequest(club.id, this.user.uid);
await this.presentRequestToast();
await this.presentRequestSentAlert(club.name);
try {
await this.fbService.setClubRequest(club.id, this.user.uid)
await this.presentRequestToast();
await this.presentRequestSentAlert(club.name);
} catch (err) {
console.log(err.message);
if (err.message === "Missing or insufficient permissions.") {
this.presentErrorAlert();
}
}


// await this.router.navigateByUrl("logout", {});
},
Expand Down Expand Up @@ -340,6 +348,33 @@ export class OnboardingPage implements OnInit {
console.log("onDidDismiss resolved with role", role);
}

async presentErrorAlert() {
const alert = await this.alertController.create({
cssClass: "my-custom-class",
header: await lastValueFrom(
this.translate.get("onboarding.error__clubRequest")
),
subHeader: "",
message: await lastValueFrom(
this.translate.get("onboarding.error__clubRequest_desc")
),
buttons: [
{
text: await lastValueFrom(this.translate.get("common.ok")),
handler: async () => {
},
},
],
});

await alert.present();

const { role } = await alert.onDidDismiss();
console.log("onDidDismiss resolved with role", role);
}



/*
async scanCode () {
const image: any = await this.takePicture();
Expand Down
1 change: 1 addition & 0 deletions src/app/services/firebase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export class FirebaseService {
}

approveUserClubRequest(clubId: string, userId: string): Promise<any> {
console.log("club " + clubId , " / userid " + userId);
return setDoc(
doc(this.firestore, `/club/${clubId}/requests/${userId}`),
{
Expand Down

0 comments on commit af82a13

Please sign in to comment.