Skip to content

Commit

Permalink
feat(ever-merchant): validated save payment gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
AlishMekliov931 committed Aug 2, 2019
1 parent c545910 commit 77a987f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
Expand Up @@ -14,6 +14,7 @@ <h4 class="custom-title-popup mb-0">
[defaultCompanyBrandLogo]="defaultCompanyBrandLogo"
[defaultCurrency]="defaultCurrency"
(configureObject)="updateConfigureObject($event)"
[(isValid)]="isValid"
></e-cu-stripe-gateway>
</div>

Expand All @@ -23,6 +24,7 @@ <h4 class="custom-title-popup mb-0">
</button>

<button
[disabled]="!isValid"
(click)="cancelModal(newConfigureObject)"
class="button button-brand"
>
Expand Down
Expand Up @@ -8,4 +8,10 @@
.body {
height: 80%;
}

button:disabled {
cursor: default;
opacity: 0.4;
pointer-events: none;
}
}
@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import PaymentGateways, {
paymentGatewaysToString
Expand All @@ -21,6 +21,7 @@ export class PaymentMutationComponent {
currenciesCodes: string[] = [];
paymentGateways = PaymentGateways;
newConfigureObject = new Subject();
isValid: boolean;

constructor(
public modalController: ModalController,
Expand Down
Expand Up @@ -50,6 +50,14 @@ export class SettingsPaymentsComponent implements OnInit {
this.showPaymentsGateways = true;
}

get isValid() {
return (
this.hasChanged &&
(!this.currWarehouse.isPaymentEnabled ||
this.myPaymentsGateways.length > 0)
);
}

getPaymentName(pg: PaymentGateways) {
return paymentGatewaysToString(pg);
}
Expand Down
Expand Up @@ -115,8 +115,8 @@
src="{{ companyBrandLogo?.value }}"
alt="Invalid image"
class="img-rounded"
(error)="invalidUrl = true"
(load)="invalidUrl = false"
(error)="onUrlChanges(true)"
(load)="onUrlChanges(false)"
/>
</div>

Expand Down
@@ -1,4 +1,11 @@
import { Component, OnInit, Input, OnDestroy, Output } from '@angular/core';
import {
Component,
OnInit,
Input,
OnDestroy,
Output,
EventEmitter
} from '@angular/core';
import {
FormGroup,
AbstractControl,
Expand All @@ -8,6 +15,7 @@ import {
import { Subject } from 'rxjs';
import PaymentGateways from '@modules/server.common/enums/PaymentGateways';
import { IPaymentGatewayCreateObject } from '@modules/server.common/interfaces/IPaymentGateway';
import { takeUntil } from 'rxjs/operators';

@Component({
selector: 'e-cu-stripe-gateway',
Expand All @@ -29,7 +37,11 @@ export class StripeGatewayComponent implements OnInit, OnDestroy {
publishableKey: string;
allowRememberMe: boolean;
};
@Input()
isValid: boolean;

@Output()
isValidChange = new EventEmitter();
@Output()
configureObject = new Subject();

Expand All @@ -40,14 +52,16 @@ export class StripeGatewayComponent implements OnInit, OnDestroy {
companyBrandLogo: AbstractControl;
publishableKey: AbstractControl;
allowRememberMe: AbstractControl;

invalidUrl: boolean;

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

constructor(private formBuilder: FormBuilder) {}

ngOnInit() {
this.buildForm(this.formBuilder);
this.bindFormControls();
this.onFormChanges();
}

bindFormControls() {
Expand All @@ -66,6 +80,12 @@ export class StripeGatewayComponent implements OnInit, OnDestroy {
this.configureObject.next(this.getConfigureObject());
}

private onUrlChanges(isInvalid: boolean) {
this.invalidUrl = isInvalid;
this.isValid = this.form.valid && !isInvalid;
this.isValidChange.emit(this.isValid);
}

private buildForm(formBuilder: FormBuilder) {
this.form = formBuilder.group({
payButtontext: [
Expand Down Expand Up @@ -96,4 +116,13 @@ export class StripeGatewayComponent implements OnInit, OnDestroy {
configureObject: this.form.getRawValue()
};
}

private onFormChanges() {
this.form.statusChanges
.pipe(takeUntil(this._ngDestroy$))
.subscribe((value) => {
this.isValid = this.form.valid && !this.invalidUrl;
this.isValidChange.emit(this.isValid);
});
}
}
Expand Up @@ -114,7 +114,7 @@ <h4 class="row-title">
<ion-button
[disabled]="
hasChanges(
paymentsSettings.hasChanged,
paymentsSettings.isValid,
productsDelivery.dirty,
productsTakeaway.dirty,
orderBarcodeType.dirty,
Expand Down

0 comments on commit 77a987f

Please sign in to comment.