Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

reuse aftersubmit handler

Oleg Isonen55f996878a7d
diff --git a/apps/designer/app/designer/shared/assets/use-assets.ts b/apps/designer/app/designer/shared/assets/use-assets.ts
index a6b3488b1d..06cc1f44a7 100644
--- a/apps/designer/app/designer/shared/assets/use-assets.ts
+++ b/apps/designer/app/designer/shared/assets/use-assets.ts
@@ -122,17 +122,28 @@ export const useAssets = (type: AssetType) => {
}
}, [data, setAssets]);
- const handleDelete = (ids: Array<string>) => {
- if (action === undefined) {
- return;
+ const handleAfterSubmit = (data: UploadData) => {
+ if (data.status === "error") {
+ return toastUnknownFieldErrors(normalizeErrors(data.errors), []);
+ }
+
+ // @todo currently waiting until all of them are fetched
+ // should update each individually when its loaded
+ if (action) {
+ load(action);
}
+ };
+
+ const handleDelete = (ids: Array<string>) => {
const formData = new FormData();
for (const id of ids) {
formData.append("assetId", id);
}
- submit(formData, { method: "delete", action }, () => {
- load(action);
- });
+ submit<UploadData>(
+ formData,
+ { method: "delete", action },
+ handleAfterSubmit
+ );
};
const handleSubmit = (input: HTMLInputElement) => {
@@ -155,17 +166,7 @@ export const useAssets = (type: AssetType) => {
action,
encType: "multipart/form-data",
},
- (data) => {
- if (data.status === "error") {
- return toastUnknownFieldErrors(normalizeErrors(data.errors), []);
- }
-
- // @todo currently waiting until all of them are fetched
- // should update each individually when its loaded
- if (action) {
- load(action);
- }
- }
+ handleAfterSubmit
);
}
};