Skip to content

Commit

Permalink
PER-9922 Show loading spinner and success message checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
crisnicandrei committed Dec 2, 2024
1 parent 4e181f1 commit 7aae25e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
border: 1px solid rgba(54, 68, 147, 0.4);
border-radius: 12px;
}

:host(.full-screen) {
left: 0;
z-index: 2;
}

.spinner-container {
position: relative;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/* @format */
import { Component } from '@angular/core';
import { Component, HostBinding, Input } from '@angular/core';

@Component({
selector: 'pr-loading-spinner',
templateUrl: './loading-spinner.component.html',
styleUrl: './loading-spinner.component.scss',
})
export class LoadingSpinnerComponent {}
export class LoadingSpinnerComponent {
@Input() isFullScreen = false;

@HostBinding('class.full-screen') get fullScreenClass() {
return this.isFullScreen;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<!-- @format -->
<form (submit)="submitPledge(pledgeForm.value)" [formGroup]="pledgeForm">
<pr-loading-spinner
[isFullScreen]="true"
*ngIf="waiting"
></pr-loading-spinner>

<div class="input-group-vertical">
<div class="input-vertical pledge-buttons">
<div
Expand Down Expand Up @@ -85,4 +90,8 @@
}}
GB
</button>
<p class="success-message" *ngIf="isSuccessful">
Success! {{ amountInGb }} GB of Permanent storage has been added to your
account.
</p>
</form>
21 changes: 21 additions & 0 deletions src/app/pledge/components/new-pledge/new-pledge.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,25 @@ describe('NewPledgeComponent', () => {

expect(instance.donationSelection).toBe('custom');
});

it('should display the loading spinner', async () => {
const { find, instance } = await shallow.render();

instance.waiting = true;

expect(find('pr-loading-spinner')).toBeTruthy();
});

it('should display the correct amount of storage if the transaction is succesful', async () => {
const { find, instance, fixture } = await shallow.render();

instance.isSuccessful = true;
instance.amountInGb = 5;

fixture.detectChanges();

const displayedMessage = find('.success-message');

expect(displayedMessage.nativeElement.textContent).toContain('Success! 5 GB of Permanent storage has been added to your account.');
});
});
6 changes: 5 additions & 1 deletion src/app/pledge/components/new-pledge/new-pledge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const elements = stripe.elements();
})
export class NewPledgeComponent implements OnInit, AfterViewInit {
@Input() inlineFlow: boolean = false;
public waiting: boolean;
public waiting: boolean = false;
public pledgeForm: UntypedFormGroup;

public donationLevels = [10, 20, 50];
Expand All @@ -42,6 +42,7 @@ export class NewPledgeComponent implements OnInit, AfterViewInit {
public donationAmount = 10;

public pricePerGb = 10;
public isSuccessful: boolean = false;

@ViewChild('customDonationAmount', { static: true })
customDonationInput: ElementRef;
Expand All @@ -53,6 +54,7 @@ export class NewPledgeComponent implements OnInit, AfterViewInit {

public static stripeCardInstance: any;
public static currentInstance: NewPledgeComponent;
public amountInGb: number = 0;

constructor(
private api: ApiService,
Expand Down Expand Up @@ -264,13 +266,15 @@ export class NewPledgeComponent implements OnInit, AfterViewInit {
entity: 'account',
action: 'purchase_storage',
});
this.isSuccessful = true;

Check warning on line 269 in src/app/pledge/components/new-pledge/new-pledge.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/pledge/components/new-pledge/new-pledge.component.ts#L269

Added line #L269 was not covered by tests
this.accountService.addStorageBytes(sizeInBytes);
this.message.showMessage({
message: `You just claimed ${this.getStorageAmount(
pledge.dollarAmount,
)} GB of storage!`,
style: 'success',
});
this.amountInGb = this.getStorageAmount(pledge.dollarAmount);

Check warning on line 277 in src/app/pledge/components/new-pledge/new-pledge.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/pledge/components/new-pledge/new-pledge.component.ts#L277

Added line #L277 was not covered by tests
}
} catch (err) {
this.waiting = false;
Expand Down
2 changes: 2 additions & 0 deletions src/app/pledge/pledge.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AngularFireDatabaseModule } from '@angular/fire/compat/database';
import { CountUpModule } from 'ngx-countup';
import { environment } from '@root/environments/environment';
import { SecretsService } from '@shared/services/secrets/secrets.service';
import { ComponentsModule } from '../component-library/components.module';
import { PledgeRoutingModule } from './pledge.routes';
import { NewPledgeComponent } from './components/new-pledge/new-pledge.component';
import { PledgeService } from './services/pledge.service';
Expand All @@ -25,6 +26,7 @@ import { UpdateCardComponent } from './components/update-card/update-card.compon
CommonModule,
SharedModule,
RouterModule,
ComponentsModule,
AngularFireModule.initializeApp({
...environment.firebase,
apiKey: SecretsService.getStatic('FIREBASE_API_KEY'),
Expand Down

0 comments on commit 7aae25e

Please sign in to comment.