@tellescope/react-components 1.180.0 → 1.181.1
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/lib/cjs/Forms/forms.d.ts +6 -1
- package/lib/cjs/Forms/forms.d.ts.map +1 -1
- package/lib/cjs/Forms/forms.js +5 -5
- package/lib/cjs/Forms/forms.js.map +1 -1
- package/lib/cjs/Forms/inputs.d.ts +1 -1
- package/lib/cjs/Forms/inputs.d.ts.map +1 -1
- package/lib/cjs/Forms/inputs.js +13 -3
- package/lib/cjs/Forms/inputs.js.map +1 -1
- package/lib/cjs/Forms/types.d.ts +1 -0
- package/lib/cjs/Forms/types.d.ts.map +1 -1
- package/lib/cjs/state.d.ts +1 -0
- package/lib/cjs/state.d.ts.map +1 -1
- package/lib/cjs/state.js +34 -0
- package/lib/cjs/state.js.map +1 -1
- package/lib/esm/Forms/forms.d.ts +6 -1
- package/lib/esm/Forms/forms.d.ts.map +1 -1
- package/lib/esm/Forms/forms.js +5 -5
- package/lib/esm/Forms/forms.js.map +1 -1
- package/lib/esm/Forms/inputs.d.ts +1 -1
- package/lib/esm/Forms/inputs.d.ts.map +1 -1
- package/lib/esm/Forms/inputs.js +13 -3
- package/lib/esm/Forms/inputs.js.map +1 -1
- package/lib/esm/Forms/types.d.ts +1 -0
- package/lib/esm/Forms/types.d.ts.map +1 -1
- package/lib/esm/state.d.ts +1 -0
- package/lib/esm/state.d.ts.map +1 -1
- package/lib/esm/state.js +34 -0
- package/lib/esm/state.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/Forms/forms.tsx +10 -3
- package/src/Forms/inputs.tsx +17 -3
- package/src/Forms/types.ts +1 -0
- package/src/state.tsx +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellescope/react-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.181.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"@reduxjs/toolkit": "^1.6.2",
|
|
48
48
|
"@stripe/react-stripe-js": "^2.9.0",
|
|
49
49
|
"@stripe/stripe-js": "^1.52.1",
|
|
50
|
-
"@tellescope/constants": "^1.
|
|
51
|
-
"@tellescope/sdk": "^1.
|
|
52
|
-
"@tellescope/types-client": "^1.
|
|
53
|
-
"@tellescope/types-models": "^1.
|
|
54
|
-
"@tellescope/types-utilities": "^1.
|
|
55
|
-
"@tellescope/utilities": "^1.
|
|
56
|
-
"@tellescope/validation": "^1.
|
|
50
|
+
"@tellescope/constants": "^1.181.1",
|
|
51
|
+
"@tellescope/sdk": "^1.181.1",
|
|
52
|
+
"@tellescope/types-client": "^1.181.1",
|
|
53
|
+
"@tellescope/types-models": "^1.181.1",
|
|
54
|
+
"@tellescope/types-utilities": "^1.181.1",
|
|
55
|
+
"@tellescope/utilities": "^1.181.1",
|
|
56
|
+
"@tellescope/validation": "^1.181.1",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
58
58
|
"@typescript-eslint/parser": "^4.33.0",
|
|
59
59
|
"css-to-react-native": "^3.0.0",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
85
85
|
"react-native": "^0.65.0 || ^0.66.0 || ^0.67.0 || ^0.68.0 || ^0.71.0"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "b83a341ad50cf72e2a30de11d40de8a3fafdd118",
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
}
|
package/src/Forms/forms.tsx
CHANGED
|
@@ -136,6 +136,7 @@ export const QuestionForField = ({
|
|
|
136
136
|
isInQuestionGroup,
|
|
137
137
|
logicOptions,
|
|
138
138
|
uploadingFiles, setUploadingFiles, handleFileUpload,
|
|
139
|
+
groupFields,
|
|
139
140
|
} : {
|
|
140
141
|
spacing?: number,
|
|
141
142
|
form?: Form,
|
|
@@ -147,10 +148,12 @@ export const QuestionForField = ({
|
|
|
147
148
|
setCustomerId: React.Dispatch<React.SetStateAction<string | undefined>>,
|
|
148
149
|
isSinglePage?: boolean,
|
|
149
150
|
isInQuestionGroup?: boolean,
|
|
151
|
+
questionGroupSize?: number,
|
|
150
152
|
logicOptions?: NextFieldLogicOptions,
|
|
151
153
|
handleFileUpload: (blob: FileBlob, fieldId: string) => Promise<any>,
|
|
152
154
|
uploadingFiles: { fieldId: string }[]
|
|
153
155
|
setUploadingFiles: React.Dispatch<React.SetStateAction<{ fieldId: string }[]>>,
|
|
156
|
+
groupFields?: FormField[],
|
|
154
157
|
} & Pick<TellescopeFormProps, "rootResponseId" | "goToNextField" | "groupId" | "groupInstance" | "submit" | "formResponseId" | 'enduserId' | 'isPreviousDisabled' | 'goToPreviousField' | 'enduser' | 'handleDatabaseSelect' | 'onAddFile' | 'onFieldChange' | 'fields' | 'customInputs' | 'responses' | 'selectedFiles' | 'validateField'>) => {
|
|
155
158
|
const String = customInputs?.['string'] ?? StringInput
|
|
156
159
|
const StringLong = customInputs?.['stringLong'] ?? StringLongInput
|
|
@@ -256,7 +259,7 @@ export const QuestionForField = ({
|
|
|
256
259
|
<DateStringInput field={field} disabled={value.disabled} value={value.answer.value as string} onChange={onFieldChange as ChangeHandler<'string'>} form={form} />
|
|
257
260
|
)
|
|
258
261
|
: field.type === 'Hidden Value' ? (
|
|
259
|
-
<HiddenValue isSinglePage={isSinglePage} goToNextField={goToNextField} goToPreviousField={goToPreviousField} field={field} value={value.answer.value as string} onChange={onFieldChange as ChangeHandler<any>} form={form} />
|
|
262
|
+
<HiddenValue groupFields={groupFields} isSinglePage={isSinglePage} goToNextField={goToNextField} goToPreviousField={goToPreviousField} field={field} value={value.answer.value as string} onChange={onFieldChange as ChangeHandler<any>} form={form} />
|
|
260
263
|
)
|
|
261
264
|
: field.type === 'Address' ? (
|
|
262
265
|
<Address field={field} disabled={value.disabled} value={value.answer.value as any} onChange={onFieldChange as ChangeHandler<any>} form={form} />
|
|
@@ -350,7 +353,7 @@ export const QuestionForField = ({
|
|
|
350
353
|
)
|
|
351
354
|
: field.type === 'Question Group' ? (
|
|
352
355
|
<Flex column flex={1}>
|
|
353
|
-
{(field.options?.subFields ?? []).map(({ id }) => {
|
|
356
|
+
{(field.options?.subFields ?? []).map(({ id }, indexInGroup) => {
|
|
354
357
|
const match = fields.find(f => f.id === id)
|
|
355
358
|
if (!match) return null
|
|
356
359
|
|
|
@@ -371,7 +374,11 @@ export const QuestionForField = ({
|
|
|
371
374
|
validateField={validateField} enduserId={enduserId}
|
|
372
375
|
spacing={field.options?.groupPadding}
|
|
373
376
|
logicOptions={logicOptions}
|
|
374
|
-
isInQuestionGroup
|
|
377
|
+
isInQuestionGroup
|
|
378
|
+
groupFields={
|
|
379
|
+
fields.filter(f => field.options?.subFields?.find(s => s.id === f.id))
|
|
380
|
+
}
|
|
381
|
+
questionGroupSize={field.options?.subFields?.length}
|
|
375
382
|
uploadingFiles={uploadingFiles} setUploadingFiles={setUploadingFiles}
|
|
376
383
|
handleFileUpload={handleFileUpload}
|
|
377
384
|
/>
|
package/src/Forms/inputs.tsx
CHANGED
|
@@ -3087,9 +3087,18 @@ export const RedirectInput = ({ enduserId, groupId, groupInsance, rootResponseId
|
|
|
3087
3087
|
return null
|
|
3088
3088
|
}
|
|
3089
3089
|
|
|
3090
|
-
export const HiddenValueInput = ({ goToNextField, goToPreviousField, field, value, onChange,
|
|
3090
|
+
export const HiddenValueInput = ({ goToNextField, goToPreviousField, field, value, onChange, isSinglePage, groupFields }: FormInputProps<'email'>) => {
|
|
3091
3091
|
let lastRef = useRef(0)
|
|
3092
3092
|
let lastIdRef = useRef('')
|
|
3093
|
+
|
|
3094
|
+
// in a Question Group, only the first Hidden Value should navigate
|
|
3095
|
+
// AND, it should only navigate if the group only contains hidden values
|
|
3096
|
+
const firstHiddenValue = groupFields?.find(v => v.type === 'Hidden Value')
|
|
3097
|
+
const dontNavigate = (
|
|
3098
|
+
(firstHiddenValue && firstHiddenValue?.id !== field.id) // is in a group, but not the first hidden value
|
|
3099
|
+
|| !!(groupFields?.find(v => v.type !== 'Hidden Value')) // group contains at least 1 non-hidden value
|
|
3100
|
+
)
|
|
3101
|
+
|
|
3093
3102
|
useEffect(() => {
|
|
3094
3103
|
if (lastRef.current > Date.now() - 1000 && lastIdRef.current === field.id) return
|
|
3095
3104
|
lastRef.current = Date.now()
|
|
@@ -3098,14 +3107,19 @@ export const HiddenValueInput = ({ goToNextField, goToPreviousField, field, valu
|
|
|
3098
3107
|
if (value) {
|
|
3099
3108
|
if (isSinglePage) return
|
|
3100
3109
|
onChange('', field.id)
|
|
3110
|
+
|
|
3111
|
+
if (dontNavigate) return
|
|
3101
3112
|
goToPreviousField?.()
|
|
3102
3113
|
} else {
|
|
3103
3114
|
onChange(field.title, field.id)
|
|
3104
|
-
|
|
3115
|
+
|
|
3116
|
+
if (dontNavigate) return
|
|
3117
|
+
|
|
3105
3118
|
// pass value that is set after above onChange
|
|
3119
|
+
console.log('going to next field for hidden value', field.title, !!goToNextField)
|
|
3106
3120
|
goToNextField?.({ type: 'Hidden Value', value: field.title })
|
|
3107
3121
|
}
|
|
3108
|
-
}, [value, onChange, field, goToNextField, goToPreviousField, isSinglePage])
|
|
3122
|
+
}, [value, onChange, field, goToNextField, goToPreviousField, isSinglePage, dontNavigate])
|
|
3109
3123
|
|
|
3110
3124
|
return <></>
|
|
3111
3125
|
}
|
package/src/Forms/types.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface FormInputProps<K extends keyof AnswerForType> {
|
|
|
35
35
|
handleFileUpload?: (blob: FileBlob, fieldId: string) => Promise<any>,
|
|
36
36
|
uploadingFiles?: { fieldId: string }[]
|
|
37
37
|
setUploadingFiles?: React.Dispatch<React.SetStateAction<{ fieldId: string }[]>>,
|
|
38
|
+
groupFields?: FormField[],
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export type FormInputs = {
|
package/src/state.tsx
CHANGED
|
@@ -719,6 +719,7 @@ export interface ListUpdateMethods <T, ADD> extends LoadMoreFunctions<T> {
|
|
|
719
719
|
getOldestLoadedId: () => string | undefined,
|
|
720
720
|
setOldestLoadedId: (id: string) => void,
|
|
721
721
|
loadRecentlyCreated: () => Promise<T[]>,
|
|
722
|
+
loadRecentlyUpdated: () => Promise<T[]>,
|
|
722
723
|
recentlyCreatedFetch: Date,
|
|
723
724
|
}
|
|
724
725
|
export type ListStateReturnType <T extends { id: string | number }, ADD=Partial<T>> = [LoadedData<T[]>, ListUpdateMethods<T, ADD>]
|
|
@@ -764,6 +765,10 @@ export const useListStateHook = <T extends { id: string | number }, ADD extends
|
|
|
764
765
|
if (now.getTime() === recentlyCreatedFetch.current.getTime()) {
|
|
765
766
|
setLastDate(`${modelName}-recentlyCreatedFetch`, now)
|
|
766
767
|
}
|
|
768
|
+
const recentlyUpdatedFetch = useRef(getLastDate(`${modelName}-recentlyUpdatedFetch`) || now)
|
|
769
|
+
if (now.getTime() === recentlyUpdatedFetch.current.getTime()) {
|
|
770
|
+
setLastDate(`${modelName}-recentlyUpdatedFetch`, now)
|
|
771
|
+
}
|
|
767
772
|
|
|
768
773
|
const addLocalElement = useCallback((e: T, o?: AddOptions) => {
|
|
769
774
|
dispatch(slice.actions.add({ value: e, options: o }))
|
|
@@ -1163,6 +1168,25 @@ export const useListStateHook = <T extends { id: string | number }, ADD extends
|
|
|
1163
1168
|
|
|
1164
1169
|
return []
|
|
1165
1170
|
}, [session.api, modelName, addLocalElements, loadQuery, setLastDate])
|
|
1171
|
+
|
|
1172
|
+
const loadRecentlyUpdated = React.useCallback(async () => {
|
|
1173
|
+
if (!loadQuery) return []
|
|
1174
|
+
|
|
1175
|
+
const fromUpdated = recentlyUpdatedFetch.current
|
|
1176
|
+
|
|
1177
|
+
if (fromUpdated.getTime() + 1000 > Date.now()) return [] // throttle by 1 sec
|
|
1178
|
+
recentlyUpdatedFetch.current = new Date()
|
|
1179
|
+
setLastDate(`${modelName}-recentlyUpdatedFetch`, recentlyUpdatedFetch.current)
|
|
1180
|
+
|
|
1181
|
+
try {
|
|
1182
|
+
const created = await loadQuery({ fromUpdated })
|
|
1183
|
+
if (created.length === 0) return []
|
|
1184
|
+
|
|
1185
|
+
return addLocalElements(created, { replaceIfMatch: true })
|
|
1186
|
+
} catch(err) { console.error(err) }
|
|
1187
|
+
|
|
1188
|
+
return []
|
|
1189
|
+
}, [session.api, modelName, addLocalElements, loadQuery, setLastDate])
|
|
1166
1190
|
|
|
1167
1191
|
return [
|
|
1168
1192
|
state,
|
|
@@ -1171,7 +1195,7 @@ export const useListStateHook = <T extends { id: string | number }, ADD extends
|
|
|
1171
1195
|
createElement, createElements, updateElement, updateLocalElement, updateLocalElements, findByFilter, findById, removeElement, removeLocalElements,
|
|
1172
1196
|
reload, loadMore, doneLoading, filtered,
|
|
1173
1197
|
getOldestLoadedDate, setOldestLoadedDate, setOldestLoadedId, getOldestLoadedId,
|
|
1174
|
-
loadRecentlyCreated,
|
|
1198
|
+
loadRecentlyCreated, loadRecentlyUpdated,
|
|
1175
1199
|
recentlyCreatedFetch: recentlyCreatedFetch.current,
|
|
1176
1200
|
}
|
|
1177
1201
|
]
|