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