Skip to content

Commit

Permalink
Merge pull request #335 from CapsLuky/develop
Browse files Browse the repository at this point in the history
Melhorias para exibir o doador
  • Loading branch information
wantero authored May 4, 2021
2 parents a011f19 + d5c53d9 commit adf41c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
26 changes: 9 additions & 17 deletions src/app/components/book/donor-modal/donor-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,24 @@ <h4 class="modal-title">Informações do doador do livro: <br> {{ bookTitle }}</

<div class="modal-body">

<ng-template #loading>
<div class="text-center"><em class="fa fa-spinner fa-spin"></em> Aguarde...</div>
</ng-template>
<section class="card-body">

<section class="card-body" *ngIf="(userInfo$ | async)?.donor as donor; else loading">
<div [hidden]="!loading">
<div class="text-center"><em class="fa fa-spinner fa-spin"></em> Aguarde...</div>
</div>

<ng-container *ngIf="showDonor; else showDonorNotAlowed">
<ng-container *ngIf="messageBody !== ''">
<h5 class="card-title">{{messageBody}}</h5>
</ng-container>

<ng-container *ngIf="(userInfo$ | async)?.donor as donor">
<h5 class="card-title">Doador</h5>
<p class="card-text">Nome: {{ donor.name }}</p>
<p class="card-text">E-mail: {{ donor.email }}</p>
<p class="card-text">LinkedIn: {{ donor.linkedin }}</p>
<p class="card-text">Telefone: {{ donor.phone }}</p>
<p class="card-text">
{{ donor.address?.street }}, {{ donor.address?.number }}
{{ !!donor.address?.complement ? donor.address?.complement : '' }}
</p>
<p class="card-text">
{{ donor.address?.neighborhood }} - {{ donor.address?.city }} - {{ donor.address?.state }}
</p>
<p class="card-text">CEP: {{ donor.address?.postalCode }} - {{ donor.address?.country }}</p>
</ng-container>

<ng-template #showDonorNotAlowed>
<h5 class="card-title">Informações disponível apenas para o ganhador do livro</h5>
</ng-template>

</section>
</div>

Expand Down
33 changes: 14 additions & 19 deletions src/app/components/book/donor-modal/donor-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { BookService } from 'src/app/core/services/book/book.service';
import { UserInfoBook } from 'src/app/core/models/UserInfoBook';
import { User } from 'src/app/core/models/user';
import { UserService } from 'src/app/core/services/user/user.service';

@Component({
selector: 'app-donor-modal',
Expand All @@ -17,33 +15,30 @@ import { UserService } from 'src/app/core/services/user/user.service';
export class DonorModalComponent implements OnInit {
@Input() bookId;
@Input() bookTitle;
@Input() messageBody;
loading: boolean;

showDonor = false;
userInfo$: Observable<UserInfoBook>;

constructor(public activeModal: NgbActiveModal,
private readonly _bookService: BookService,
private readonly _userService: UserService) { }
private readonly _bookService: BookService) { }

ngOnInit() {
this.userInfo$ = this._bookService.getMainUsers(this.bookId).pipe(
map(userInfo => {
this.loading = true;
if (this.messageBody === '') {
this.getDonor();
} else {
this.loading = false;
}
}

const loggedUser = this.getLoggedUser();
if (loggedUser.email === userInfo.winner.email) {
this.showDonor = true;
}
private getDonor() {

this.userInfo$ = this._bookService.getMainUsers(this.bookId).pipe(
map(userInfo => {
this.loading = false;
return userInfo;
})
);
}

private getLoggedUser(): User {
let loggedUser = new User();
if (this._userService.getLoggedUserFromLocalStorage()) {
loggedUser = this._userService.getLoggedUserFromLocalStorage();
}
return loggedUser;
}
}
9 changes: 5 additions & 4 deletions src/app/components/book/requesteds/requesteds.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DonorModalComponent } from '../donor-modal/donor-modal.component';
export class RequestedsComponent implements OnInit, OnDestroy {
requestedBooks$: Observable<MyRequest>;
tableSettings: any;
private _messageToModalBody: string;

private _destroySubscribes$ = new Subject<void>();

Expand Down Expand Up @@ -106,15 +107,14 @@ export class RequestedsComponent implements OnInit, OnDestroy {
}

onCustomActionColum(event) {
this._messageToModalBody = '';

if (event.data.statusCode === BookRequestStatus.AWAITING_ACTION) {
alert('Por favor aguarde a decisão do doador.');
return;
this._messageToModalBody = 'Por favor aguarde a decisão do doador.';
}

if (event.data.statusCode === BookRequestStatus.REFUSED) {
alert('Você não é o ganhador desse livro. =/');
return;
this._messageToModalBody = 'Você não é o ganhador desse livro. =/';
}

const modalRef = this._modalService.open(DonorModalComponent, {
Expand All @@ -124,6 +124,7 @@ export class RequestedsComponent implements OnInit, OnDestroy {

modalRef.componentInstance.bookId = event.data.bookId;
modalRef.componentInstance.bookTitle = event.data.title;
modalRef.componentInstance.messageBody = this._messageToModalBody;
}

ngOnDestroy() {
Expand Down

0 comments on commit adf41c8

Please sign in to comment.