Skip to content

Commit

Permalink
feat: update project cover image (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshesh14 authored Apr 6, 2023
1 parent 95fe4a3 commit c49f614
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";

import Image from "next/image";
import { useRouter } from "next/router";

import useSWR, { mutate } from "swr";
Expand All @@ -15,6 +16,7 @@ import AppLayout from "layouts/app-layout";
import projectService from "services/project.service";
// components
import { DeleteProjectModal } from "components/project";
import { ImageUploadModal } from "components/core";
import EmojiIconPicker from "components/emoji-icon-picker";
// hooks
import useToast from "hooks/use-toast";
Expand Down Expand Up @@ -44,6 +46,8 @@ const defaultValues: Partial<IProject> = {

const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGuest }) => {
const [selectProject, setSelectedProject] = useState<string | null>(null);
const [isImageUploading, setIsImageUploading] = useState(false);
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);

const { setToastAlert } = useToast();

Expand All @@ -61,7 +65,9 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
register,
handleSubmit,
reset,
watch,
control,
setValue,
setError,
formState: { errors, isSubmitting },
} = useForm<IProject>({
Expand Down Expand Up @@ -116,6 +122,7 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
default_assignee: formData.default_assignee,
project_lead: formData.project_lead,
icon: formData.icon,
cover_image: formData.cover_image,
};

if (projectDetails.identifier !== formData.identifier)
Expand Down Expand Up @@ -150,6 +157,17 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
router.push(`/${workspaceSlug}/projects`);
}}
/>
<ImageUploadModal
isOpen={isImageUploadModalOpen}
onClose={() => setIsImageUploadModalOpen(false)}
onSuccess={(imageUrl) => {
setIsImageUploading(true);
setValue("cover_image", imageUrl);
setIsImageUploadModalOpen(false);
handleSubmit(onSubmit)().then(() => setIsImageUploading(false));
}}
value={watch("cover_image")}
/>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="space-y-8 sm:space-y-12">
<div className="grid grid-cols-12 items-start gap-4 sm:gap-16">
Expand Down Expand Up @@ -216,6 +234,40 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
)}
</div>
</div>
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Cover Photo</h4>
<p className="text-gray-500">Select your cover photo from the given library.</p>
</div>
<div className="col-span-12 sm:col-span-6">
{watch("cover_image") ? (
<div className="w-32 h-32 rounded border p-1">
<div className="w-full h-full relative rounded">
<Image
src={watch("cover_image")!}
alt={projectDetails?.name ?? "Cover image"}
objectFit="cover"
layout="fill"
/>
<div className="absolute bottom-1 w-full flex justify-center">
<button
type="button"
disabled={isImageUploading}
onClick={() => setIsImageUploadModalOpen(true)}
className="bg-white rounded text-sm border-2 border-gray-300 text-gray-400 p-1 py-0.5"
>
{isImageUploading ? "Uploading..." : "Change Cover"}
</button>
</div>
</div>
</div>
) : (
<Loader className="w-full">
<Loader.Item height="46px" width="full" light />
</Loader>
)}
</div>
</div>
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Identifier</h4>
Expand Down

1 comment on commit c49f614

@vercel
Copy link

@vercel vercel bot commented on c49f614 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev-git-develop-caravel.vercel.app
plane-dev.vercel.app
plane-dev-caravel.vercel.app

Please sign in to comment.