Skip to content

Commit 58dc7c1

Browse files
getProjectStateCryptedData
1 parent 42489c1 commit 58dc7c1

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

packages/config/features/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const developerMode = Boolean(process.env.developerMode && process.env.developerMode != 'false');
1+
const developerMode = Boolean(typeof(process) != 'undefined' && process.env.developerMode && process.env.developerMode != 'false');
22

33
export const config = {
44
developerMode /** this option is independent of being a development-build, but specifies if debug features for developers should be enabled **/

packages/import/features/Import.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { useEffect } from 'react';
22

33
import { useAppSelector, useAppDispatch, setRowData } from 'state';
4-
import { selectJsonSchema, selectCryptedData } from 'project-state';
4+
import { selectJsonSchema, selectCryptedData, setCryptedData, selectUiSchema, setJsonSchema, setUiSchema } from 'project-state';
55
import { PGPProvider, decryptUsingContext } from 'pgp-provider';
6+
import { DefaultService, OpenAPI } from '@formswizard/api';
7+
8+
OpenAPI.BASE = 'http://localhost:4000';
9+
const { getProjectStateCryptedData, getProjectStateSchema } = DefaultService;
610

711
export function DecryptAndImportLastNewSubmission() {
12+
const dispatch = useAppDispatch();
813
const jsonSchema = useAppSelector(selectJsonSchema);
14+
915
const cryptedData = useAppSelector(selectCryptedData);
16+
useEffect( () => {
17+
async function loadCryptedData() {
18+
const { cryptedData } = await getProjectStateCryptedData();
19+
const latestCryptedDatum = cryptedData?.length && cryptedData[cryptedData.length-1];
20+
latestCryptedDatum && dispatch(setCryptedData(latestCryptedDatum));
21+
}
22+
console.log({cryptedData})
23+
cryptedData.length || loadCryptedData()
24+
}, [cryptedData])
1025

1126
/** TODO: Delete decrypted dataset after import and loop over submissions **/
1227

1328
const { data, uuid, keyId, armoredPublicKey } = cryptedData[cryptedData.length-1] || {};
1429
const decrypted_str = decryptUsingContext(data);
1530
const decrypted = decrypted_str && JSON.parse(decrypted_str);
1631

17-
const dispatch = useAppDispatch();
1832
useEffect( () => {
1933
const row = { ...decrypted, id: uuid, uuid, keyId, armoredPublicKey }
2034
decrypted && dispatch(setRowData({row}));
@@ -23,7 +37,24 @@ export function DecryptAndImportLastNewSubmission() {
2337
return <></>
2438
}
2539

40+
export function useSchema() {
41+
const dispatch = useAppDispatch();
42+
const jsonSchema = useAppSelector(selectJsonSchema);
43+
const uiSchema = useAppSelector(selectUiSchema);
44+
useEffect(() => {
45+
async function loadSchema() {
46+
const { schema } = await getProjectStateSchema();
47+
const { jsonSchema, uiSchema } = schema || {};
48+
jsonSchema && dispatch(setJsonSchema(jsonSchema))
49+
jsonSchema && dispatch(setUiSchema(uiSchema))
50+
}
51+
jsonSchema || loadSchema()
52+
}, [jsonSchema, uiSchema, dispatch])
53+
}
54+
2655
export function Import() {
56+
useSchema()
57+
2758
return <PGPProvider>
2859
<DecryptAndImportLastNewSubmission/>
2960
</PGPProvider>

packages/import/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"typescript": "^5.2.2"
1818
},
1919
"dependencies": {
20+
"@formswizard/api": "^0.0.4",
2021
"@types/react": "^18.2.21",
2122
"pgp-provider": "workspace:*",
2223
"project-state": "workspace:*",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)