Skip to content

Commit

Permalink
Merge pull request #406 from gsainfoteam/400-bug-call-upload-image-ap…
Browse files Browse the repository at this point in the history
…i-when-there-is-no-image-in-a-notice

🚸 Prevent redundant image upload api call
  • Loading branch information
dohyun-ko authored Jan 8, 2025
2 parents 34d589c + 599c4a2 commit 0e02ee7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/api/image/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { ziggleApi } from '..';
export const uploadImages = async (images: File[]) => {
const fd = new FormData();
images.forEach((image) => fd.append('images', image));
const { data } = await ziggleApi.post('/image/upload', fd);
const { data } = await ziggleApi.post<string[]>('/image/upload', fd);
return data;
};
3 changes: 2 additions & 1 deletion src/app/[lng]/write/handle-notice-submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ const handleNoticeSubmit = async ({
const tagIds: number[] | undefined = await handleTagSubmit(tags, t);
if (!tagIds) return;

const imageKeys = await uploadImages(images).catch(() => null);
const imageKeys =
images.length > 0 ? await uploadImages(images).catch(() => null) : [];
if (!imageKeys) {
Swal.fire({
text: t('write.alerts.submitFail'),
Expand Down

0 comments on commit 0e02ee7

Please sign in to comment.