forked from jebaGem/AngularRedux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-customer.actions.ts
211 lines (192 loc) · 7 KB
/
search-customer.actions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { Injectable } from '@angular/core';
import { NgRedux, dispatch } from '@angular-redux/store';
import { IAppState } from '../store';
import { CustomerResult } from '../core/account/interfaces/api-customer';
import { SearchLoadingState } from './search-customer.state';
/**
* Action TypeKeys as Enum
* String enums solve a number of problems with prior approaches.
* it gives a convenient way to define string constants that are
* narrowly typed to specific values.
*/
export enum SearchCustomerActionTypeKeys {
PERFORM_SEARCH = 'search-customer/PERFORM_SEARCH',
PERFORM_SEARCH_SUCCEEDED = 'search-customer/PERFORM_SEARCH_SUCCEEDED',
PERFORM_SEARCH_FAILED = 'search-customer/PERFORM_SEARCH_FAILED',
GET_SINGLE_CUSTOMER = 'search-customer/GET_CUSTOMER',
GET_SINGLE_CUSTOMER_SUCCEEDED = 'search-customer/GET_SINGLE_CUSTOMER_SUCCEEDED',
GET_SINGLE_CUSTOMER_FAILED = 'search-customer/GET_SINGLE_CUSTOMER_FAILED',
SET_SEARCH_TYPE = 'search-customer/SET_SEARCH_TYPE',
SET_SEARCH_KEY = 'search-customer/SET_SEARCH_KEY',
SET_CUSTOMER = 'search-customer/SET_CUSTOMER',
SET_CUSTOMER_TOOLTIP_DISPLAY = 'search-customer/SET_CUSTOMER_TOOLTIP_DISPLAY',
SELECT_CONSENT_CHECK_BOX = 'search-customer/SELECT_CONSENT_CHECK_BOX',
SET_CUSTOMER_CONSENT_TOOLTIP = 'search-customer/SET_CUSTOMER_CONSENT_TOOLTIP',
NO_CUSTOMER_SELECTED = 'search-customer/NO_CUSTOMER_SELECTED',
SET_LOADING_STATE = 'search-customer/SET_LOADING_STATE',
REQUEST_REMOVE_VALIDATION_ERROR = 'search-customer/REQUEST_REMOVE_VALIDATION_ERROR',
CLEAR_STATE = 'search-customer/CLEAR_STATE',
CLEAR_FORM = 'search-customer/CLEAR_FORM',
TOGGLE_LOCK_BUBBLE_DISPLAY = 'search-customer/TOGGLE_LOCK_BUBBLE_DISPLAY',
CLEAR_SELECTED_CUSTOMER = 'search-customer/CLEAR_SELECTED_CUSTOMER'
}
export interface IRemoveValidationError {
type: SearchCustomerActionTypeKeys.REQUEST_REMOVE_VALIDATION_ERROR;
payload: string;
}
export interface IPerformSearch {
type: SearchCustomerActionTypeKeys.PERFORM_SEARCH;
payload: string;
}
export interface IPerformSearchSucceeded {
type: SearchCustomerActionTypeKeys.PERFORM_SEARCH_SUCCEEDED;
payload: Array<CustomerResult.ISearchCustomerResult>;
}
export interface IPerformSearchFailed {
type: SearchCustomerActionTypeKeys.PERFORM_SEARCH_FAILED;
}
export interface IGetSingleCustomer {
type: SearchCustomerActionTypeKeys.GET_SINGLE_CUSTOMER;
payload: string;
}
export interface IGetSingleCustomerSucceeded {
type: SearchCustomerActionTypeKeys.GET_SINGLE_CUSTOMER_SUCCEEDED;
payload: CustomerResult.ISearchCustomerResult;
}
export interface IGetSingleCustomerFailed {
type: SearchCustomerActionTypeKeys.GET_SINGLE_CUSTOMER_FAILED;
}
export interface ISetSearchType {
type: SearchCustomerActionTypeKeys.SET_SEARCH_TYPE;
payload: string;
}
export interface ISetSearchKey {
type: SearchCustomerActionTypeKeys.SET_SEARCH_KEY;
payload: string;
}
export interface ISelectCustomer {
type: SearchCustomerActionTypeKeys.SET_CUSTOMER;
payload: CustomerResult.ISearchCustomerResult;
}
export interface ISetCustomerLoadingState {
type: SearchCustomerActionTypeKeys.SET_LOADING_STATE;
payload: SearchLoadingState;
}
export interface ISelectConsentCheckBox {
type: SearchCustomerActionTypeKeys.SELECT_CONSENT_CHECK_BOX;
payload: boolean;
}
export interface ISetCustomerTooltipDisplay {
type: SearchCustomerActionTypeKeys.SET_CUSTOMER_TOOLTIP_DISPLAY;
payload: boolean;
}
export interface ISetCustomerConsentTooltipDisplay {
type: SearchCustomerActionTypeKeys.SET_CUSTOMER_CONSENT_TOOLTIP;
payload: boolean;
}
export interface ISetCustomerSelected {
type: SearchCustomerActionTypeKeys.NO_CUSTOMER_SELECTED;
payload: boolean;
}
export interface IClearSearchCustomerState {
type: SearchCustomerActionTypeKeys.CLEAR_STATE;
}
export interface IClearCustomerForm {
type: SearchCustomerActionTypeKeys.CLEAR_FORM;
}
export interface IToggleLockBubble {
type: SearchCustomerActionTypeKeys.TOGGLE_LOCK_BUBBLE_DISPLAY;
payload: boolean;
}
export interface IClearSelectedCustomer {
type: SearchCustomerActionTypeKeys.CLEAR_SELECTED_CUSTOMER;
}
export type SearchCustomerActionTypes =
| IPerformSearch
| IPerformSearchFailed
| IPerformSearchSucceeded
| IGetSingleCustomer
| IGetSingleCustomerSucceeded
| IGetSingleCustomerFailed
| ISetSearchType
| ISetSearchKey
| ISelectCustomer
| ISelectConsentCheckBox
| ISetCustomerTooltipDisplay
| ISetCustomerConsentTooltipDisplay
| ISetCustomerSelected
| ISetCustomerLoadingState
| IRemoveValidationError
| IClearSearchCustomerState
| IClearCustomerForm
| IToggleLockBubble
| IClearSelectedCustomer;
@Injectable()
export class SearchCustomerActions {
constructor(private ngRedux: NgRedux<IAppState>) { }
@dispatch() performSearch = (query: string): IPerformSearch => ({
type: SearchCustomerActionTypeKeys.PERFORM_SEARCH,
payload: query
})
@dispatch() setSearchType = (by: string): ISetSearchType => ({
type: SearchCustomerActionTypeKeys.SET_SEARCH_TYPE,
payload: by
})
@dispatch() setSearchKey = (key: string): ISetSearchKey => ({
type: SearchCustomerActionTypeKeys.SET_SEARCH_KEY,
payload: key
})
@dispatch() selectCustomer = (customer: CustomerResult.ISearchCustomerResult):
ISelectCustomer => ({
type: SearchCustomerActionTypeKeys.SET_CUSTOMER,
payload: customer
})
@dispatch() setCustomerTooltipDisplay = (show: boolean): ISetCustomerTooltipDisplay => ({
type: SearchCustomerActionTypeKeys.SET_CUSTOMER_TOOLTIP_DISPLAY,
payload: show
})
@dispatch() setLoadingState = (loadingState: SearchLoadingState): ISetCustomerLoadingState => ({
type: SearchCustomerActionTypeKeys.SET_LOADING_STATE,
payload: loadingState
})
/**
* For NL the consent check box should be selected. if not show the tool tip to select
* the consent check box
*/
@dispatch() selectConsentBox = (selected: boolean): ISelectConsentCheckBox => ({
type: SearchCustomerActionTypeKeys.SELECT_CONSENT_CHECK_BOX,
payload: selected
})
@dispatch() setCustomerConsentTooltipDisplay = (show: boolean):
ISetCustomerConsentTooltipDisplay =>
({
type: SearchCustomerActionTypeKeys.SET_CUSTOMER_CONSENT_TOOLTIP,
payload: show
})
@dispatch()
requestRemoveValidationError(payload: string): IRemoveValidationError {
return {
type: SearchCustomerActionTypeKeys.REQUEST_REMOVE_VALIDATION_ERROR,
payload
};
}
@dispatch()
clearValues(): IClearCustomerForm {
return {
type: SearchCustomerActionTypeKeys.CLEAR_FORM
};
}
@dispatch()
toggleLockBubbleDisplay(display: boolean): IToggleLockBubble {
return {
type: SearchCustomerActionTypeKeys.TOGGLE_LOCK_BUBBLE_DISPLAY,
payload: display
};
}
@dispatch()
clearSelectedCustomer(): IClearSelectedCustomer {
return {
type: SearchCustomerActionTypeKeys.CLEAR_SELECTED_CUSTOMER
};
}
}