@jsb188/mday 1.1.7 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +39 -20
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/email.ts +28 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +14 -0
- package/src/constants/log-activityTexts.ts +54 -28
- package/src/constants/log.ts +82 -38
- package/src/constants/organization.ts +11 -2
- package/src/constants/product.ts +9 -33
- package/src/constants/report.ts +29 -10
- package/src/constants/sheet.ts +20 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +12 -0
- package/src/schemas/editLogEntry.ts +90 -44
- package/src/schemas/inboundContact.ts +72 -0
- package/src/schemas/logsQuery.ts +7 -272
- package/src/schemas/organization.ts +11 -174
- package/src/schemas/productsQuery.ts +2 -94
- package/src/schemas/reportsQuery.ts +8 -95
- package/src/types/account.d.ts +78 -0
- package/src/types/dataTable.d.ts +447 -0
- package/src/types/email.d.ts +71 -0
- package/src/types/inboundContact.d.ts +56 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +289 -178
- package/src/types/organization.d.ts +106 -50
- package/src/types/product.d.ts +7 -96
- package/src/types/report.d.ts +239 -152
- package/src/types/sheet.d.ts +298 -0
- package/src/types/storage.d.ts +161 -0
- package/src/types/workflow.d.ts +174 -0
- package/src/utils/dataTable.ts +834 -0
- package/src/utils/email.ts +113 -0
- package/src/utils/log.ts +30 -628
- package/src/utils/organization.ts +227 -44
- package/src/utils/product-calEvent.ts +7 -60
- package/src/utils/report.ts +158 -0
- package/src/utils/sheet.ts +170 -0
- package/src/utils/square.ts +22 -0
- package/src/utils/table-route.ts +146 -0
- package/src/utils/workflow.ts +212 -0
- package/tsconfig.json +12 -0
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/types/action.d.ts +0 -42
- package/src/utils/route-helpers.ts +0 -583
package/src/schemas/logsQuery.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { isFutureCalDate, isValidCalDate } from '@jsb188/app/utils/datetime';
|
|
2
|
-
import { indexToTimeZone, isValidTimeZone } from '@jsb188/app/utils/timeZone';
|
|
1
|
+
import { isFutureCalDate, isValidCalDate } from '@jsb188/app/utils/datetime.ts';
|
|
3
2
|
import { z } from 'zod';
|
|
4
|
-
import { LOG_ANY_ACTIVITY_ENUMS, LOG_ANY_TYPE_ENUMS, LOG_SORT_ENUMS, LOG_TYPES_BY_OPERATION } from '../constants/log';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
import type { OrganizationOperationEnum } from '../types/organization';
|
|
3
|
+
import { LOG_ANY_ACTIVITY_ENUMS, LOG_ANY_TYPE_ENUMS, LOG_SORT_ENUMS, LOG_TYPES_BY_OPERATION } from '../constants/log.ts';
|
|
4
|
+
import type { FilterLogEntriesArgs, LogTypeEnum } from '../types/log.d.ts';
|
|
5
|
+
import type { OrganizationOperationEnum } from '../types/organization.d.ts';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Zod schema for query params to filter
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
export const FilterLogEntriesSchema = z.object({
|
|
12
|
+
siteId: z.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.nullable(),
|
|
14
15
|
preset: z.string()
|
|
15
16
|
.optional()
|
|
16
17
|
.nullable(),
|
|
@@ -26,9 +27,6 @@ export const FilterLogEntriesSchema = z.object({
|
|
|
26
27
|
endDate: z.string()
|
|
27
28
|
.refine((ed) => isValidCalDate(ed), { message: 'END_DATE_INVALID' })
|
|
28
29
|
.nullable(),
|
|
29
|
-
timeZone: z.string()
|
|
30
|
-
.refine((tz) => isValidTimeZone(tz), { message: 'INVALID_TIMEZONE' })
|
|
31
|
-
.nullable(),
|
|
32
30
|
query: z.string()
|
|
33
31
|
.nullable(),
|
|
34
32
|
}).refine((data) => {
|
|
@@ -76,90 +74,6 @@ export function convertDigitsToLogTypes(
|
|
|
76
74
|
}).filter(Boolean) as FilterLogEntriesArgs['types'];
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
/**
|
|
80
|
-
* Convert list of log type enums to digits
|
|
81
|
-
* @param operationType - The type of operation for organization
|
|
82
|
-
* @param types - Array of log type enums
|
|
83
|
-
* @returns String made of digits (indexes) representing log types
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
export function convertLogTypesToDigits(
|
|
87
|
-
operationType: OrganizationOperationEnum | null,
|
|
88
|
-
types: FilterLogEntriesArgs['types'],
|
|
89
|
-
): string | null {
|
|
90
|
-
if (!operationType || !types) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const logTypes = LOG_TYPES_BY_OPERATION[operationType] as LogTypeEnum[];
|
|
95
|
-
if (!logTypes) {
|
|
96
|
-
console.warn(`No log types found for operation type: ${operationType}`);
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return logTypes.map((type: LogTypeEnum) => {
|
|
101
|
-
return types.includes(type) ? '1' : '0';
|
|
102
|
-
}).join('');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Create a filter object for logEntries() query from the URL search query.
|
|
107
|
-
* @param operation - The type of operation for organization
|
|
108
|
-
* @param searchQuery - The search query string from the URL
|
|
109
|
-
* @param otherFiltersObj - Additional filter properties to merge into the result
|
|
110
|
-
* @returns FilterLogEntriesArgs - The filter object to be used in the logEntries() query
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
export function getLogFiltersFromURL(
|
|
114
|
-
operation: OrganizationOperationEnum | null,
|
|
115
|
-
searchQuery: string,
|
|
116
|
-
otherFiltersObj?: {
|
|
117
|
-
withoutPreset?: Partial<FilterLogEntriesArgs>,
|
|
118
|
-
withPreset?: Partial<FilterLogEntriesArgs>
|
|
119
|
-
}
|
|
120
|
-
) {
|
|
121
|
-
if (!searchQuery && otherFiltersObj?.withPreset) {
|
|
122
|
-
return {
|
|
123
|
-
operation: operation!,
|
|
124
|
-
...otherFiltersObj.withPreset
|
|
125
|
-
};
|
|
126
|
-
} else if (searchQuery === '?preset=none' && otherFiltersObj?.withoutPreset) {
|
|
127
|
-
return {
|
|
128
|
-
operation: operation!,
|
|
129
|
-
...otherFiltersObj.withoutPreset
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
134
|
-
|
|
135
|
-
let startDate = urlParams.get('sd');
|
|
136
|
-
let endDate = urlParams.get('ed');
|
|
137
|
-
if (startDate && !endDate) {
|
|
138
|
-
endDate = startDate;
|
|
139
|
-
} else if (endDate && !startDate) {
|
|
140
|
-
startDate = endDate;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const filter: FilterLogEntriesArgs = {
|
|
144
|
-
operation: operation!,
|
|
145
|
-
types: convertDigitsToLogTypes(operation, urlParams.get('t')), // (urlParams.get('t') || null) as FilterLogEntriesArgs['type'] | null,
|
|
146
|
-
startDate,
|
|
147
|
-
endDate,
|
|
148
|
-
timeZone: indexToTimeZone(urlParams.get('z')),
|
|
149
|
-
query: urlParams.get('q') || '',
|
|
150
|
-
...otherFiltersObj?.withoutPreset,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const validation = FilterLogEntriesSchema.safeParse(filter);
|
|
154
|
-
if (!validation.success) {
|
|
155
|
-
// console.log('validation error', validation.error);
|
|
156
|
-
// Return null and force the client to go to a valid page
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return filter;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
77
|
/**
|
|
164
78
|
* Get Sort enum value from URL
|
|
165
79
|
*/
|
|
@@ -171,182 +85,3 @@ export function getLogSorValueFromURL(
|
|
|
171
85
|
const sortIndex = urlParams.get('s');
|
|
172
86
|
return LOG_SORT_ENUMS[Number(sortIndex) - 1] || null;
|
|
173
87
|
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Test if URL search query is valid against actual filter object
|
|
177
|
-
*/
|
|
178
|
-
|
|
179
|
-
export function logsSearchQueryIsValid(
|
|
180
|
-
searchQuery: string,
|
|
181
|
-
filter: FilterLogEntriesArgs | null
|
|
182
|
-
) {
|
|
183
|
-
if (!filter) {
|
|
184
|
-
return !searchQuery; // If no filter, searchQuery must be empty to be valid
|
|
185
|
-
} else if (!searchQuery || searchQuery === '?preset=none') {
|
|
186
|
-
return true; // If no searchQuery, any filter is valid
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
190
|
-
// const operation = urlParams.get('o');
|
|
191
|
-
// const types = urlParams.get('t');
|
|
192
|
-
const accountId = urlParams.get('a');
|
|
193
|
-
const startDate = urlParams.get('sd');
|
|
194
|
-
const endDate = urlParams.get('ed');
|
|
195
|
-
const timeZone = urlParams.get('z');
|
|
196
|
-
const query = urlParams.get('q');
|
|
197
|
-
|
|
198
|
-
// console.log(
|
|
199
|
-
// 'a', !!filter.accountId === !!accountId,
|
|
200
|
-
// 'sd', !!filter.startDate === !!startDate,
|
|
201
|
-
// 'ed', !!filter.endDate === !!endDate,
|
|
202
|
-
// 'z', !!filter.timeZone === !!timeZone,
|
|
203
|
-
// 'q', !!filter.query === !!query
|
|
204
|
-
// );
|
|
205
|
-
|
|
206
|
-
return (
|
|
207
|
-
// operation is allowed to pass through
|
|
208
|
-
// !!filter.operation === !!operation &&
|
|
209
|
-
// !!filter.types?.length === !!types && // Allow this to pass because of forced filters from page
|
|
210
|
-
!!filter.accountId === !!accountId &&
|
|
211
|
-
!!filter.startDate === !!startDate &&
|
|
212
|
-
!!filter.endDate === !!endDate &&
|
|
213
|
-
!!filter.timeZone === !!timeZone &&
|
|
214
|
-
!!filter.query === !!query
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Create URL from search query params.
|
|
220
|
-
* This function assumes the query parameters are valid and well-formed.
|
|
221
|
-
* @param operationType - Type of operation for organization
|
|
222
|
-
* @param orgGenericId - Generic ID of the organization
|
|
223
|
-
* @param searchQuery - Search query string from the URL
|
|
224
|
-
* @param fileType - Type of file ('pdf' or 'csv')
|
|
225
|
-
* @returns FilterLogEntriesArgs - The filter object to be used in the logEntries() query
|
|
226
|
-
*/
|
|
227
|
-
|
|
228
|
-
export function createLogsFileNameFromURL(
|
|
229
|
-
operationType: OrganizationOperationEnum | null,
|
|
230
|
-
orgGenericId: string,
|
|
231
|
-
searchQuery: string,
|
|
232
|
-
fileType: string
|
|
233
|
-
) {
|
|
234
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
235
|
-
const o = urlParams.get('o');
|
|
236
|
-
const t = urlParams.get('t');
|
|
237
|
-
const a = urlParams.get('a');
|
|
238
|
-
const sd = urlParams.get('sd');
|
|
239
|
-
const ed = urlParams.get('ed');
|
|
240
|
-
const z = urlParams.get('z');
|
|
241
|
-
const q = urlParams.get('q');
|
|
242
|
-
|
|
243
|
-
let checkStr = '';
|
|
244
|
-
let paramStr = '';
|
|
245
|
-
|
|
246
|
-
if (o) {
|
|
247
|
-
checkStr += o;
|
|
248
|
-
} else {
|
|
249
|
-
const ix = OPERATION_ENUMS.indexOf(operationType || '');
|
|
250
|
-
checkStr += String(ix + 1);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (t?.split('')?.some(letter => letter !== '0')) {
|
|
254
|
-
checkStr += '1';
|
|
255
|
-
paramStr += `_${t}`;
|
|
256
|
-
} else {
|
|
257
|
-
checkStr += '0';
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (a) {
|
|
261
|
-
checkStr += '1';
|
|
262
|
-
paramStr += `_${a}`;
|
|
263
|
-
} else {
|
|
264
|
-
checkStr += '0';
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (sd) {
|
|
268
|
-
checkStr += '1';
|
|
269
|
-
paramStr += `_${sd}`;
|
|
270
|
-
} else {
|
|
271
|
-
checkStr += '0';
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (ed) {
|
|
275
|
-
checkStr += '1';
|
|
276
|
-
paramStr += `_${ed}`;
|
|
277
|
-
} else {
|
|
278
|
-
checkStr += '0';
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (z) {
|
|
282
|
-
checkStr += '1';
|
|
283
|
-
paramStr += `_${z}`;
|
|
284
|
-
} else {
|
|
285
|
-
checkStr += '0';
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (q) {
|
|
289
|
-
checkStr += '1';
|
|
290
|
-
paramStr += `_${q}`;
|
|
291
|
-
} else {
|
|
292
|
-
checkStr += '0';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (checkStr.split('').every(digit => digit === '0')) {
|
|
296
|
-
return `logs_${orgGenericId}_x${paramStr}.${fileType}`;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return `logs_${orgGenericId}_${checkStr}${paramStr}.${fileType}`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Create URL search params from a filter object
|
|
304
|
-
* @param filter - The filter object to convert to URL search params
|
|
305
|
-
* @param sort - Optional sort enum value
|
|
306
|
-
* @param skipOperation - Whether to skip including the operation in the params
|
|
307
|
-
* @returns URLSearchParams - The search params object
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
export function createSearchParamsFromFilter(
|
|
311
|
-
filter: FilterLogEntriesArgs,
|
|
312
|
-
sort?: LogSortEnum | null,
|
|
313
|
-
skipOperation?: boolean,
|
|
314
|
-
): URLSearchParams {
|
|
315
|
-
const params = new URLSearchParams();
|
|
316
|
-
const { operation } = filter;
|
|
317
|
-
|
|
318
|
-
if (operation && !skipOperation) {
|
|
319
|
-
params.set('o', String(OPERATION_ENUMS.indexOf(operation) + 1));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (filter.types && operation) {
|
|
323
|
-
const typeDigits = convertLogTypesToDigits(operation, filter.types);
|
|
324
|
-
if (typeDigits) {
|
|
325
|
-
params.set('t', typeDigits);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (filter.accountId) {
|
|
330
|
-
params.set('a', filter.accountId);
|
|
331
|
-
}
|
|
332
|
-
if (filter.startDate) {
|
|
333
|
-
params.set('sd', filter.startDate);
|
|
334
|
-
}
|
|
335
|
-
if (filter.endDate) {
|
|
336
|
-
params.set('ed', filter.endDate);
|
|
337
|
-
}
|
|
338
|
-
if (filter.timeZone) {
|
|
339
|
-
params.set('z', filter.timeZone);
|
|
340
|
-
}
|
|
341
|
-
if (filter.query) {
|
|
342
|
-
params.set('q', filter.query);
|
|
343
|
-
}
|
|
344
|
-
if (sort) {
|
|
345
|
-
params.set('s', String(LOG_SORT_ENUMS.indexOf(sort) + 1));
|
|
346
|
-
}
|
|
347
|
-
if (!params.size && filter.preset === null) {
|
|
348
|
-
params.set('preset', 'none');
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
return params;
|
|
352
|
-
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type { OrganizationGQL } from '../types/organization.d';
|
|
4
|
-
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { makeAddressSchema } from '@jsb188/auth-web/schemas/address';
|
|
3
|
+
import type { OrganizationGQL } from '../types/organization.d.ts';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Length values for validation
|
|
@@ -9,68 +8,8 @@ import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
|
9
8
|
|
|
10
9
|
const MIN_LEN_VALUES = {
|
|
11
10
|
name: 40,
|
|
12
|
-
address_city: 100,
|
|
13
|
-
address_state: 32,
|
|
14
|
-
address_postalCode: 20,
|
|
15
11
|
};
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* Rules for each field
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const RULES = function() {
|
|
23
|
-
|
|
24
|
-
const addressRule = (_value: string, fv: any, k: string) => {
|
|
25
|
-
const addr = fv.address;
|
|
26
|
-
const hasAddressFV = Object.values(addr).some((v: any) => v?.trim()?.length > 0);
|
|
27
|
-
|
|
28
|
-
if (hasAddressFV) {
|
|
29
|
-
return !!addr?.[k]?.trim().length;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
'address.line1': {
|
|
37
|
-
for: 'address.line1',
|
|
38
|
-
rule: (v: any, fv: any) => addressRule(v, fv, 'line1'),
|
|
39
|
-
error: () => ({
|
|
40
|
-
message: i18n.t('error.msg_value_required', { value: i18n.t('form.line1') }),
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
'address.postalCode': {
|
|
44
|
-
for: 'address.postalCode',
|
|
45
|
-
rule: (v: any, fv: any) => addressRule(v, fv, 'postalCode'),
|
|
46
|
-
error: () => ({
|
|
47
|
-
message: i18n.t('error.msg_value_required', { value: i18n.t('form.postalCode') }),
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
50
|
-
'address.city': {
|
|
51
|
-
for: 'address.city',
|
|
52
|
-
rule: (v: any, fv: any) => addressRule(v, fv, 'city'),
|
|
53
|
-
error: () => ({
|
|
54
|
-
message: i18n.t('error.msg_value_required', { value: i18n.t('form.city') }),
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
'address.state': {
|
|
58
|
-
for: 'address.state',
|
|
59
|
-
rule: (v: any, fv: any) => addressRule(v, fv, 'state'),
|
|
60
|
-
error: () => ({
|
|
61
|
-
message: i18n.t('error.msg_value_required', { value: i18n.t('form.state') }),
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
'address.country': {
|
|
65
|
-
for: 'address.country',
|
|
66
|
-
rule: (v: any, fv: any) => addressRule(v, fv, 'country'),
|
|
67
|
-
error: () => ({
|
|
68
|
-
message: i18n.t('error.msg_value_required', { value: i18n.t('form.country') }),
|
|
69
|
-
}),
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}();
|
|
73
|
-
|
|
74
13
|
/**
|
|
75
14
|
* Schema; Edit account
|
|
76
15
|
*/
|
|
@@ -79,16 +18,12 @@ export function makeEditOrganizationSchema(
|
|
|
79
18
|
formId: string,
|
|
80
19
|
focusedName: string,
|
|
81
20
|
formValues: OrganizationGQL, // always append with "|| nodeData"
|
|
82
|
-
openModalPopUp: OpenModalPopUpFn
|
|
83
21
|
) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
offsetX: 0,
|
|
90
|
-
offsetY: 7,
|
|
91
|
-
};
|
|
22
|
+
const addressSchema = makeAddressSchema(
|
|
23
|
+
formId,
|
|
24
|
+
focusedName,
|
|
25
|
+
formValues?.address,
|
|
26
|
+
);
|
|
92
27
|
|
|
93
28
|
return {
|
|
94
29
|
listData: [{
|
|
@@ -120,109 +55,11 @@ export function makeEditOrganizationSchema(
|
|
|
120
55
|
__type: 'section_title',
|
|
121
56
|
item: {
|
|
122
57
|
title: i18n.t('form.address'),
|
|
123
|
-
description: i18n.t('org.address_notice_msg')
|
|
124
|
-
}
|
|
125
|
-
}, {
|
|
126
|
-
__type: 'input',
|
|
127
|
-
item: {
|
|
128
|
-
name: 'address.line1',
|
|
129
|
-
label: i18n.t('form.line1'),
|
|
130
|
-
placeholder: i18n.t('form.line1_ph'),
|
|
131
|
-
// autoComplete: 'off',
|
|
58
|
+
description: i18n.t('org.address_notice_msg'),
|
|
132
59
|
}
|
|
133
|
-
},
|
|
134
|
-
__type: 'input',
|
|
135
|
-
item: {
|
|
136
|
-
name: 'address.line2',
|
|
137
|
-
label: i18n.t('form.line2_optional'),
|
|
138
|
-
placeholder: i18n.t('form.line2_ph'),
|
|
139
|
-
// autoComplete: 'off',
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
__type: 'input',
|
|
143
|
-
item: {
|
|
144
|
-
name: 'address.postalCode',
|
|
145
|
-
label: i18n.t('form.postalCode'),
|
|
146
|
-
placeholder: formValues?.address?.postalCode || i18n.t('form.postalCode_ph'),
|
|
147
|
-
// autoComplete: 'off',
|
|
148
|
-
}
|
|
149
|
-
}, {
|
|
150
|
-
__type: 'group',
|
|
151
|
-
item: {
|
|
152
|
-
items: [{
|
|
153
|
-
__type: 'input',
|
|
154
|
-
item: {
|
|
155
|
-
name: 'address.city',
|
|
156
|
-
maxLength: MIN_LEN_VALUES.address_city,
|
|
157
|
-
label: i18n.t('form.city'),
|
|
158
|
-
placeholder: formValues?.address?.city || i18n.t('form.city_ph'),
|
|
159
|
-
},
|
|
160
|
-
}, {
|
|
161
|
-
__type: 'input',
|
|
162
|
-
item: {
|
|
163
|
-
name: 'address.state',
|
|
164
|
-
maxLength: MIN_LEN_VALUES.address_state,
|
|
165
|
-
label: i18n.t('form.state'),
|
|
166
|
-
placeholder: formValues?.address?.state,
|
|
167
|
-
},
|
|
168
|
-
}],
|
|
169
|
-
}
|
|
170
|
-
}, {
|
|
171
|
-
__type: 'input_click',
|
|
172
|
-
forceClickId: 'input_click_address.country',
|
|
173
|
-
label: i18n.t('form.country'),
|
|
174
|
-
item: {
|
|
175
|
-
label: i18n.t('form.country'),
|
|
176
|
-
locked: true,
|
|
177
|
-
focused: focusedName === (formId + '_address.country'),
|
|
178
|
-
name: 'address.country',
|
|
179
|
-
getter: (value: string) => value ? i18n.t(`country.from_code.${value}`) : '',
|
|
180
|
-
placeholder: formValues?.address?.country || i18n.t('form.country_ph'),
|
|
181
|
-
|
|
182
|
-
popOverProps: {
|
|
183
|
-
...poProps,
|
|
184
|
-
|
|
185
|
-
id: formId + '_address.country',
|
|
186
|
-
doNotFixToBottom: true,
|
|
187
|
-
iface: {
|
|
188
|
-
name: 'PO_LIST',
|
|
189
|
-
|
|
190
|
-
variables: {
|
|
191
|
-
designClassName: 'w_400',
|
|
192
|
-
className: 'max_h_50vh',
|
|
193
|
-
initialState: {
|
|
194
|
-
'address.country': formValues?.address?.country,
|
|
195
|
-
},
|
|
196
|
-
options: ['US','MX','CA'].map(cCode => ({
|
|
197
|
-
__type: 'LIST_ITEM' as const,
|
|
198
|
-
text: i18n.t(`country.from_code.${cCode}`),
|
|
199
|
-
// textClassName: 'ft_xs',
|
|
200
|
-
// rightIconClassName: 'ft_xs mb_2',
|
|
201
|
-
name: 'address.country',
|
|
202
|
-
value: cCode,
|
|
203
|
-
selected: formValues?.address?.country === cCode,
|
|
204
|
-
})).concat({
|
|
205
|
-
__type: 'BREAK' as const
|
|
206
|
-
}).concat(SUPPORTED_COUNTRIES.map(countryCode => ({
|
|
207
|
-
__type: 'LIST_ITEM' as const,
|
|
208
|
-
text: i18n.t(`country.from_code.${countryCode}`),
|
|
209
|
-
// textClassName: 'ft_xs',
|
|
210
|
-
// rightIconClassName: 'ft_xs mb_2',
|
|
211
|
-
name: 'address.country',
|
|
212
|
-
value: countryCode,
|
|
213
|
-
selected: formValues?.address?.country === countryCode,
|
|
214
|
-
})))
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
}],
|
|
60
|
+
}, ...addressSchema.listData],
|
|
220
61
|
rules: [
|
|
221
|
-
|
|
222
|
-
RULES['address.postalCode'],
|
|
223
|
-
RULES['address.city'],
|
|
224
|
-
RULES['address.state'],
|
|
225
|
-
RULES['address.country'],
|
|
62
|
+
...addressSchema.rules,
|
|
226
63
|
],
|
|
227
64
|
};
|
|
228
65
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { PRODUCT_TYPES } from '@jsb188/mday/constants/product';
|
|
2
|
-
import type { OrganizationOperationEnum } from '../types/organization.d';
|
|
1
|
+
import { PRODUCT_TYPES } from '@jsb188/mday/constants/product.ts';
|
|
3
2
|
import { z } from 'zod';
|
|
4
|
-
import type {
|
|
3
|
+
import type { ProductTypeEnum } from '../types/product.d.ts';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Zod schema for query params to filter
|
|
@@ -52,94 +51,3 @@ export function convertDigitToProductType(digit?: string | null): ProductTypeEnu
|
|
|
52
51
|
}
|
|
53
52
|
return PRODUCT_TYPES[Number(digit)] || null;
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Create a filter object for productsList() query from the URL search query.
|
|
58
|
-
* @param operationType - The organization operation type
|
|
59
|
-
* @param searchQuery - The search query string from the URL
|
|
60
|
-
* @param otherFiltersObj - Additional filter properties to merge into the result
|
|
61
|
-
* @returns ProductsFilterArgs - The filter object to be used in the productsList() query
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
export function getProductsFilterFromURL(
|
|
65
|
-
_operationType: OrganizationOperationEnum | null,
|
|
66
|
-
searchQuery: string,
|
|
67
|
-
otherFiltersObj?: {
|
|
68
|
-
withoutPreset?: Partial<ProductsFilterArgs>,
|
|
69
|
-
withPreset?: Partial<ProductsFilterArgs>
|
|
70
|
-
}
|
|
71
|
-
) {
|
|
72
|
-
if (!searchQuery && otherFiltersObj?.withPreset) {
|
|
73
|
-
return otherFiltersObj.withPreset;
|
|
74
|
-
} else if (searchQuery === '?preset=none' && otherFiltersObj?.withoutPreset) {
|
|
75
|
-
return otherFiltersObj.withoutPreset;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
79
|
-
|
|
80
|
-
// let startDate = urlParams.get('sd');
|
|
81
|
-
// let endDate = urlParams.get('ed');
|
|
82
|
-
// if (startDate && !endDate) {
|
|
83
|
-
// endDate = startDate;
|
|
84
|
-
// } else if (endDate && !startDate) {
|
|
85
|
-
// startDate = endDate;
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
|
-
const filter: ProductsFilterArgs = {
|
|
89
|
-
productType: convertDigitToProductType(urlParams.get('t'))!,
|
|
90
|
-
// startDate,
|
|
91
|
-
// endDate,
|
|
92
|
-
// timeZone: indexToTimeZone(urlParams.get('z')),
|
|
93
|
-
query: urlParams.get('q') || '',
|
|
94
|
-
...otherFiltersObj?.withoutPreset,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const validation = ProductsFilterSchema.safeParse(filter);
|
|
98
|
-
|
|
99
|
-
// console.log(otherFiltersObj);
|
|
100
|
-
// console.log('filter', filter);
|
|
101
|
-
// console.log('validation', validation);
|
|
102
|
-
|
|
103
|
-
if (!validation.success) {
|
|
104
|
-
// console.log('validation error', validation.error);
|
|
105
|
-
// Return null and force the client to go to a valid page
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return filter;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Test if URL search query is valid against actual filter object
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
export function productsSearchQueryIsValid(
|
|
117
|
-
searchQuery: string,
|
|
118
|
-
filter: ProductsFilterArgs | null
|
|
119
|
-
) {
|
|
120
|
-
if (!filter) {
|
|
121
|
-
return !searchQuery; // If no filter, searchQuery must be empty to be valid
|
|
122
|
-
} else if (!searchQuery || searchQuery === '?preset=none') {
|
|
123
|
-
return true; // If no searchQuery, any filter is valid
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
127
|
-
// const operation = urlParams.get('o');
|
|
128
|
-
const productType = urlParams.get('t');
|
|
129
|
-
// const accountId = urlParams.get('a');
|
|
130
|
-
// const startDate = urlParams.get('sd');
|
|
131
|
-
// const endDate = urlParams.get('ed');
|
|
132
|
-
// const timeZone = urlParams.get('z');
|
|
133
|
-
const query = urlParams.get('q');
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
// operation is allowed to pass through
|
|
137
|
-
// !!filter.operation === !!operation &&
|
|
138
|
-
!!filter.productType === !!productType &&
|
|
139
|
-
// !!filter.accountId === !!accountId &&
|
|
140
|
-
// !!filter.startDate === !!startDate &&
|
|
141
|
-
// !!filter.endDate === !!endDate &&
|
|
142
|
-
// !!filter.timeZone === !!timeZone &&
|
|
143
|
-
!!filter.query === !!query
|
|
144
|
-
);
|
|
145
|
-
}
|