diff --git a/apps/app/components/core/image-upload-modal.tsx b/apps/app/components/core/image-upload-modal.tsx index a0077858e..6e68394b8 100644 --- a/apps/app/components/core/image-upload-modal.tsx +++ b/apps/app/components/core/image-upload-modal.tsx @@ -19,11 +19,16 @@ type TImageUploadModalProps = { onClose: () => void; isOpen: boolean; onSuccess: (url: string) => void; + userImage?: boolean; }; -export const ImageUploadModal: React.FC = (props) => { - const { value, onSuccess, isOpen, onClose } = props; - +export const ImageUploadModal: React.FC = ({ + value, + onSuccess, + isOpen, + onClose, + userImage, +}) => { const [image, setImage] = useState(null); const [isImageUploading, setIsImageUploading] = useState(false); @@ -46,22 +51,34 @@ export const ImageUploadModal: React.FC = (props) => { const handleSubmit = async () => { setIsImageUploading(true); - if (image === null || !workspaceSlug) return; + if (!image || !workspaceSlug) return; const formData = new FormData(); formData.append("asset", image); formData.append("attributes", JSON.stringify({})); - fileServices - .uploadFile(workspaceSlug as string, formData) - .then((res) => { - const imageUrl = res.asset; - onSuccess(imageUrl); - setIsImageUploading(false); - }) - .catch((err) => { - console.error(err); - }); + if (userImage) { + fileServices + .uploadUserFile(formData) + .then((res) => { + const imageUrl = res.asset; + onSuccess(imageUrl); + setIsImageUploading(false); + }) + .catch((err) => { + console.error(err); + }); + } else + fileServices + .uploadFile(workspaceSlug as string, formData) + .then((res) => { + const imageUrl = res.asset; + onSuccess(imageUrl); + setIsImageUploading(false); + }) + .catch((err) => { + console.error(err); + }); }; const handleClose = () => { @@ -109,11 +126,10 @@ export const ImageUploadModal: React.FC = (props) => { : "" }`} > - {image !== null || (value && value !== null && value !== "") ? ( + {image !== null || (value && value !== "") ? ( <> +
+ + {myProfile.avatar && myProfile.avatar !== "" && ( + + )} +
@@ -259,7 +279,7 @@ const Profile: NextPage = () => {

Quick Links

-
+
{quickLinks.map((item, index) => ( diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx index 986b2ac5f..90d04bf35 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx @@ -81,7 +81,8 @@ const SingleCycle: React.FC = (props) => { const cycleStatus = cycleDetails?.start_date && cycleDetails?.end_date - ? getDateRangeStatus(cycleDetails?.start_date, cycleDetails?.end_date) : ""; + ? getDateRangeStatus(cycleDetails?.start_date, cycleDetails?.end_date) + : ""; const { data: cycleIssues } = useSWR( workspaceSlug && projectId && cycleId ? CYCLE_ISSUES(cycleId as string) : null, diff --git a/apps/app/pages/[workspaceSlug]/settings/index.tsx b/apps/app/pages/[workspaceSlug]/settings/index.tsx index 31ce42f1f..1c638155a 100644 --- a/apps/app/pages/[workspaceSlug]/settings/index.tsx +++ b/apps/app/pages/[workspaceSlug]/settings/index.tsx @@ -14,10 +14,11 @@ import { LinkIcon } from "@heroicons/react/24/outline"; import { requiredWorkspaceAdmin } from "lib/auth"; // services import workspaceService from "services/workspace.service"; -// layouts -import AppLayout from "layouts/app-layout"; +import fileService from "services/file.service"; // hooks import useToast from "hooks/use-toast"; +// layouts +import AppLayout from "layouts/app-layout"; // components import { ImageUploadModal } from "components/core"; import { DeleteWorkspaceModal } from "components/workspace"; @@ -96,6 +97,15 @@ const WorkspaceSettings: NextPage = (props) => { .catch((err) => console.error(err)); }; + const handleDelete = (url: string | null | undefined) => { + if (!url) return; + + const index = url.indexOf(".com"); + const asset = url.substring(index + 5); + + fileService.deleteFile(asset); + }; + return ( = (props) => { onClose={() => setIsImageUploadModalOpen(false)} onSuccess={(imageUrl) => { setIsImageUploading(true); + handleDelete(activeWorkspace?.logo); setValue("logo", imageUrl); setIsImageUploadModalOpen(false); handleSubmit(onSubmit)().then(() => setIsImageUploading(false)); diff --git a/apps/app/services/file.service.ts b/apps/app/services/file.service.ts index 5f96a663d..044e625ac 100644 --- a/apps/app/services/file.service.ts +++ b/apps/app/services/file.service.ts @@ -40,6 +40,30 @@ class FileServices extends APIService { }); } + async deleteFile(asset: string): Promise { + return this.delete(`/api/workspaces/file-assets/${asset}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + + async uploadUserFile(file: FormData): Promise { + return this.mediaUpload(`/api/users/file-assets/`, file) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + + async deleteUserFile(asset: string): Promise { + return this.delete(`/api/users/file-assets/${asset}`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + async getUnsplashImages(page: number = 1, query?: string): Promise { const clientId = process.env.NEXT_PUBLIC_UNSPLASH_ACCESS; const url = query @@ -50,9 +74,7 @@ class FileServices extends APIService { method: "get", url, }) - .then((response) => { - return response?.data?.results ?? response?.data; - }) + .then((response) => response?.data?.results ?? response?.data) .catch((error) => { throw error?.response?.data; }); diff --git a/turbo.json b/turbo.json index 98de1bca0..4b033cd68 100644 --- a/turbo.json +++ b/turbo.json @@ -12,7 +12,8 @@ "NEXT_PUBLIC_SENTRY_ENVIRONMENT", "NEXT_PUBLIC_GITHUB_APP_NAME", "NEXT_PUBLIC_ENABLE_SENTRY", - "NEXT_PUBLIC_ENABLE_OAUTH" + "NEXT_PUBLIC_ENABLE_OAUTH", + "NEXT_PUBLIC_UNSPLASH_ACCESS" ], "pipeline": { "build": {