Skip to content

Commit

Permalink
feat(JavaScript): allow passing submit complete options (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
NateFerrero authored Sep 13, 2024
1 parent 5477b40 commit d6e80ce
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .changeset/young-peaches-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@flatfile/embedded-utils': patch
'@flatfile/javascript': patch
---

JavaScript: allow specifying submit complete options
70 changes: 42 additions & 28 deletions apps/vanilla/cdn.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello, world!</title>
Expand All @@ -11,35 +10,50 @@
<link rel="stylesheet" type="text/css" href="./styles.css" />

<script>
start = () => {
const { initializeFlatfile: startFlatfile, FlatfileClient } = FlatFileJavaScript
const publishableKey =
localStorage.getItem('override-publishable-key') ?? 'pk_123456'

start = () => {
const { initializeFlatfile: startFlatfile, FlatfileClient } =
FlatFileJavaScript

console.log({ FlatfileClient })
const flatfileApi = new FlatfileClient({ environment: 'https://platform.eu.flatfile.com/api/v1' })
console.log({ FlatfileClient })
const flatfileApi = new FlatfileClient({
// environment: 'https://platform.eu.flatfile.com/api/v1',
})

startFlatfile({
publishableKey: localStorage.getItem('override-publishable-key') ?? 'pk_123456',
apiUrl: 'https://platform.eu.flatfile.com/api',
spaceBody: {
namespace: "portal",
},
sheet: blueprint,
onSubmit: async ({ event }) => {
console.log('onSubmit', { event })
const {
data,
} = await flatfileApi.files.list({
spaceId: event.context.spaceId,
});
console.log('file', { data });
},
});
};
startFlatfile({
publishableKey,
// apiUrl: 'https://platform.eu.flatfile.com/api',
spaceBody: {
namespace: 'portal',
},
sheet: blueprint,
submitSettings: {
complete: {
acknowledge: true, // required for auto close
message: 'Submitting data is now complete!',
},
},
onSubmit: async ({ event }) => {
console.log('onSubmit', { event })
const { data } = await flatfileApi.files.list({
spaceId: event.context.spaceId,
})
console.log('file', { data })
},
closeSpace: {
operation: 'simpleSubmitAction',
onClose: () => {
console.log('Portal is now closed!')
},
},
})
}
</script>
</head>
</head>

<body>
<body>
<button onClick="start()">Open Flatfile</button>
</body>

</body>
</html>
4 changes: 4 additions & 0 deletions packages/embedded-utils/src/types/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export interface ReusedSpaceWithAccessToken extends BaseSpace {
}

type SubmitSettings = {
complete?: {
acknowledge?: boolean
message?: string
}
deleteSpaceAfterSubmit?: boolean
}
export const DefaultSubmitSettings = {
Expand Down
3 changes: 2 additions & 1 deletion packages/javascript/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const createSimpleListener = ({

await api.jobs.complete(jobId, {
outcome: {
message: 'complete',
acknowledge: submitSettings?.complete?.acknowledge ?? true,
message: submitSettings?.complete?.message ?? 'complete',
},
})
if (onSubmitSettings.deleteSpaceAfterSubmit) {
Expand Down
1 change: 1 addition & 0 deletions packages/javascript/src/startFlatfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export async function startFlatfile(options: SimpleOnboarding | ISpace) {
onRecordHook: simpleOnboardingOptions?.onRecordHook,
onSubmit: simpleOnboardingOptions?.onSubmit,
slug: simpleListenerSlug,
submitSettings: simpleOnboardingOptions?.submitSettings,
}),
closeSpace,
closeSpaceNow,
Expand Down

0 comments on commit d6e80ce

Please sign in to comment.