moved the membership-options component back into the profile component since it is only used there.

pull/3/head
Chris Veilleux 2019-03-12 10:54:24 -05:00
parent 4bd41e3f79
commit 012ad39fe3
7 changed files with 76 additions and 52 deletions

View File

@ -1,7 +1,7 @@
<mat-button-toggle-group <mat-button-toggle-group
class="options-button-group" class="options-button-group"
[vertical]="alignVertical" [vertical]="alignVertical"
[value]="accountMembership" [value]="selectedMembershipType"
(change)="onMembershipSelect($event)" (change)="onMembershipSelect($event)"
> >
<mat-button-toggle <mat-button-toggle

View File

@ -0,0 +1,51 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { MediaChange, MediaObserver } from '@angular/flex-layout';
import { MatButtonToggleChange } from '@angular/material';
import { Subscription } from 'rxjs';
import { AccountMembership, MembershipType, ProfileService } from '../profile.service';
@Component({
selector: 'account-membership-options',
templateUrl: './membership-options.component.html',
styleUrls: ['./membership-options.component.scss']
})
export class MembershipOptionsComponent implements OnInit, OnDestroy {
@Input() accountMembership: AccountMembership;
public alignVertical: boolean;
@Input() membershipTypes: MembershipType[];
public mediaWatcher: Subscription;
@Output() membershipChange = new EventEmitter<string>();
public selectedMembershipType: string;
constructor(public mediaObserver: MediaObserver, private profileService: ProfileService) {
this.mediaWatcher = mediaObserver.media$.subscribe(
(change: MediaChange) => {
this.alignVertical = ['xs', 'sm'].includes(change.mqAlias);
}
);
}
ngOnInit(): void {
this.profileService.selectedMembershipType.subscribe(
(membershipType) => { this.selectedMembershipType = membershipType; }
);
this.profileService.setSelectedMembershipType(
this.accountMembership,
this.membershipTypes
);
}
ngOnDestroy(): void {
this.mediaWatcher.unsubscribe();
}
onMembershipSelect(newMembershipType: MatButtonToggleChange) {
this.profileService.selectedMembershipType.next(newMembershipType.value);
this.membershipChange.emit(newMembershipType.value);
}
}

View File

@ -4,42 +4,60 @@ import { FlexLayoutModule } from '@angular/flex-layout';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { import {
MatBottomSheetModule,
MatButtonModule, MatButtonModule,
MatButtonToggleModule,
MatCardModule, MatCardModule,
MatDialogModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
MatToolbarModule MatToolbarModule
} from '@angular/material'; } from '@angular/material';
import { NgxStripeModule } from 'ngx-stripe';
import { AgreementsComponent } from './agreements/agreements.component'; import { AgreementsComponent } from './agreements/agreements.component';
import { DeleteComponent } from './delete/delete.component'; import { DeleteComponent } from './delete/delete.component';
import { environment} from '../../environments/environment';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import { MembershipComponent } from './membership/membership.component';
import { MembershipOptionsComponent } from './membership-options/membership-options.component';
import { PaymentComponent } from './payment/payment.component';
import { ProfileComponent } from './profile.component'; import { ProfileComponent } from './profile.component';
import { ProfileService } from './profile.service'; import { ProfileService } from './profile.service';
import { MembershipComponent } from './membership/membership.component'; import { ProfileRoutingModule } from './profile-routing.module';
import { SharedModule } from 'shared'; import { VerifyCardDialogComponent } from './payment/verify-card-dialog.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AgreementsComponent, AgreementsComponent,
DeleteComponent, DeleteComponent,
LoginComponent, LoginComponent,
MembershipComponent,
MembershipOptionsComponent,
PaymentComponent,
ProfileComponent, ProfileComponent,
MembershipComponent VerifyCardDialogComponent
], ],
entryComponents: [ entryComponents: [
LoginComponent LoginComponent,
PaymentComponent,
VerifyCardDialogComponent
], ],
imports: [ imports: [
CommonModule, CommonModule,
FlexLayoutModule, FlexLayoutModule,
FontAwesomeModule, FontAwesomeModule,
MatBottomSheetModule,
MatButtonModule, MatButtonModule,
MatButtonToggleModule,
MatCardModule, MatCardModule,
MatDialogModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
MatToolbarModule, MatToolbarModule,
SharedModule NgxStripeModule.forRoot(environment.stripeApiKey),
ProfileRoutingModule
], ],
providers: [ providers: [
ProfileService ProfileService

View File

@ -1,42 +0,0 @@
import { Component, EventEmitter, Input, OnDestroy, Output } from '@angular/core';
import { MediaChange, MediaObserver } from '@angular/flex-layout';
import { MatButtonToggleChange } from '@angular/material';
import { Subscription } from 'rxjs';
export interface MembershipType {
type: string;
rate: string;
ratePeriod: string;
stripePlan: string;
}
@Component({
selector: 'shared-membership-options',
templateUrl: './membership-options.component.html',
styleUrls: ['./membership-options.component.scss']
})
export class MembershipOptionsComponent implements OnDestroy {
@Input() accountMembership: string;
public alignVertical: boolean;
@Input() membershipTypes: MembershipType[];
public mediaWatcher: Subscription;
@Output() membershipSelected = new EventEmitter<string>();
constructor(public mediaObserver: MediaObserver) {
this.mediaWatcher = mediaObserver.media$.subscribe(
(change: MediaChange) => {
this.alignVertical = ['xs', 'sm'].includes(change.mqAlias);
}
);
}
onMembershipSelect(membershipType: MatButtonToggleChange) {
this.membershipSelected.emit(membershipType.value);
}
ngOnDestroy(): void {
this.mediaWatcher.unsubscribe();
}
}

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
@Component({ @Component({
selector: 'lib-shared', selector: 'shared-base',
template: ` template: `
<p> <p>
shared works! shared works!

View File

@ -13,7 +13,6 @@ import {
import { FacebookButtonComponent } from './facebook-button/facebook-button.component'; import { FacebookButtonComponent } from './facebook-button/facebook-button.component';
import { GithubButtonComponent } from './github-button/github-button.component'; import { GithubButtonComponent } from './github-button/github-button.component';
import { GoogleButtonComponent } from './google-button/google-button.component'; import { GoogleButtonComponent } from './google-button/google-button.component';
import { MembershipOptionsComponent } from './membership-options/membership-options.component';
import { SharedComponent } from './shared.component'; import { SharedComponent } from './shared.component';
export function getAuthServiceConfigs() { export function getAuthServiceConfigs() {
@ -38,7 +37,6 @@ export function getAuthServiceConfigs() {
FacebookButtonComponent, FacebookButtonComponent,
GithubButtonComponent, GithubButtonComponent,
GoogleButtonComponent, GoogleButtonComponent,
MembershipOptionsComponent,
SharedComponent SharedComponent
], ],
imports: [ imports: [
@ -52,7 +50,6 @@ export function getAuthServiceConfigs() {
FacebookButtonComponent, FacebookButtonComponent,
GithubButtonComponent, GithubButtonComponent,
GoogleButtonComponent, GoogleButtonComponent,
MembershipOptionsComponent,
SharedComponent SharedComponent
], ],
providers: [ providers: [