diff --git a/src/app/modules/admin/member/partner/components/list.component.ts b/src/app/modules/admin/member/partner/components/list.component.ts index 584b05c..d7739a5 100644 --- a/src/app/modules/admin/member/partner/components/list.component.ts +++ b/src/app/modules/admin/member/partner/components/list.component.ts @@ -22,6 +22,7 @@ import { startWith, Subject, switchMap, + take, takeUntil, timer, } from 'rxjs'; @@ -32,7 +33,10 @@ import { Partner } from '../models/partner'; import { PartnerPagination } from '../models/partner-pagination'; import { PartnerService } from '../services/partner.service'; import { ActivatedRoute, Router } from '@angular/router'; -import { RegistComposeComponent } from '../compose/regist-compose.component'; +import { + RegistComposeComponent, + RegistComposeResult, +} from '../compose/regist-compose.component'; import { CashComposeComponent } from '../compose/cash-compose.component'; import { MatDialog } from '@angular/material/dialog'; @@ -240,12 +244,15 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { __onClickRegist(event: MouseEvent, partner: MemberModel): void { const dialogRef = this._matDialog.open(RegistComposeComponent, { - data: { title: '대본 등록하기', parent: partner, sites: this.sites }, + data: { title: '대본 등록', parent: partner, sites: this.sites }, }); - dialogRef.afterClosed().subscribe((result) => { - console.log('Compose dialog was closed!'); - }); + dialogRef + .afterClosed() + .pipe(take(1)) + .subscribe((result: RegistComposeResult) => { + console.log('Compose dialog was closed: ', result); + }); } __onClickCash(event: MouseEvent): void { const dialogRef = this._matDialog.open(CashComposeComponent, { diff --git a/src/app/modules/admin/member/partner/compose/regist-compose.component.html b/src/app/modules/admin/member/partner/compose/regist-compose.component.html index 2676df1..12b7408 100644 --- a/src/app/modules/admin/member/partner/compose/regist-compose.component.html +++ b/src/app/modules/admin/member/partner/compose/regist-compose.component.html @@ -3,7 +3,7 @@
-
{{ data.title }} 등록
+
{{ data.title }}
+ + {{ alert.message }} + +
{{ bank.getName() }} + 국민은행 은행명은 필수 입력입니다. @@ -184,6 +196,7 @@ mat-flat-button [color]="'primary'" (click)="send()" + [disabled]="isSendDisable" > 등록 diff --git a/src/app/modules/admin/member/partner/compose/regist-compose.component.ts b/src/app/modules/admin/member/partner/compose/regist-compose.component.ts index 70907ef..d860139 100644 --- a/src/app/modules/admin/member/partner/compose/regist-compose.component.ts +++ b/src/app/modules/admin/member/partner/compose/regist-compose.component.ts @@ -7,11 +7,18 @@ import { } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { FuseAlertType } from '@fuse/components/alert'; import { SiteService } from 'app/modules/polyglot/domain/services/site.service'; import { IdentityService } from 'app/modules/polyglot/member/services/identity.service'; +import { MemberService } from 'app/modules/polyglot/member/services/member.service'; +import { + CreateMemberRequest, + CreateMemberResponse, +} from 'app/modules/protobuf/c2se/backend/member_pb'; import { Bank } from 'app/modules/protobuf/models/account/bank_pb'; import { Site } from 'app/modules/protobuf/models/domain/site_pb'; import { MemberModel } from 'app/modules/protobuf/models/member/member_pb'; +import { fuseAnimations } from '@fuse/animations'; export interface RegistComposeData { title: string; @@ -20,35 +27,25 @@ export interface RegistComposeData { banks: Bank[]; } export interface RegistComposeResult { - parentId: string; - siteName: string; - signinId: string; - password: string; - exchangePassword: string; - nickname: string; - calculateType: string; - phoneNumber: string; - bankName: string; - accountNumber: string; - accountHolder: string; + choice: boolean; } @Component({ selector: 'app-regist-compose', templateUrl: './regist-compose.component.html', encapsulation: ViewEncapsulation.None, + animations: fuseAnimations, }) export class RegistComposeComponent implements OnInit { composeForm!: FormGroup; - sites: any[] = []; - // quillModules: any = { - // toolbar: [ - // ['bold', 'italic', 'underline'], - // [{ align: [] }, { list: 'ordered' }, { list: 'bullet' }], - // ['clean'], - // ], - // }; + alert: { type: FuseAlertType; message: string } = { + type: 'success', + message: '등록이 성공하였습니다.', + }; + + showAlert: boolean = false; + isSendDisable = false; /** * Constructor */ @@ -57,10 +54,9 @@ export class RegistComposeComponent implements OnInit { @Inject(MAT_DIALOG_DATA) public data: RegistComposeData, private _formBuilder: FormBuilder, private _identityService: IdentityService, + private _memberService: MemberService, private _changeDetectorRef: ChangeDetectorRef - ) { - this.data.sites.forEach((v) => console.log(v.getUrl())); - } + ) {} // ----------------------------------------------------------------------------------------------------- // @ Lifecycle hooks @@ -113,11 +109,61 @@ export class RegistComposeComponent implements OnInit { /** * Send the message + * + } */ send(): void { - console.log(this.composeForm.value); + if (!this.composeForm.valid) { + return; + } + + this.isSendDisable = true; + + const { + partnerId, + siteName, + signinId, + password, + exchangePassword, + nickname, + calculateType, + phoneNumber, + bankName, + accountNumber, + accountHolder, + } = this.composeForm.value; + + const member = new CreateMemberRequest(); + const site = new Site(); + site.setId(siteName); + + member.setSiteId(siteName); + member.setUsername(signinId); + member.setPassword('beteran'); + member.setMemberClassId('ae9b874e-5d0e-4c4d-8432-f45f02691ceb'); + member.setMemberLevelId('c56231ac-2120-4a81-a30a-5d41fafb6c57'); + member.setReferrerMemberUsername(this.data.parent.getUsername()); + member.setNickname(nickname); + member.setMobilePhoneNumber(phoneNumber); + + this._memberService + .createMember(member) + .then((res: CreateMemberResponse.Result) => { + console.log(res.getMember()); + this.showAlert = true; + }) + .catch((e) => { + this.showAlert = true; + this.alert = { type: 'error', message: '등록에 실패하였습니다.' }; + }) + .finally(() => (this.showAlert = false)); } + private close(): void { + this.matDialogRef.close({ + choice: true, + }); + } __checkSigninId(event: FocusEvent): void { const signinId = this.composeForm.get('signinId')?.value; // console.log(event, '::', signinId); diff --git a/src/app/modules/admin/member/partner/partner.module.ts b/src/app/modules/admin/member/partner/partner.module.ts index 6a10331..659d29a 100644 --- a/src/app/modules/admin/member/partner/partner.module.ts +++ b/src/app/modules/admin/member/partner/partner.module.ts @@ -26,6 +26,7 @@ import { COMPOSE } from './compose'; import { partnerRoutes } from './partner.routing'; import { MatDialogModule } from '@angular/material/dialog'; +import { FuseAlertModule } from '@fuse/components/alert'; @NgModule({ declarations: [COMPONENTS, COMPOSE], @@ -51,6 +52,8 @@ import { MatDialogModule } from '@angular/material/dialog'; MatGridListModule, MatMenuModule, MatRadioModule, + + FuseAlertModule, ], }) export class PartnerModule {} diff --git a/src/app/modules/polyglot/member/services/member.service.ts b/src/app/modules/polyglot/member/services/member.service.ts index a694a0a..ac31f64 100644 --- a/src/app/modules/polyglot/member/services/member.service.ts +++ b/src/app/modules/polyglot/member/services/member.service.ts @@ -17,8 +17,12 @@ import { UpdateMemberRequest, UpdateMemberResponse, SUBJECT_UPDATE_MEMBER, + CreateMemberResponse, + CreateMemberRequest, + SUBJECT_CREATE_MEMBER, } from 'app/modules/protobuf/c2se/backend/member_pb'; import { Pagination } from 'app/modules/protobuf/protobuf/pagination/pagination_pb'; +import { MemberModel } from 'app/modules/protobuf/models/member/member_pb'; @Injectable({ providedIn: 'root', @@ -157,46 +161,22 @@ export class MemberService { // classId: 4b014ef5-3bab-4413-aaf9-b0040a70ec77 // levelId: c56231ac-2120-4a81-a30a-5d41fafb6c57 - // createMember( - // siteId: string = '8429a7ab-b9de-400b-a209-28ff46e22bec', - // memberLevelId: string = 'c56231ac-2120-4a81-a30a-5d41fafb6c57', - // classId: string = '4b014ef5-3bab-4413-aaf9-b0040a70ec77', - // signinId: string, - // nickname: string, - // password: string, - // mobilePhoneNumber: string - // ): Promise { - // return new Promise((resolve, reject) => { - // let req = new UpdateMemberRequest(); - // req.setId(id); - - // if (!!siteId) { - // req.setSiteId(siteId); - // } - // if (!!memberLevelId) { - // req.setMemberLevelId(memberLevelId); - // } - // if (!!password) { - // req.setPassword(password); - // } - // if (!!mobilePhoneNumber) { - // req.setMobilePhoneNumber(mobilePhoneNumber); - // } - - // this.__natsService - // .request( - // SUBJECT_UPDATE_MEMBER, - // req.serializeBinary(), - // UpdateMemberResponse.deserializeBinary - // ) - // .then((result) => { - // console.log('updateMember Result: ', result); - // resolve(result); - // }) - // .catch((e: Error) => { - // console.log('failed', e); - // reject(e); - // }); - // }); - // } + createMember(req: CreateMemberRequest): Promise { + return new Promise((resolve, reject) => { + this.__natsService + .request( + SUBJECT_CREATE_MEMBER, + req.serializeBinary(), + CreateMemberResponse.deserializeBinary + ) + .then((result) => { + console.log('createMember Result: ', result); + resolve(result); + }) + .catch((e: Error) => { + console.log('failed', e); + reject(e); + }); + }); + } }