Skip to content

Commit

Permalink
Merge pull request #336 from SharebookBR/develop
Browse files Browse the repository at this point in the history
Dev to release
  • Loading branch information
raffacabofrio authored May 5, 2021
2 parents 039ad8f + adf41c8 commit ab368f7
Show file tree
Hide file tree
Showing 37 changed files with 1,013 additions and 324 deletions.
73 changes: 41 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ import { RequestComponent } from './components/book/request/request.component';
import { TrackingComponent } from './components/book/tracking/tracking.component';
import { FacilitatorNotesComponent } from './components/book/facilitator-notes/facilitator-notes.component';
import { MainUsersComponent } from './components/book/main-users/main-users.component';
import { WinnerUsersComponent } from './components/book/winner-users/winner-users.component';
import { ConfirmationDialogComponent } from './core/directives/confirmation-dialog/confirmation-dialog.component';
import { ConfirmationDialogService } from './core/services/confirmation-dialog/confirmation-dialog.service';

import { RouteReuseStrategy } from '@angular/router';
import { CustomReuseStrategy } from './core/router/custom-reuse-strategy';
import { InputSearchModule } from './components/input-search/input-search.module';
import { DonatePageComponent } from './components/book/donate-page/donate-page.component';
import { TermsOfUseComponent } from './components/terms-of-use/terms-of-use.component';
import { DonorModalComponent } from './components/book/donor-modal/donor-modal.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -100,8 +103,11 @@ import { DonatePageComponent } from './components/book/donate-page/donate-page.c
TrackingComponent,
FacilitatorNotesComponent,
MainUsersComponent,
WinnerUsersComponent,
PrivacyPolicyComponent,
CookieConsentComponent,
TermsOfUseComponent,
DonorModalComponent,
],
imports: [
BrowserModule,
Expand Down Expand Up @@ -152,9 +158,11 @@ import { DonatePageComponent } from './components/book/donate-page/donate-page.c
TrackingComponent,
FacilitatorNotesComponent,
MainUsersComponent,
WinnerUsersComponent,
DonorModalComponent
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(protected _googleAnalyticsService: GoogleAnalyticsService) {} // <-- We inject the service here to keep it alive whole time
constructor(protected _googleAnalyticsService: GoogleAnalyticsService) { } // <-- We inject the service here to keep it alive whole time
}
12 changes: 7 additions & 5 deletions src/app/components/book/details/details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ export class DetailsComponent implements OnInit, OnDestroy {

const chooseDate = Math.floor(
new Date(this.bookInfo.chooseDate).getTime() /
(3600 * 24 * 1000)
(3600 * 24 * 1000)
);
const todayDate = Math.floor(
new Date().getTime() / (3600 * 24 * 1000)
);

this.daysToChoose = chooseDate - todayDate;
this.chooseDateInfo =
!this.daysToChoose || this.daysToChoose <= 0
? 'Hoje'
: 'Daqui a ' + this.daysToChoose + ' dia(s)';
const daysLeftMessage = (this.daysToChoose && this.daysToChoose > 1)
? 'Daqui a ' + this.daysToChoose + ' dias'
: 'Daqui a 1 dia';
const isToday = (!this.daysToChoose || this.daysToChoose <= 0);
this.chooseDateInfo = isToday ? 'Hoje' : daysLeftMessage;


if (this.myUser.name) {
switch (book.freightOption) {
Expand Down
11 changes: 10 additions & 1 deletion src/app/components/book/donate-page/donate-page.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<div class="container">
<h1 class="text-center display-4">
Doar Livro
Lista de interessados no livro '{{ book.title }}'
<button class="btn btn-info btn-lg" (click)="back()" title="Voltar">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</button>
</h1>

<div class="alert alert-warning" role="alert" [hidden]="!showWarning">
{{ warningMessage }}
</div>

<div class="alert alert-success" role="alert" [hidden]="!showWarningWinnerChoosed">
Você já escolheu o ganhador. =)
</div>

<div [hidden]="!isLoading">
<i class="fa fa-spinner fa-spin" style="position: absolute; left: 50%;"></i>
</div>
Expand Down
96 changes: 84 additions & 12 deletions src/app/components/book/donate-page/donate-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DatePipe } from '@angular/common';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
Expand All @@ -8,6 +9,8 @@ import { BookService } from 'src/app/core/services/book/book.service';
import { LocalDataSource } from 'ng2-smart-table';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { DonateComponent } from '../donate/donate.component';
import { Book } from 'src/app/core/models/book';
import { BookDonationStatus } from 'src/app/core/models/BookDonationStatus';

@Component({
selector: 'app-donate-page',
Expand All @@ -22,7 +25,12 @@ export class DonatePageComponent implements OnInit, OnDestroy {
selectedDonatedUser: any;
showNote: Boolean = false;
formGroup: FormGroup;
bookId: string;
bookSlug: string;
book: Book = new Book();
chooseDateFormated: string;
warningMessage: string;
showWarning = false;
showWarningWinnerChoosed = false;

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

Expand All @@ -43,21 +51,14 @@ export class DonatePageComponent implements OnInit, OnDestroy {
.pipe(
takeUntil(this._destroySubscribes$)
)
.subscribe(param => (this.bookId = param.id));
.subscribe(param => (this.bookSlug = param.id));

this.returnUrl = this._activatedRoute.snapshot.queryParams['returnUrl'] || '/panel';

this._scBook.getRequestersList(this.bookId)
.pipe(
takeUntil(this._destroySubscribes$)
)
.subscribe(resp => {
this.donateUsers = new LocalDataSource(<any>resp);
this.isLoading = false;
});
this.loadBook();

const btnDonate =
'<span class="btn btn-warning btn-sm ml-1 mb-1" data-toggle="tooltip" title="Escolher Donatário">' +
'<span class="btn btn-warning btn-sm ml-1 mb-1" data-toggle="tooltip" title="Escolher ganhador">' +
' <i class="fa fa-trophy"></i> </span>';

this.settings = {
Expand Down Expand Up @@ -108,11 +109,34 @@ export class DonatePageComponent implements OnInit, OnDestroy {

onCustom(event) {
if (event.action === 'donate') {

switch (this.book.status) {
case BookDonationStatus.WAITING_APPROVAL:
alert(`Aguarde a aprovação dessa doação.`);
return;
case BookDonationStatus.AVAILABLE:
alert(`Aguarde a data de decisão.`);
return;

// BookDonationStatus.WAITING_DECISION >> não precisa de aviso.
// é a hora de escolher o ganhador!

case BookDonationStatus.WAITING_SEND:
case BookDonationStatus.SENT:
case BookDonationStatus.RECEIVED:
alert(`Você já escolheu o ganhador. =)`);
return;

case BookDonationStatus.CANCELED:
alert (`Essa doação foi cancelada. =(`);
return;
}

const modalRef = this._modalService.open(DonateComponent, {
backdropClass: 'light-blue-backdrop',
centered: true
});
modalRef.componentInstance.bookId = this.bookId;
modalRef.componentInstance.bookId = this.book.id;
modalRef.componentInstance.userId = event.data.userId;
modalRef.componentInstance.userNickName = event.data.requesterNickName;

Expand All @@ -132,4 +156,52 @@ export class DonatePageComponent implements OnInit, OnDestroy {
this._destroySubscribes$.next();
this._destroySubscribes$.complete();
}

loadBook() {
this._scBook
.getBySlug(this.bookSlug)
.pipe(takeUntil(this._destroySubscribes$))
.subscribe(
(book) => {
this.book = book;
this.loadRequestersList();
this.chooseDateFormated = new DatePipe('en-US').transform(book.chooseDate, 'dd/MM/yyyy');

switch (book.status) {
case BookDonationStatus.WAITING_APPROVAL:
this.showWarning = true;
this.warningMessage = `Aguarde a aprovação dessa doação.`;
break;
case BookDonationStatus.AVAILABLE:
this.showWarning = true;
this.warningMessage = `Aguarde a data de decisão para escolher o ganhador, em ${this.chooseDateFormated}.`;
break;

// BookDonationStatus.WAITING_DECISION >> não precisa de aviso.
// é a hora de escolher o ganhador!

case BookDonationStatus.WAITING_SEND:
case BookDonationStatus.SENT:
case BookDonationStatus.RECEIVED:
this.showWarningWinnerChoosed = true;
break;

case BookDonationStatus.CANCELED:
this.showWarning = true;
this.warningMessage = `Essa doação foi cancelada. =(`;
break;
}
});
}

loadRequestersList() {
this._scBook.getRequestersList(this.book.id)
.pipe(
takeUntil(this._destroySubscribes$)
)
.subscribe(resp => {
this.donateUsers = new LocalDataSource(<any>resp);
this.isLoading = false;
});
}
}
Loading

0 comments on commit ab368f7

Please sign in to comment.