create product
This commit is contained in:
@@ -6,3 +6,9 @@ export const useSingleUpload = () => {
|
||||
mutationFn: api.singleUpload,
|
||||
});
|
||||
};
|
||||
|
||||
export const useMultiUpload = () => {
|
||||
return useMutation({
|
||||
mutationFn: api.multiUpload,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { SingleUploadResponseType } from "../types/Types";
|
||||
import type {
|
||||
MultiUploadResponseType,
|
||||
SingleUploadResponseType,
|
||||
} from "../types/Types";
|
||||
|
||||
export const singleUpload = async (file: File) => {
|
||||
const formData = new FormData();
|
||||
@@ -10,3 +13,15 @@ export const singleUpload = async (file: File) => {
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const multiUpload = async (files: File[]) => {
|
||||
const formData = new FormData();
|
||||
files?.map((file) => {
|
||||
formData.append("files", file);
|
||||
});
|
||||
const { data } = await axios.post<MultiUploadResponseType>(
|
||||
"/admin/multi-file",
|
||||
formData,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -10,3 +10,4 @@ export type SingleUploadType = {
|
||||
};
|
||||
|
||||
export type SingleUploadResponseType = BaseResponse<SingleUploadType>;
|
||||
export type MultiUploadResponseType = BaseResponse<SingleUploadType[]>;
|
||||
|
||||
Reference in New Issue
Block a user