form-craft-package 1.1.7 → 1.1.9

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-craft-package",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -67,7 +67,7 @@ export default function FormDataDetailsComponent({
67
67
  if (res.status === 200) {
68
68
  const parsedData: IFormSchema | null = parseJSON(res.data.data)
69
69
  if (parsedData) {
70
- console.log({parsedData})
70
+ console.log({ parsedData })
71
71
  const { layout, migrationRules, convertScreenToPdf = false } = parsedData.detailsConfig
72
72
 
73
73
  if (isPublic) {
@@ -161,20 +161,19 @@ export const DynamicFormButtonRender = memo(
161
161
  const generatePdfProof = useCallback(() => {
162
162
  formRef?.validateFields().then((values) => {
163
163
  const queryParams = objectToQueryParams(values)
164
- console.log(queryParams)
165
164
  const feDomainUrl = window.location.origin
166
- const fullUrl = `${feDomainUrl}/${location.pathname}?${queryParams}`
167
- console.log(fullUrl)
168
- const blobName = 'abc'
165
+ const fullUrl = encodeURIComponent(`${feDomainUrl}${location.pathname}?${queryParams}`)
166
+
167
+ const blobName = 'abc.pdf'
169
168
  client
170
- .post(`/api/attachment/pdf/${companyKey}/${fullUrl}/${blobName}`)
169
+ .post(`/api/attachment/pdf/${companyKey}/${blobName}?url=${fullUrl}`)
171
170
  .then((res) => {
172
- if (res.status < 300) {
173
- console.log(res.data)
174
- onCreateNewData(res.data)
175
- }
171
+ if (res.status < 300) onCreateNewData(res.data)
172
+ })
173
+ .catch(() => {
174
+ closeModal()
175
+ error({ message: 'Error occured while generating PDF!' })
176
176
  })
177
- .catch(() => error({ message: 'Error occured while generating PDF!' }))
178
177
  })
179
178
  }, [formRef, location.pathname, companyKey])
180
179
 
@@ -229,6 +228,7 @@ export const DynamicFormButtonRender = memo(
229
228
  case ButtonActionCategoryEnum.SaveDataChanges:
230
229
  if (formRef) {
231
230
  const signatureField = formRef.getFieldValue(FormPreservedItemKeys.HasSignature)
231
+ // to save the signature upon submission
232
232
  if (!!signatureField) {
233
233
  const signatureBase64 = formRef.getFieldValue(signatureField)
234
234
  const blobName = await saveFile(base64ToBlob(signatureBase64), 'signature', isPublic ? companyKey : '')
@@ -237,7 +237,8 @@ export const DynamicFormButtonRender = memo(
237
237
  }
238
238
 
239
239
  if (formDataId === NEW_FORM_DATA_IDENTIFIER) {
240
- if (convertScreenToPdf) {
240
+ if (isPublic && convertScreenToPdf) {
241
+ // pdf generate does not work when auth-ed
241
242
  setDataLoadingType(FormLoadingModalTypeEnum.GeneratingPdf)
242
243
  generatePdfProof()
243
244
  } else onCreateNewData()
@@ -16,7 +16,6 @@ export default function LayoutRenderer_ReCaptcha({ formRef, fieldKey, elementPro
16
16
  }
17
17
  client.get(`/api/site/${formKey}/verifycaptcha/${token}`).then((res) => {
18
18
  if (res.status < 300) {
19
- console.log('re', res.data)
20
19
  if (!res.data) formRef.setFieldValue(fieldKey, true)
21
20
  else setTokenVerificationFailed(true)
22
21
  }
@@ -39,7 +39,7 @@ export default function LayoutRenderer_FileUpload({
39
39
  onChange: async (fileInfo: any) => {
40
40
  if (fileInfo.file.status === 'done') {
41
41
  setLoading(true)
42
- const blobName = await saveFile(companyKey, fileInfo.file.originFileObj, fileInfo.file.name)
42
+ const blobName = await saveFile(fileInfo.file.originFileObj, fileInfo.file.name, companyKey)
43
43
  if (blobName) formRef.setFieldValue(fieldKey, blobName)
44
44
  setLoading(false)
45
45
  }
@@ -32,6 +32,8 @@ export default function FormDataLoadingIndicatorModal({
32
32
  <Spin spinning size="large" />
33
33
  {(() => {
34
34
  switch (currentType) {
35
+ case FormLoadingModalTypeEnum.GeneratingPdf:
36
+ return <span className="text-primary">Generating PDF...</span>
35
37
  case FormLoadingModalTypeEnum.SavingChanges:
36
38
  return <span className="text-primary">Saving data...</span>
37
39
  case FormLoadingModalTypeEnum.ErrorOccured:
@@ -1,6 +1,6 @@
1
1
  import client from './axios-handler'
2
2
 
3
- export const saveFile = async (file: any, fileName: string, companyKey: string): Promise<string | null> => {
3
+ export const saveFile = async (file: any, fileName: string, companyKey?: string): Promise<string | null> => {
4
4
  try {
5
5
  const formData = new FormData()
6
6
  formData.append('file', file, fileName)
@@ -98,7 +98,8 @@ export const base64ToBlob = (base64: string) => {
98
98
 
99
99
  export const objectToQueryParams = (obj: Record<string, any>): string =>
100
100
  Object.entries(obj)
101
- .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
101
+ .map(([key, value]) => `${key}=${value}`)
102
+ // .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
102
103
  .join('&')
103
104
 
104
105
  /** --------------------------------------------------------------------------------------------------------- */