mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: update remove file function logic (#1259)
* chore: update remove file function logic * fix: workspace file delete endpoint
This commit is contained in:
parent
d09f410f21
commit
e7af3da115
@ -9,6 +9,8 @@ import { useDropzone } from "react-dropzone";
|
|||||||
import { Transition, Dialog } from "@headlessui/react";
|
import { Transition, Dialog } from "@headlessui/react";
|
||||||
// services
|
// services
|
||||||
import fileServices from "services/file.service";
|
import fileServices from "services/file.service";
|
||||||
|
// hooks
|
||||||
|
import useWorkspaceDetails from "hooks/use-workspace-details";
|
||||||
// ui
|
// ui
|
||||||
import { PrimaryButton, SecondaryButton } from "components/ui";
|
import { PrimaryButton, SecondaryButton } from "components/ui";
|
||||||
// icons
|
// icons
|
||||||
@ -35,6 +37,8 @@ export const ImageUploadModal: React.FC<Props> = ({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug } = router.query;
|
const { workspaceSlug } = router.query;
|
||||||
|
|
||||||
|
const { workspaceDetails } = useWorkspaceDetails();
|
||||||
|
|
||||||
const onDrop = useCallback((acceptedFiles: File[]) => {
|
const onDrop = useCallback((acceptedFiles: File[]) => {
|
||||||
setImage(acceptedFiles[0]);
|
setImage(acceptedFiles[0]);
|
||||||
}, []);
|
}, []);
|
||||||
@ -62,12 +66,7 @@ export const ImageUploadModal: React.FC<Props> = ({
|
|||||||
setIsImageUploading(false);
|
setIsImageUploading(false);
|
||||||
setImage(null);
|
setImage(null);
|
||||||
|
|
||||||
if (value) {
|
if (value) fileServices.deleteUserFile(value);
|
||||||
const index = value.indexOf(".com");
|
|
||||||
const asset = value.substring(index + 5);
|
|
||||||
|
|
||||||
fileServices.deleteUserFile(asset);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -81,12 +80,7 @@ export const ImageUploadModal: React.FC<Props> = ({
|
|||||||
setIsImageUploading(false);
|
setIsImageUploading(false);
|
||||||
setImage(null);
|
setImage(null);
|
||||||
|
|
||||||
if (value) {
|
if (value && workspaceDetails) fileServices.deleteFile(workspaceDetails.id, value);
|
||||||
const index = value.indexOf(".com");
|
|
||||||
const asset = value.substring(index + 5);
|
|
||||||
|
|
||||||
fileServices.deleteFile(asset);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -90,10 +90,7 @@ const Profile: NextPage = () => {
|
|||||||
|
|
||||||
setIsRemoving(true);
|
setIsRemoving(true);
|
||||||
|
|
||||||
const index = url.indexOf(".com");
|
fileService.deleteUserFile(url).then(() => {
|
||||||
const asset = url.substring(index + 5);
|
|
||||||
|
|
||||||
fileService.deleteUserFile(asset).then(() => {
|
|
||||||
if (updateUser)
|
if (updateUser)
|
||||||
userService
|
userService
|
||||||
.updateUser({ avatar: "" })
|
.updateUser({ avatar: "" })
|
||||||
|
@ -111,10 +111,7 @@ const WorkspaceSettings: NextPage = () => {
|
|||||||
|
|
||||||
setIsImageRemoving(true);
|
setIsImageRemoving(true);
|
||||||
|
|
||||||
const index = url.indexOf(".com");
|
fileService.deleteFile(activeWorkspace.id, url).then(() => {
|
||||||
const asset = url.substring(index + 5);
|
|
||||||
|
|
||||||
fileService.deleteFile(asset).then(() => {
|
|
||||||
workspaceService
|
workspaceService
|
||||||
.updateWorkspace(activeWorkspace.slug, { logo: "" }, user)
|
.updateWorkspace(activeWorkspace.slug, { logo: "" }, user)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
@ -40,8 +40,11 @@ class FileServices extends APIService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteFile(asset: string): Promise<any> {
|
async deleteFile(workspaceId: string, assetUrl: string): Promise<any> {
|
||||||
return this.delete(`/api/workspaces/file-assets/${asset}/`)
|
const lastIndex = assetUrl.lastIndexOf("/");
|
||||||
|
const assetId = assetUrl.substring(lastIndex + 1);
|
||||||
|
|
||||||
|
return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetId}/`)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
@ -56,8 +59,11 @@ class FileServices extends APIService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUserFile(asset: string): Promise<any> {
|
async deleteUserFile(assetUrl: string): Promise<any> {
|
||||||
return this.delete(`/api/users/file-assets/${asset}`)
|
const lastIndex = assetUrl.lastIndexOf("/");
|
||||||
|
const assetId = assetUrl.substring(lastIndex + 1);
|
||||||
|
|
||||||
|
return this.delete(`/api/users/file-assets/${assetId}`)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
|
Loading…
Reference in New Issue
Block a user