сделал объединение конфига с айки и с сайта
This commit is contained in:
Kataev Denis 2023-02-08 15:53:13 +04:00
parent 624d121006
commit 9e7b91e117
6 changed files with 54 additions and 30 deletions

View File

@ -20,7 +20,7 @@
</p>
</div>
<label class="terminal-list-label">Пункты самовывоза</label>
<div *ngIf="deliverData.deliveryType?.title === 'Самовывоз'" class="terminal-list-container">
<div *ngIf="deliverData.deliveryType?.name === 'Самовывоз'" class="terminal-list-container">
<div *ngFor="let terminal of terminalList" [ngClass]="{
'terminal-container': true,
'selected': terminal.label === selectedTerminal.label
@ -34,7 +34,7 @@
<div formGroupName="deliveryDataForm">
<p сlass="form-row form-row-wide">
<p-dropdown [options]="deliveryTypes" formControlName="deliveryType" placeholder="Доставка"
optionLabel="title" (onChange)="changeDeliveryType($event)"></p-dropdown>
optionLabel="name" (onChange)="changeDeliveryType($event)"></p-dropdown>
</p>
<p сlass="form-row form-row-wide">
<label id="deliveryDate">Время выдачи</label>

View File

@ -109,6 +109,11 @@ export class UserDataOrderComponent implements OnInit, OnDestroy {
}
})
// this.wpJsonService.getTerminalList().subscribe({
// next: (value) => {
// this.terminalList = value
// }
// })
}
checkAuthorization(showAuthoriztion: boolean, forced = false) {
@ -241,8 +246,8 @@ export class UserDataOrderComponent implements OnInit, OnDestroy {
}
private async _createDeliveryDataForm(): Promise<FormGroup> {
this.deliveryTypes = this.checkoutConfig.delivery.values;
this.deliverData.deliveryType = this.deliveryTypes[this.checkoutConfig.delivery.default];
this.deliveryTypes = this.checkoutConfig.delivery.filter((value: any) => value.isPickUp);
this.deliverData.deliveryType = this.deliveryTypes[0];
return this.fb.group({
deliveryDate: [{ value: this.deliverData.deliveryDate, disabled: this.checkoutConfig.timeDelivery.changeTime.disabled }, []],
deliveryType: [{ value: this.deliverData.deliveryType, disabled: this.checkoutConfig.delivery.disabled }, [Validators.required]],

View File

@ -86,6 +86,7 @@ export interface DeliveryType {
title: string;
id: number;
type: string;
name: string;
}
export interface AcceptedOrder {

View File

@ -62,6 +62,10 @@ export class WpJsonService {
return this._request(`/assets/site-config.json`, 'GET', null, false)
}
getSiteConfigFromIiko(): Observable<any> {
return this._request(`/static/settings.json`, 'GET', null, false)
}
_request(path: string, method: string, body?: any, auth = false, baseUrl?: string): Observable<any> {
const token = decodeURI(this.cookiesService.getItem('token') ?? '');
let headers = new HttpHeaders();

View File

@ -1,31 +1,45 @@
import { Injectable } from "@angular/core";
import { Actions, createEffect, ofType } from "@ngrx/effects";
import { catchError, of, exhaustMap, map, tap } from "rxjs";
import { WpJsonService } from "src/app/services/wp-json.service";
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import {
catchError,
of,
exhaustMap,
map,
combineLatest,
} from 'rxjs';
import { WpJsonService } from 'src/app/services/wp-json.service';
import * as ConfigActions from './config.actions';
@Injectable()
export class ConfigEffects {
getConfig$ = createEffect(() =>
this.actions$.pipe(
ofType(ConfigActions.getConfig),
exhaustMap((action) =>
this.wpJsonService.getSiteConfig()
.pipe(
map((getSuccessResponse) => {
return ConfigActions.getSuccess({ getSuccessResponse })
}
),
catchError((error) => of(ConfigActions.getFailure({ error })))
)
)
getConfig$ = createEffect(() =>
this.actions$.pipe(
ofType(ConfigActions.getConfig),
exhaustMap((action) =>
combineLatest([
this.wpJsonService.getSiteConfig(),
this.wpJsonService.getSiteConfigFromIiko(),
]).pipe(
map(([config, configFromIiko]) => {
const allConfig = Object.assign(config.checkout, configFromIiko);
return allConfig;
}),
map((allConfig) => {
return {
getSuccessResponse: {
checkout: allConfig,
},
};
}),
map((value) => ConfigActions.getSuccess(value)),
catchError((error) => of(ConfigActions.getFailure({ error })))
)
)
)
);
constructor(
private actions$: Actions,
private wpJsonService: WpJsonService,
) { }
}
constructor(
private actions$: Actions,
private wpJsonService: WpJsonService
) {}
}

View File

@ -1,12 +1,12 @@
[
{
"label": "Не основная группа",
"label": "Терминал1",
"id": "5613101b-e9bf-3e26-0175-88c7ab7e00cf",
"image": "https://idei.club/uploads/posts/2022-03/1647392267_5-idei-club-p-supermarket-interer-interer-krasivo-foto-6.jpg",
"address": "ул. Ленина 16"
},
{
"label": "Основная группа",
"label": "Терминал2",
"id": "5613101b-e9bf-3e26-0175-88c7ab7e00cf",
"image": "https://idei.club/uploads/posts/2022-03/1647392267_5-idei-club-p-supermarket-interer-interer-krasivo-foto-6.jpg",
"address": "ул. Ленина 18"