form-craft-package 1.7.12-dev.0 → 1.7.12-dev.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/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { IFormConfigDetails, IFormSchema } from '../../../types'
|
|
|
5
5
|
import client from '../../../api/client'
|
|
6
6
|
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
|
|
7
7
|
import { persistQueryClient } from '@tanstack/react-query-persist-client'
|
|
8
|
+
import { UserAuth } from '../../../api/user'
|
|
8
9
|
|
|
9
10
|
export interface UseCacheFormLayoutConfig {
|
|
10
11
|
cachedConfig?: IFormConfigDetails & IFormSchema & { formId?: number }
|
|
@@ -13,8 +14,9 @@ export interface UseCacheFormLayoutConfig {
|
|
|
13
14
|
applyUpdate: () => void
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function useCacheFormLayoutConfig(formId?: number): UseCacheFormLayoutConfig {
|
|
17
|
+
export function useCacheFormLayoutConfig(formId?: number, formKey?: string): UseCacheFormLayoutConfig {
|
|
17
18
|
const queryClient = useQueryClient()
|
|
19
|
+
const isPublic = !UserAuth.hasRefreshToken()
|
|
18
20
|
|
|
19
21
|
const [currentSchema, setCurrentSchema] = useState<IFormConfigDetails & IFormSchema>()
|
|
20
22
|
const [pendingSchema, setPendingSchema] = useState<IFormConfigDetails & IFormSchema>()
|
|
@@ -32,9 +34,9 @@ export function useCacheFormLayoutConfig(formId?: number): UseCacheFormLayoutCon
|
|
|
32
34
|
isSuccess,
|
|
33
35
|
} = useQuery<(IFormConfigDetails & IFormSchema) | undefined, Error>({
|
|
34
36
|
queryKey,
|
|
35
|
-
queryFn: () => fetchLayoutConfig(formId),
|
|
37
|
+
queryFn: () => fetchLayoutConfig(isPublic, formId, formKey),
|
|
36
38
|
gcTime: Infinity,
|
|
37
|
-
enabled: !!formId,
|
|
39
|
+
enabled: isPublic ? !!formKey : !!formId,
|
|
38
40
|
placeholderData: keepPreviousData,
|
|
39
41
|
})
|
|
40
42
|
|
|
@@ -45,10 +47,11 @@ export function useCacheFormLayoutConfig(formId?: number): UseCacheFormLayoutCon
|
|
|
45
47
|
persistQueryClient({
|
|
46
48
|
queryClient,
|
|
47
49
|
persister: localStoragePersistor,
|
|
48
|
-
|
|
50
|
+
maxAge: 1000 * 60 * 60 * 32, // 32h
|
|
49
51
|
dehydrateOptions: {
|
|
50
52
|
shouldDehydrateQuery: (query) => {
|
|
51
53
|
const [key, id] = query.queryKey
|
|
54
|
+
|
|
52
55
|
if (key === 'layoutConfig' && id === String(formId)) return false
|
|
53
56
|
|
|
54
57
|
return true
|
|
@@ -91,17 +94,22 @@ export function useCacheFormLayoutConfig(formId?: number): UseCacheFormLayoutCon
|
|
|
91
94
|
|
|
92
95
|
return {
|
|
93
96
|
cachedConfig: currentSchema?.id !== formId ? pendingSchema : currentSchema,
|
|
94
|
-
isConfigLoading: !!formId ? isLoading && !currentSchema : false,
|
|
97
|
+
isConfigLoading: (isPublic ? !!formKey : !!formId) ? isLoading && !currentSchema : false,
|
|
95
98
|
isUpdateFound: Boolean(pendingSchema),
|
|
96
99
|
applyUpdate,
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
async function fetchLayoutConfig(
|
|
101
|
-
|
|
103
|
+
async function fetchLayoutConfig(
|
|
104
|
+
isPublic: boolean,
|
|
105
|
+
formId?: number,
|
|
106
|
+
formKey?: string,
|
|
107
|
+
): Promise<(IFormConfigDetails & IFormSchema) | undefined> {
|
|
108
|
+
if (isPublic ? !formKey : !formId) return undefined
|
|
102
109
|
|
|
103
110
|
try {
|
|
104
|
-
const
|
|
111
|
+
const endpoint = isPublic ? `/api/site/${formKey}` : `/api/form/${formId}`
|
|
112
|
+
const res = await client.get<{ data: string }>(endpoint)
|
|
105
113
|
if (res.status === 200) {
|
|
106
114
|
const { data: jsonData, ...restResData } = res.data
|
|
107
115
|
return { ...restResData, ...JSON.parse(jsonData) } as IFormConfigDetails & IFormSchema
|
|
@@ -11,6 +11,8 @@ import { useBreadcrumb } from '../../common/custom-hooks/use-breadcrumb.hook'
|
|
|
11
11
|
import NotFound from '../../common/not-found'
|
|
12
12
|
import { useManyToManyConnector } from '../../common/custom-hooks/use-many-to-many-connector.hook'
|
|
13
13
|
import { PageViewTypEnum, DeviceBreakpointEnum, FormPreservedItemKeys, LOCAL_STORAGE_KEYS_ENUM } from '../../../enums'
|
|
14
|
+
import { UserAuth } from '../../../api/user'
|
|
15
|
+
import { useCacheFormLayoutConfig } from '../../common/custom-hooks/use-cache-form-layout-config.hook'
|
|
14
16
|
import {
|
|
15
17
|
fromMongoDbExtendedJSON,
|
|
16
18
|
getPickerFieldsWithOriginalTz,
|
|
@@ -18,8 +20,6 @@ import {
|
|
|
18
20
|
isValidMongoDbId,
|
|
19
21
|
queryParamsToObject,
|
|
20
22
|
} from '../../../functions/forms'
|
|
21
|
-
import { UserAuth } from '../../../api/user'
|
|
22
|
-
import { useCacheFormLayoutConfig } from '../../common/custom-hooks/use-cache-form-layout-config.hook'
|
|
23
23
|
|
|
24
24
|
export default function FormDataDetailsComponent({
|
|
25
25
|
isPublic,
|
|
@@ -42,7 +42,7 @@ export default function FormDataDetailsComponent({
|
|
|
42
42
|
|
|
43
43
|
const currentBreakpoint = useGetCurrentBreakpoint()
|
|
44
44
|
|
|
45
|
-
const { cachedConfig, isConfigLoading } = useCacheFormLayoutConfig(formId)
|
|
45
|
+
const { cachedConfig, isConfigLoading } = useCacheFormLayoutConfig(formId, formKey)
|
|
46
46
|
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
// for public forms, setting the details form into localStorage, so that buttons work correctly
|