Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Handle multi document generation #1318

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import DevNavBar from './components/DevNavBar';
import FeatherySpinner from '../elements/components/Spinner';
import CallbackQueue from '../utils/callbackQueue';
import {
featheryDoc,
downloadFile,
featheryWindow,
openTab,
runningInClient
Expand Down Expand Up @@ -130,13 +130,13 @@ import {
ACTION_AI_DOCUMENT_EXTRACT,
ACTION_ALLOY_VERIFY_ID,
ACTION_BACK,
ACTION_GENERATE_ENVELOPES,
ACTION_GENERATE_QUIK_DOCUMENTS,
ACTION_INVITE_COLLABORATOR,
ACTION_LOGOUT,
ACTION_NEW_SUBMISSION,
ACTION_NEXT,
ACTION_OAUTH_LOGIN,
ACTION_OPEN_FUSER_ENVELOPES,
ACTION_PURCHASE_PRODUCTS,
ACTION_REMOVE_PRODUCT_FROM_PURCHASE,
ACTION_REMOVE_REPEATED_ROW,
Expand Down Expand Up @@ -1911,7 +1911,7 @@ function Form({
setElementError((e as Error).message);
break;
}
} else if (type === ACTION_OPEN_FUSER_ENVELOPES) {
} else if (type === ACTION_GENERATE_ENVELOPES) {
await submitPromise;
try {
const data = await client.generateEnvelopes(action);
Expand All @@ -1930,13 +1930,15 @@ function Form({
} else openTab(url);
} else {
// Download files directly
data.files.forEach((url: string) => {
const link = featheryDoc().createElement('a');
link.href = url;
featheryDoc().body.appendChild(link);
link.click();
featheryDoc().body.removeChild(link);
});
await Promise.all(
data.files.map(async (url: string) => {
const response = await fetch(url);
const blob = await response.blob();
const fileName = new URL(url).pathname.split('/').at(-1) ?? '';
const file = new File([blob], fileName, { type: blob.type });
downloadFile(file);
})
);
}
} catch (e: any) {
setElementError((e as Error).message);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/elementActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ACTION_LOGOUT = 'logout';
export const ACTION_NEXT = 'next';
export const ACTION_NEW_SUBMISSION = 'new_submission';
export const ACTION_OAUTH_LOGIN = 'trigger_oauth_login';
export const ACTION_OPEN_FUSER_ENVELOPES = 'open_fuser_envelopes';
export const ACTION_GENERATE_ENVELOPES = 'open_fuser_envelopes';
export const ACTION_REMOVE_REPEATED_ROW = 'remove_repeated_row';
export const ACTION_GENERATE_QUIK_DOCUMENTS = 'generate_quik_documents';
export const ACTION_SEND_MAGIC_LINK = 'send_magic_link';
Expand Down
5 changes: 3 additions & 2 deletions src/utils/featheryClient/integrationClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as errors from '../error';
import { parseError } from '../error';
import { fieldValues, initFormsPromise, initInfo } from '../init';
import { encodeGetParams } from '../primitives';
import { parseError } from '../error';
import { API_URL } from '.';
import { OfflineRequestHandler, untrackUnload } from '../offlineRequestHandler';
import {
Expand Down Expand Up @@ -351,7 +351,8 @@ export default class IntegrationClient {
form_key: this.formKey,
fuser_key: userId,
documents: action.documents ?? [],
signer_email: signer
signer_email: signer,
repeatable: action.repeatable ?? false
};

const url = `${API_URL}document/form/generate/`;
Expand Down
Loading