Skip to content

Commit 99cdb9b

Browse files
api dependent on formId
1 parent 58dc7c1 commit 99cdb9b

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

packages/import/features/Import.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ import { DefaultService, OpenAPI } from '@formswizard/api';
88
OpenAPI.BASE = 'http://localhost:4000';
99
const { getProjectStateCryptedData, getProjectStateSchema } = DefaultService;
1010

11+
function useFormId() {
12+
const hash = typeof location != 'undefined' ? location.hash.slice(1) : '';
13+
const hashParameters = !hash ? {} : Object.fromEntries(new URLSearchParams(hash) as any);
14+
const { formId } = hashParameters;
15+
return formId
16+
}
17+
1118
export function DecryptAndImportLastNewSubmission() {
1219
const dispatch = useAppDispatch();
20+
const formId = useFormId();
1321
const jsonSchema = useAppSelector(selectJsonSchema);
1422

1523
const cryptedData = useAppSelector(selectCryptedData);
1624
useEffect( () => {
1725
async function loadCryptedData() {
18-
const { cryptedData } = await getProjectStateCryptedData();
26+
const { cryptedData } = await getProjectStateCryptedData(formId);
1927
const latestCryptedDatum = cryptedData?.length && cryptedData[cryptedData.length-1];
2028
latestCryptedDatum && dispatch(setCryptedData(latestCryptedDatum));
2129
}
@@ -39,11 +47,13 @@ export function DecryptAndImportLastNewSubmission() {
3947

4048
export function useSchema() {
4149
const dispatch = useAppDispatch();
50+
const formId = useFormId();
4251
const jsonSchema = useAppSelector(selectJsonSchema);
4352
const uiSchema = useAppSelector(selectUiSchema);
53+
4454
useEffect(() => {
4555
async function loadSchema() {
46-
const { schema } = await getProjectStateSchema();
56+
const { schema } = await getProjectStateSchema(formId);
4757
const { jsonSchema, uiSchema } = schema || {};
4858
jsonSchema && dispatch(setJsonSchema(jsonSchema))
4959
jsonSchema && dispatch(setUiSchema(uiSchema))

packages/import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"typescript": "^5.2.2"
1818
},
1919
"dependencies": {
20-
"@formswizard/api": "^0.0.4",
20+
"@formswizard/api": "^0.2.0",
2121
"@types/react": "^18.2.21",
2222
"pgp-provider": "workspace:*",
2323
"project-state": "workspace:*",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)