dev #13305
добавил тестовый конфиг (+- подходит для нефтяников), сделал сайт конфигуряемым
This commit is contained in:
parent
c7db59110e
commit
7a12e6d4f7
@ -14,6 +14,8 @@ import { AccountComponent } from '../account/account.component';
|
|||||||
import { MessageService } from 'primeng/api';
|
import { MessageService } from 'primeng/api';
|
||||||
import { MessagingService } from 'src/app/services/messaging.service';
|
import { MessagingService } from 'src/app/services/messaging.service';
|
||||||
import { CookiesService } from 'src/app/services/cookies.service';
|
import { CookiesService } from 'src/app/services/cookies.service';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import * as ConfigActions from '../../state/config/config.actions'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-main',
|
selector: 'app-main',
|
||||||
@ -38,6 +40,7 @@ export class MainComponent implements OnInit {
|
|||||||
private messageService: MessageService,
|
private messageService: MessageService,
|
||||||
private messagingService: MessagingService,
|
private messagingService: MessagingService,
|
||||||
private cookiesService: CookiesService,
|
private cookiesService: CookiesService,
|
||||||
|
private store: Store
|
||||||
) {
|
) {
|
||||||
renderer.listen('window', 'appinstalled', (evt) => {
|
renderer.listen('window', 'appinstalled', (evt) => {
|
||||||
console.log('INSTALLED!!!');
|
console.log('INSTALLED!!!');
|
||||||
@ -54,10 +57,12 @@ export class MainComponent implements OnInit {
|
|||||||
this.token = token ? token : '';
|
this.token = token ? token : '';
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.appendAccount();
|
this.appendAccount();
|
||||||
|
this.store.dispatch(ConfigActions.getConfig());
|
||||||
// this.checkRequestPermission()
|
// this.checkRequestPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
angular/src/app/state/config/config.actions.ts
Normal file
13
angular/src/app/state/config/config.actions.ts
Normal file
@ -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 }>()
|
||||||
|
);
|
||||||
31
angular/src/app/state/config/config.effects.ts
Normal file
31
angular/src/app/state/config/config.effects.ts
Normal file
@ -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,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
}
|
||||||
34
angular/src/app/state/config/config.reducer.ts
Normal file
34
angular/src/app/state/config/config.reducer.ts
Normal file
@ -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<ConfigState>('config');
|
||||||
|
|
||||||
|
export const selectCheckout = createSelector(
|
||||||
|
selectConfigState,
|
||||||
|
(state) => {
|
||||||
|
return state.checkout
|
||||||
|
}
|
||||||
|
);
|
||||||
40
angular/src/assets/site-config.json
Normal file
40
angular/src/assets/site-config.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user