validation of group name is modified
This commit is contained in:
parent
e518ed386e
commit
619ebe4e61
|
@ -26,8 +26,17 @@
|
|||
maxlength="20"
|
||||
placeholder="{{ 'group.name' | translate }}"
|
||||
formControlName="groupName"
|
||||
(keyup)="onKeyupGroupName()"
|
||||
/>
|
||||
<mat-hint align="end">{{ input.value?.length || 0 }}/20</mat-hint>
|
||||
<mat-error
|
||||
*ngIf="inputForm.get('groupName').hasError('groupNameBanned')"
|
||||
>
|
||||
{{
|
||||
'group.errors.bannedWords'
|
||||
| translate: { bannedWords: bannedWords.join(',') }
|
||||
}}
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
} from '@angular/material';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
import { Observable, combineLatest, Subscription, of } from 'rxjs';
|
||||
import { map, tap, catchError } from 'rxjs/operators';
|
||||
import { map, tap, catchError, take } from 'rxjs/operators';
|
||||
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import * as AppStore from '@app/store';
|
||||
|
@ -62,7 +62,7 @@ import {
|
|||
AlertDialogResult,
|
||||
AlertDialogData
|
||||
} from '@ucap-webmessenger/ui';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { TranslateService, TranslateParser } from '@ngx-translate/core';
|
||||
import { environment } from '../../../../../environments/environment';
|
||||
|
||||
export interface CreateChatDialogData {
|
||||
|
@ -115,11 +115,38 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|||
private logger: NGXLogger,
|
||||
private dialogService: DialogService,
|
||||
private translateService: TranslateService,
|
||||
private translateParser: TranslateParser,
|
||||
private changeDetectorRef: ChangeDetectorRef
|
||||
) {
|
||||
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
||||
KEY_VER_INFO
|
||||
);
|
||||
|
||||
const banKeys: string[] = [
|
||||
'group.nameFavorite',
|
||||
'group.nameMyDept',
|
||||
'group.nameDefault'
|
||||
];
|
||||
|
||||
const currentLang = this.translateService.currentLang;
|
||||
const langs = ['ko', 'en'];
|
||||
|
||||
langs.forEach(lang => {
|
||||
this.translateService
|
||||
.getTranslation(lang)
|
||||
.pipe(take(1))
|
||||
.subscribe(
|
||||
translation => {
|
||||
banKeys.forEach(banKey => {
|
||||
this.bannedWords.push(
|
||||
this.translateParser.getValue(translation, banKey)
|
||||
);
|
||||
});
|
||||
},
|
||||
error => {},
|
||||
() => {}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
currentTabIndex: number;
|
||||
|
@ -162,6 +189,8 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|||
|
||||
inputForm: FormGroup;
|
||||
|
||||
bannedWords: string[] = [];
|
||||
|
||||
ngOnInit() {
|
||||
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
|
||||
this.companyCode = loginInfo.companyCode;
|
||||
|
@ -283,7 +312,14 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|||
.subscribe();
|
||||
|
||||
this.inputForm = this.formBuilder.group({
|
||||
groupName: ['', [Validators.required, this.checkSpecialCharacter()]]
|
||||
groupName: [
|
||||
'',
|
||||
[
|
||||
Validators.required,
|
||||
this.checkSpecialCharacter(),
|
||||
this.checkBanWords()
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
if (this.data.type === UserSelectDialogType.EditChatMember) {
|
||||
|
@ -302,6 +338,17 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|||
};
|
||||
}
|
||||
|
||||
checkBanWords(): ValidatorFn {
|
||||
return (control: AbstractControl): { [key: string]: any } | null => {
|
||||
if (!control || !control.value) {
|
||||
return null;
|
||||
}
|
||||
const ban =
|
||||
-1 < this.bannedWords.indexOf((control.value as string).trim());
|
||||
return ban ? { groupNameBanned: { value: control.value } } : null;
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (!!this.roomSubscription) {
|
||||
this.roomSubscription.unsubscribe();
|
||||
|
@ -754,4 +801,8 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy {
|
|||
: undefined
|
||||
});
|
||||
}
|
||||
|
||||
onKeyupGroupName() {
|
||||
this.inputForm.get('groupName').markAsTouched();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,7 +177,8 @@
|
|||
"confirmRemoveGroup": "Are you sure you want to delete the group {{nameOfGroup}}?<br/>Group members will only be deleted from that group.",
|
||||
"errors": {
|
||||
"label": "Group errors",
|
||||
"requireName": "Group name is required."
|
||||
"requireName": "Group name is required.",
|
||||
"bannedWords": "Prohibited word. [{{bannedWords}}]"
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
|
|
|
@ -177,7 +177,8 @@
|
|||
"confirmRemoveGroup": "그룹({{nameOfGroup}})을 삭제하시겠습니까?<br/>그룹 멤버는 해당 그룹에서만 삭제됩니다.",
|
||||
"errors": {
|
||||
"label": "그룹 에러",
|
||||
"requireName": "그룹명은 필수입력입니다."
|
||||
"requireName": "그룹명은 필수입력입니다.",
|
||||
"bannedWords": "금지단어 [{{bannedWords}}]"
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user