mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 22:28:47 +00:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { apiRequest } from "@app/config/request";
|
|
|
|
import { workspaceKeys } from "../workspace";
|
|
|
|
export const useImportEnvKey = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ file, decryptionKey }: { file: File; decryptionKey: string }) => {
|
|
const formData = new FormData();
|
|
|
|
formData.append("decryptionKey", decryptionKey);
|
|
formData.append("file", file);
|
|
|
|
try {
|
|
const response = await apiRequest.post("/api/v3/migrate/env-key/", formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data"
|
|
},
|
|
onUploadProgress: (progressEvent) => {
|
|
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
console.log(`Upload Progress: ${percentCompleted}%`);
|
|
}
|
|
});
|
|
|
|
console.log("Upload successful:", response.data);
|
|
} catch (error) {
|
|
console.error("Upload failed:", error);
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(workspaceKeys.getAllUserWorkspace);
|
|
}
|
|
});
|
|
};
|