diff --git a/angular/src/app/interface/data.ts b/angular/src/app/interface/data.ts index bb1a3e0..7ebe6c9 100644 --- a/angular/src/app/interface/data.ts +++ b/angular/src/app/interface/data.ts @@ -203,6 +203,7 @@ export interface UserInfo { OrdersSum: number; categories: UserInfoCategory[]; customer_level: number; + birthday: string; id: string; name: string | null; phone: string; @@ -213,3 +214,9 @@ export interface ResponseError { code: number; msg: string; } + +export interface UpdateNewCustomerRequest { + name: string; + sex: string; + birthday: string; +} diff --git a/angular/src/app/presentation-options/default-option/default-option-routing.module.ts b/angular/src/app/presentation-options/default-option/default-option-routing.module.ts index 205ee1a..388c3de 100644 --- a/angular/src/app/presentation-options/default-option/default-option-routing.module.ts +++ b/angular/src/app/presentation-options/default-option/default-option-routing.module.ts @@ -4,6 +4,7 @@ import { GuestCardComponent } from './pages/guest-card/guest-card.component'; import { AuthGuard } from 'src/app/guards/auth-guard.guard'; import { LoginComponent } from './pages/login/login.component'; import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component'; +import { CreateUserComponent } from './pages/create_user/create_user.component'; const routes: Routes = [ { @@ -18,7 +19,11 @@ const routes: Routes = [ { path: 'loyality-program', component: LoyalityProgramComponent, - } + }, + { + path: 'create_user', + component: CreateUserComponent, + }, ]; @NgModule({ diff --git a/angular/src/app/presentation-options/default-option/default-option.module.ts b/angular/src/app/presentation-options/default-option/default-option.module.ts index 58cbbf4..940e19b 100644 --- a/angular/src/app/presentation-options/default-option/default-option.module.ts +++ b/angular/src/app/presentation-options/default-option/default-option.module.ts @@ -7,6 +7,9 @@ import { SocialMediaButtonsComponent } from './components/social-media-buttons/s import { NavbarComponent } from './components/navbar/navbar.component'; import { MenuItemComponent } from './components/navbar/menu_item.component'; import { MatIconModule } from '@angular/material/icon'; +import { MatDatepickerModule } from '@angular/material/datepicker'; +import { MatSelectModule } from '@angular/material/select'; +import { MatNativeDateModule } from '@angular/material/core'; import { GuestCardComponent } from './pages/guest-card/guest-card.component'; import { QrCodeModule } from 'ng-qrcode'; import { AccordionComponent } from './components/accordion/accordion.component'; @@ -22,6 +25,7 @@ import { DirectivesModule } from 'src/app/directives/directives.module'; import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component'; import { MatButtonModule } from '@angular/material/button'; import { ToastModule } from 'primeng/toast'; +import { CreateUserComponent } from './pages/create_user/create_user.component'; @NgModule({ @@ -37,6 +41,7 @@ import { ToastModule } from 'primeng/toast'; LoginComponent, LoyalityProgramComponent, MenuItemComponent, + CreateUserComponent, ], imports: [ ToastModule, @@ -51,7 +56,10 @@ import { ToastModule } from 'primeng/toast'; ReactiveFormsModule, MatInputModule, DirectivesModule, - MatButtonModule + MatButtonModule, + MatDatepickerModule, + MatSelectModule, + MatNativeDateModule, ], bootstrap: [IndexComponent], }) diff --git a/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html new file mode 100644 index 0000000..b75af08 --- /dev/null +++ b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html @@ -0,0 +1,45 @@ + +
+
+
+

Регистрация

+ + Ваше имя + + + + Пол + + Не выбран + Мужчина + Женщина + + + + Дата рождения + + + + + +
+
+
+
+ + +
+ +
+
+ + +
+ +
+
diff --git a/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.scss b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.scss new file mode 100644 index 0000000..1ecf9a2 --- /dev/null +++ b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.scss @@ -0,0 +1,22 @@ +h1 { + color: var(--text-color); + text-align: center; +} + +.center { + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); +} + +.container { + max-width: 600px; + width: 100%; +} + +.form { + display: flex; + flex-direction: column; + width: 100%; +} diff --git a/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.ts b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.ts new file mode 100644 index 0000000..38b15bc --- /dev/null +++ b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.ts @@ -0,0 +1,43 @@ +import { Component, OnInit } from "@angular/core"; +import { FormControl, FormGroup, Validators } from "@angular/forms"; +import { MessageService } from "primeng/api"; +import { AuthService } from "src/app/services/auth.service"; +import moment from 'moment'; + +@Component({ + selector: 'create-user', + templateUrl: './create_user.component.html', + styleUrls: ['./create_user.component.scss'], +}) +export class CreateUserComponent implements OnInit { + public form = new FormGroup({ + name: new FormControl('', [Validators.required]), + sex: new FormControl('', [Validators.required]), + date: new FormControl('', [Validators.required]), + }); + + constructor( + public authService: AuthService, + private messageService: MessageService, + ) { } + + ngOnInit() { } + + submit() { + if (this.form.invalid) { + this.messageService.add({ + severity: 'error', + summary: 'Введите имя, пол и дату рождения', + }); + return; + } + + const name = this.form.value.name!; + const sex = this.form.value.sex!; + const date = this.form.value.date!; + + const formattedDate = moment(date).format('yyyy-MM-DD'); + + this.authService.register(name, sex, formattedDate); + } +} diff --git a/angular/src/app/presentation-options/default-option/pages/login/login.component.html b/angular/src/app/presentation-options/default-option/pages/login/login.component.html index 3f336e6..90d3211 100644 --- a/angular/src/app/presentation-options/default-option/pages/login/login.component.html +++ b/angular/src/app/presentation-options/default-option/pages/login/login.component.html @@ -15,30 +15,22 @@ (ngSubmit)="submitNumber()" [formGroup]="phoneForm" > - - - Ваше имя - - -
- - - Номер телефона - - - + + Номер телефона + + +
- + @@ -87,7 +79,7 @@ maxlength="1" /> - +

Не пришло SMS?
diff --git a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts index f764e7e..93cfaa6 100644 --- a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts +++ b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts @@ -18,7 +18,6 @@ import { MessageService } from 'primeng/api'; export class LoginComponent implements OnInit { public isShowNumber: boolean = true; public phoneForm = new FormGroup({ - name: new FormControl('', [Validators.required]), phone: new FormControl('', [Validators.required]), }); public codeForm = new FormGroup({ @@ -125,7 +124,7 @@ export class LoginComponent implements OnInit { const phoneData = this.phoneForm.value; this.authService.submitCode( - Object.values(data).join(''), phoneData.phone!, phoneData.name!); + Object.values(data).join(''), phoneData.phone!); } backToPhoneForm = () => { diff --git a/angular/src/app/services/auth.service.ts b/angular/src/app/services/auth.service.ts index 359f596..c47b0c3 100644 --- a/angular/src/app/services/auth.service.ts +++ b/angular/src/app/services/auth.service.ts @@ -4,7 +4,7 @@ import { WpJsonService } from './wp-json.service'; import { environment } from 'src/environments/environment'; import { JsonrpcService, RpcService } from './jsonrpc.service'; import { MessageService } from 'primeng/api'; -import { UserInfo, Purchase, lvlPeriod, UserInfoWalletBalance, ResponseError } from '../interface/data'; +import { UserInfo, Purchase, lvlPeriod, UserInfoWalletBalance } from '../interface/data'; import { lvlPeriods } from 'src/app/app.constants'; import moment, { Moment } from 'moment-timezone'; import { Router } from '@angular/router'; @@ -69,7 +69,10 @@ export class AuthService { ) .subscribe({ next: (value) => { - if (value && value.error && value.error.code > 1) { + if (value && value.customer_info && value.customer_info.errorCode === 'Customer_CustomerNotFound' + || !this.userHasData(value?.customer_info)) { + this.router.navigate(['create_user']); + } else if (value && value.error && value.error.code > 1) { this.messageService.clear(); this.messageService.add({ severity: 'error', @@ -90,6 +93,10 @@ export class AuthService { }); } + userHasData(user?: UserInfo) { + return user && (user.name || user.birthday); + } + logout() { this.userInfo = undefined; this.cookiesService.logout(); @@ -145,7 +152,7 @@ export class AuthService { }); } - submitCode(code: string, phone: string, name: string) { + submitCode(code: string, phone: string) { this.loading = true; this.jsonrpc .rpc( @@ -160,38 +167,9 @@ export class AuthService { next: (result) => { if (result.code === 0) { this.cookiesService.setCookie('token', result?.data?.token); - this.jsonrpc.rpc( - { - method: 'updateAdditionalInfo', - params: [ - { - first_name: name, - birth_day: '01.01.1999' - }, - ], - }, - RpcService.authService, - true - ).subscribe({ - next: () => { - this.router.navigate(['/']); + this.router.navigate(['/']); - this.wpJsonService.newCustomer( - environment.systemId, - result?.data?.token, - environment.icardProxy, - ) - .subscribe({ - next: () => { - this.getUserInfo(); - } - }) - }, - error: (err) => { - console.error(err); - this.loading = false; - }, - }) + this.getUserInfo(); } else if (result.code === 230) { this.messageService.clear(); this.messageService.add({ @@ -202,7 +180,7 @@ export class AuthService { }, error: (error) => { console.error(error); - this.loading = false; + this.loading = false; }, }); } @@ -261,4 +239,45 @@ export class AuthService { return accumulator + currentValue.balance; }, 0); } + + register(name: string, sex: string, date: string) { + if (this.token) { + this.loading = true; + + this.jsonrpc.rpc( + { + method: 'updateAdditionalInfo', + params: [ + { + first_name: name, + birth_day: '01.01.1999' + }, + ], + }, + RpcService.authService, + true + ).subscribe({ + next: () => { + this.wpJsonService.updateNewCustomer(environment.systemId, this.token!, { + name, + sex: sex, + birthday: date, + }) + .subscribe({ + next: () => { + this.router.navigate(['/']); + this.getUserInfo(); + }, + error: () => { + this.loading = false; + } + }); + }, + error: (err) => { + console.error(err); + this.loading = false; + }, + }) + } + } } diff --git a/angular/src/app/services/wp-json.service.ts b/angular/src/app/services/wp-json.service.ts index c05b001..743d829 100644 --- a/angular/src/app/services/wp-json.service.ts +++ b/angular/src/app/services/wp-json.service.ts @@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders } from "@angular/common/http"; import { CookiesService } from "./cookies.service"; import { Observable, of, switchMap } from "rxjs"; import { JsonRpcBody } from "./jsonrpc.service"; -import { DeliveryType, AcceptedOrder, Product } from "../interface/data"; +import { DeliveryType, AcceptedOrder, Product, UpdateNewCustomerRequest } from "../interface/data"; export enum Method { @@ -59,6 +59,10 @@ export class WpJsonService { return this._request(`purchase/${systemId}/${token}/${delta || ''}`, 'GET', null, false, url) } + updateNewCustomer(systemId: string, token: string, data: UpdateNewCustomerRequest) { + return this._request(`update_new_customer/${systemId}/${token}/`, 'POST', data, false, environment.icardProxy); + } + // getSiteConfig(): Observable { // return this._request(`/assets/site-config.json`, 'GET', null, false) // } diff --git a/angular/src/styles.scss b/angular/src/styles.scss index 57f7bc9..9ce27a8 100644 --- a/angular/src/styles.scss +++ b/angular/src/styles.scss @@ -127,10 +127,6 @@ body { --main-color_hover: rgba(208, 180, 133, 0.2); } -.mdc-button__label { - color: var(--text-color) !important; -} - .mdc-text-field--outlined:not(.mdc-text-field--disabled, .mdc-text-field--invalid) .mdc-notched-outline__leading, .mdc-text-field--outlined:not(.mdc-text-field--disabled, .mdc-text-field--invalid) .mdc-notched-outline__notch, .mdc-text-field--outlined:not(.mdc-text-field--disabled, .mdc-text-field--invalid) .mdc-notched-outline__trailing { @@ -138,7 +134,11 @@ body { } .mat-mdc-outlined-button:not(:disabled) { - border-color: var(--text-color) !important; + border-color: var(--text-color) !important; + + .mdc-button__label { + color: var(--text-color); + } } .mat-h1, @@ -170,6 +170,14 @@ body { color: var(--text-color); } +.mat-datepicker-toggle { + color: var(--text-color_2); +} + +.mat-mdc-select-value { + color: var(--text-color); +} + hr { width: 100%; border-top: 1px solid #BDBDBD;