Sms provider configuration component improvements
This commit is contained in:
parent
449cb5941d
commit
d5cf27cdbf
@ -92,6 +92,10 @@ export function isEmptyStr(value: any): boolean {
|
|||||||
return value === '';
|
return value === '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNotEmptyStr(value: any): boolean {
|
||||||
|
return value !== null && typeof value === 'string' && value.trim().length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export function isFunction(value: any): boolean {
|
export function isFunction(value: any): boolean {
|
||||||
return typeof value === 'function';
|
return typeof value === 'function';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,11 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '@app/core/core.state';
|
import { AppState } from '@app/core/core.state';
|
||||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
import { isDefinedAndNotNull } from '@core/utils';
|
import { isDefinedAndNotNull } from '@core/utils';
|
||||||
import { AwsSnsSmsProviderConfiguration } from '@shared/models/settings.models';
|
import {
|
||||||
|
AwsSnsSmsProviderConfiguration,
|
||||||
|
SmsProviderConfiguration,
|
||||||
|
SmsProviderType
|
||||||
|
} from '@shared/models/settings.models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-aws-sns-provider-configuration',
|
selector: 'tb-aws-sns-provider-configuration',
|
||||||
@ -93,6 +97,7 @@ export class AwsSnsProviderConfigurationComponent implements ControlValueAccesso
|
|||||||
let configuration: AwsSnsSmsProviderConfiguration = null;
|
let configuration: AwsSnsSmsProviderConfiguration = null;
|
||||||
if (this.awsSnsProviderConfigurationFormGroup.valid) {
|
if (this.awsSnsProviderConfigurationFormGroup.valid) {
|
||||||
configuration = this.awsSnsProviderConfigurationFormGroup.value;
|
configuration = this.awsSnsProviderConfigurationFormGroup.value;
|
||||||
|
(configuration as SmsProviderConfiguration).type = SmsProviderType.AWS_SNS;
|
||||||
}
|
}
|
||||||
this.propagateChange(configuration);
|
this.propagateChange(configuration);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import {
|
|||||||
import { deepClone } from '@core/utils';
|
import { deepClone } from '@core/utils';
|
||||||
import {
|
import {
|
||||||
createSmsProviderConfiguration,
|
createSmsProviderConfiguration,
|
||||||
SmsProviderConfiguration,
|
SmsProviderConfiguration, smsProviderConfigurationValidator,
|
||||||
SmsProviderType,
|
SmsProviderType,
|
||||||
smsProviderTypeTranslationMap
|
smsProviderTypeTranslationMap
|
||||||
} from '@shared/models/settings.models';
|
} from '@shared/models/settings.models';
|
||||||
@ -78,7 +78,7 @@ export class SmsProviderConfigurationComponent implements ControlValueAccessor,
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.smsProviderConfigurationFormGroup = this.fb.group({
|
this.smsProviderConfigurationFormGroup = this.fb.group({
|
||||||
type: [null, Validators.required],
|
type: [null, Validators.required],
|
||||||
configuration: [null, Validators.required]
|
configuration: [null, smsProviderConfigurationValidator(true)]
|
||||||
});
|
});
|
||||||
this.smsProviderConfigurationFormGroup.valueChanges.subscribe(() => {
|
this.smsProviderConfigurationFormGroup.valueChanges.subscribe(() => {
|
||||||
this.updateModel();
|
this.updateModel();
|
||||||
|
|||||||
@ -20,7 +20,11 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '@app/core/core.state';
|
import { AppState } from '@app/core/core.state';
|
||||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
import { isDefinedAndNotNull } from '@core/utils';
|
import { isDefinedAndNotNull } from '@core/utils';
|
||||||
import { phoneNumberPattern, TwilioSmsProviderConfiguration } from '@shared/models/settings.models';
|
import {
|
||||||
|
phoneNumberPattern,
|
||||||
|
SmsProviderConfiguration, SmsProviderType,
|
||||||
|
TwilioSmsProviderConfiguration
|
||||||
|
} from '@shared/models/settings.models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-twilio-sms-provider-configuration',
|
selector: 'tb-twilio-sms-provider-configuration',
|
||||||
@ -95,6 +99,7 @@ export class TwilioSmsProviderConfigurationComponent implements ControlValueAcce
|
|||||||
let configuration: TwilioSmsProviderConfiguration = null;
|
let configuration: TwilioSmsProviderConfiguration = null;
|
||||||
if (this.twilioSmsProviderConfigurationFormGroup.valid) {
|
if (this.twilioSmsProviderConfigurationFormGroup.valid) {
|
||||||
configuration = this.twilioSmsProviderConfigurationFormGroup.value;
|
configuration = this.twilioSmsProviderConfigurationFormGroup.value;
|
||||||
|
(configuration as SmsProviderConfiguration).type = SmsProviderType.TWILIO;
|
||||||
}
|
}
|
||||||
this.propagateChange(configuration);
|
this.propagateChange(configuration);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,8 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import { DeviceTransportType } from '@shared/models/device.models';
|
import { DeviceTransportType } from '@shared/models/device.models';
|
||||||
|
import { ValidatorFn } from '@angular/forms';
|
||||||
|
import { isNotEmptyStr } from '@core/utils';
|
||||||
|
|
||||||
export const smtpPortPattern: RegExp = /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;
|
export const smtpPortPattern: RegExp = /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;
|
||||||
|
|
||||||
@ -95,6 +97,36 @@ export interface SmsProviderConfiguration extends SmsProviderConfigurations {
|
|||||||
type: SmsProviderType;
|
type: SmsProviderType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function smsProviderConfigurationValidator(required: boolean): ValidatorFn {
|
||||||
|
return control => {
|
||||||
|
const configuration: SmsProviderConfiguration = control.value;
|
||||||
|
let errors = null;
|
||||||
|
if (required) {
|
||||||
|
let valid = false;
|
||||||
|
if (configuration && configuration.type) {
|
||||||
|
switch (configuration.type) {
|
||||||
|
case SmsProviderType.AWS_SNS:
|
||||||
|
const awsSnsConfiguration: AwsSnsSmsProviderConfiguration = configuration;
|
||||||
|
valid = isNotEmptyStr(awsSnsConfiguration.accessKeyId) && isNotEmptyStr(awsSnsConfiguration.secretAccessKey)
|
||||||
|
&& isNotEmptyStr(awsSnsConfiguration.region);
|
||||||
|
break;
|
||||||
|
case SmsProviderType.TWILIO:
|
||||||
|
const twilioConfiguration: TwilioSmsProviderConfiguration = configuration;
|
||||||
|
valid = isNotEmptyStr(twilioConfiguration.numberFrom) && isNotEmptyStr(twilioConfiguration.accountSid)
|
||||||
|
&& isNotEmptyStr(twilioConfiguration.accountToken);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
|
errors = {
|
||||||
|
invalid: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export interface TestSmsRequest {
|
export interface TestSmsRequest {
|
||||||
providerConfiguration: SmsProviderConfiguration;
|
providerConfiguration: SmsProviderConfiguration;
|
||||||
numberTo: string;
|
numberTo: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user