form-craft-package 1.11.4 → 1.11.5-dev.0

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.11.4",
3
+ "version": "1.11.5-dev.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -4,7 +4,7 @@ import { saveFile } from '../../../../../functions/forms/form'
4
4
  import { TranslationTextSubTypeEnum, TranslationTextTypeEnum } from '../../../../../enums'
5
5
  import { RcFile, UploadFile, UploadProps } from 'antd/es/upload'
6
6
  import { Form, Modal, Spin, Upload } from 'antd'
7
- import { useCallback, useMemo, useState } from 'react'
7
+ import { useCallback, useEffect, useMemo, useState } from 'react'
8
8
  import { FaUpload } from 'react-icons/fa6'
9
9
  import { Button_FillerPortal } from '../../../../common/button'
10
10
  import { useNotification, useTranslation } from '../../../../common/custom-hooks'
@@ -77,15 +77,19 @@ export default function GalleryUploadModal({
77
77
  [elementKey, label, placeholder, t],
78
78
  )
79
79
 
80
- const uploadedBlobNames = useMemo(
80
+ const uploadedBlobNames = useMemo(
81
81
  () =>
82
82
  uploadedFiles
83
83
  .map((file) =>
84
84
  typeof file.response === 'object' && file.response ? (file.response as { blobName?: string }).blobName : '',
85
85
  )
86
86
  .filter((blobName): blobName is string => !!blobName),
87
- [uploadedFiles],
88
- )
87
+ [uploadedFiles],
88
+ )
89
+
90
+ useEffect(() => {
91
+ if (!isOpen) setUploadedFiles([])
92
+ }, [isOpen])
89
93
 
90
94
  const uploadProps: UploadProps = {
91
95
  multiple: true,
@@ -108,13 +112,14 @@ export default function GalleryUploadModal({
108
112
  },
109
113
  }
110
114
 
111
- const discardUploadedFiles = useCallback(async () => {
112
- setIsDiscarding(true)
113
- try {
114
- await Promise.all(uploadedBlobNames.map((blobName) => client.delete(`/api/attachment/${blobName}`)))
115
- onDiscardSuccess()
116
- } finally {
117
- setIsDiscarding(false)
115
+ const discardUploadedFiles = useCallback(async () => {
116
+ setIsDiscarding(true)
117
+ try {
118
+ await Promise.all(uploadedBlobNames.map((blobName) => client.delete(`/api/attachment/${blobName}`)))
119
+ setUploadedFiles([])
120
+ onDiscardSuccess()
121
+ } finally {
122
+ setIsDiscarding(false)
118
123
  }
119
124
  }, [onDiscardSuccess, uploadedBlobNames])
120
125
 
@@ -135,16 +140,19 @@ export default function GalleryUploadModal({
135
140
  ...(Array.isArray(existingBlobNames) ? existingBlobNames : []),
136
141
  ...uploadedBlobNames,
137
142
  ]
138
- const res = await client.put(`/api/formdata/${formId}/${formDataId}`, {
139
- name: formDataRes.data.name,
140
- version: formDataRes.data.version,
141
- private: formDataRes.data.private,
142
- data: JSON.stringify(parsedData),
143
- })
144
- if (res.status === 200) onSaveSuccess(uploadedBlobNames)
145
- } finally {
146
- setIsSaving(false)
147
- }
143
+ const res = await client.put(`/api/formdata/${formId}/${formDataId}`, {
144
+ name: formDataRes.data.name,
145
+ version: formDataRes.data.version,
146
+ private: formDataRes.data.private,
147
+ data: JSON.stringify(parsedData),
148
+ })
149
+ if (res.status === 200) {
150
+ setUploadedFiles([])
151
+ onSaveSuccess(uploadedBlobNames)
152
+ }
153
+ } finally {
154
+ setIsSaving(false)
155
+ }
148
156
  }, [formDataId, formId, formItem.path, onSaveSuccess, uploadedBlobNames])
149
157
 
150
158
  return (