From 7a12e6d4f779235ceb38aea6941bcbca18a06863 Mon Sep 17 00:00:00 2001 From: gofnnp Date: Mon, 5 Dec 2022 08:41:26 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#13305=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B9?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=20(+-=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D1=85=D0=BE=D0=B4=D0=B8=D1=82=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B5=D1=84=D1=82=D1=8F=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2),?= =?UTF-8?q?=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=81=D0=B0=D0=B9?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=D1=8B=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular/src/app/pages/main/main.component.ts | 5 +++ .../src/app/state/config/config.actions.ts | 13 ++++++ .../src/app/state/config/config.effects.ts | 31 ++++++++++++++ .../src/app/state/config/config.reducer.ts | 34 ++++++++++++++++ angular/src/assets/site-config.json | 40 +++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 angular/src/app/state/config/config.actions.ts create mode 100644 angular/src/app/state/config/config.effects.ts create mode 100644 angular/src/app/state/config/config.reducer.ts create mode 100644 angular/src/assets/site-config.json diff --git a/angular/src/app/pages/main/main.component.ts b/angular/src/app/pages/main/main.component.ts index 5fe1f24..28918db 100644 --- a/angular/src/app/pages/main/main.component.ts +++ b/angular/src/app/pages/main/main.component.ts @@ -14,6 +14,8 @@ import { AccountComponent } from '../account/account.component'; import { MessageService } from 'primeng/api'; import { MessagingService } from 'src/app/services/messaging.service'; import { CookiesService } from 'src/app/services/cookies.service'; +import { Store } from '@ngrx/store'; +import * as ConfigActions from '../../state/config/config.actions' @Component({ selector: 'app-main', @@ -38,6 +40,7 @@ export class MainComponent implements OnInit { private messageService: MessageService, private messagingService: MessagingService, private cookiesService: CookiesService, + private store: Store ) { renderer.listen('window', 'appinstalled', (evt) => { console.log('INSTALLED!!!'); @@ -54,10 +57,12 @@ export class MainComponent implements OnInit { this.token = token ? token : ''; }; }); + } ngOnInit(): void { this.appendAccount(); + this.store.dispatch(ConfigActions.getConfig()); // this.checkRequestPermission() } diff --git a/angular/src/app/state/config/config.actions.ts b/angular/src/app/state/config/config.actions.ts new file mode 100644 index 0000000..9b6d1bd --- /dev/null +++ b/angular/src/app/state/config/config.actions.ts @@ -0,0 +1,13 @@ +import { createAction, props } from '@ngrx/store'; + +export const getConfig = createAction('[Config] Get'); + +export const getSuccess = createAction( + '[Config] Get Success', + props<{ getSuccessResponse: any }>() +); + +export const getFailure = createAction( + '[Config] Get Failure', + props<{ error: string }>() +); \ No newline at end of file diff --git a/angular/src/app/state/config/config.effects.ts b/angular/src/app/state/config/config.effects.ts new file mode 100644 index 0000000..e3f7d40 --- /dev/null +++ b/angular/src/app/state/config/config.effects.ts @@ -0,0 +1,31 @@ +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 * 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 }))) + ) + ) + ) + ) + + constructor( + private actions$: Actions, + private wpJsonService: WpJsonService, + ) { } + +} \ No newline at end of file diff --git a/angular/src/app/state/config/config.reducer.ts b/angular/src/app/state/config/config.reducer.ts new file mode 100644 index 0000000..fedad6e --- /dev/null +++ b/angular/src/app/state/config/config.reducer.ts @@ -0,0 +1,34 @@ +import { createFeatureSelector, createReducer, createSelector, on } from '@ngrx/store'; +import { getConfig, getFailure, getSuccess } from './config.actions'; + +export interface ConfigState { + checkout: any +} + +export const initialConfigState: ConfigState = { + checkout: null +}; + +const _configReducer = createReducer( + initialConfigState, + on(getSuccess, (state, { getSuccessResponse }) => { + return getSuccessResponse; + }), + on(getFailure, (state, { error }) => { + console.error(error); + return state + }) +); + +export function configReducer(state: any, action: any) { + return _configReducer(state, action); +} + +export const selectConfigState = createFeatureSelector('config'); + +export const selectCheckout = createSelector( + selectConfigState, + (state) => { + return state.checkout + } +); \ No newline at end of file diff --git a/angular/src/assets/site-config.json b/angular/src/assets/site-config.json new file mode 100644 index 0000000..3f5247d --- /dev/null +++ b/angular/src/assets/site-config.json @@ -0,0 +1,40 @@ +{ + "checkout": { + "delivery": { + "values": [ + { + "cost": 0, + "title": "Самовывоз", + "id": 16, + "type": "self_delivery" + } + ], + "default": 0, + "disabled": true + }, + "payments": { + "values": [ + { + "type": "bonus", + "label": "Оплата бонусами" + }, + { + "type": "card", + "label": "Оплата картой" + } + ], + "default": 0, + "disabled": true + }, + "timeDelivery": { + "changeTime": { + "isShow": true, + "defaultValue": 60, + "disabled": true + }, + "checkboxNow": { + "isShow": false + } + } + } +} \ No newline at end of file