Skip to content

Commit

Permalink
fix: project cover image upload (#1704)
Browse files Browse the repository at this point in the history
* fix: popover close on image upload

* fix: removed comments
  • Loading branch information
dakshesh14 committed Jul 31, 2023
1 parent 6769d11 commit 4fb11cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions apps/app/components/core/image-picker-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import { Tab, Transition, Popover } from "@headlessui/react";
import fileService from "services/file.service";

// components
import { Input, Spinner, PrimaryButton } from "components/ui";
import { Input, Spinner, PrimaryButton, SecondaryButton } from "components/ui";
// hooks
import useWorkspaceDetails from "hooks/use-workspace-details";
import useOutsideClickDetector from "hooks/use-outside-click-detector";

const unsplashEnabled =
process.env.NEXT_PUBLIC_UNSPLASH_ENABLED === "true" ||
Expand Down Expand Up @@ -64,10 +63,6 @@ export const ImagePickerPopover: React.FC<Props> = ({ label, value, onChange })

const { workspaceDetails } = useWorkspaceDetails();

useOutsideClickDetector(ref, () => {
setIsOpen(false);
});

const onDrop = useCallback((acceptedFiles: File[]) => {
setImage(acceptedFiles[0]);
}, []);
Expand Down Expand Up @@ -95,6 +90,7 @@ export const ImagePickerPopover: React.FC<Props> = ({ label, value, onChange })
onChange(imageUrl);
setIsImageUploading(false);
setImage(null);
setIsOpen(false);

if (isUnsplashImage) return;

Expand Down Expand Up @@ -130,7 +126,7 @@ export const ImagePickerPopover: React.FC<Props> = ({ label, value, onChange })
leaveTo="transform opacity-0 scale-95"
>
<Popover.Panel className="absolute right-0 z-10 mt-2 rounded-md border border-custom-border-200 bg-custom-background-80 shadow-lg">
<div className="h-96 flex flex-col w-80 overflow-auto rounded border border-custom-border-300 bg-custom-background-100 p-3 shadow-2xl sm:max-w-2xl md:w-96 lg:w-[40rem]">
<div className="h-96 md:h-[28rem] w-80 md:w-[36rem] flex flex-col overflow-auto rounded border border-custom-border-300 bg-custom-background-100 p-3 shadow-2xl">
<Tab.Group>
<div>
<Tab.List as="span" className="inline-block rounded bg-custom-background-80 p-1">
Expand Down Expand Up @@ -188,12 +184,12 @@ export const ImagePickerPopover: React.FC<Props> = ({ label, value, onChange })
</div>
)}
</Tab.Panel>
<Tab.Panel className="h-full w-full flex flex-col items-center justify-center">
<div className="w-full h-full flex flex-col py-5">
<Tab.Panel className="h-full w-full pt-5">
<div className="w-full h-full flex flex-col gap-y-5 sm:gap-y-5">
<div className="flex items-center gap-3 w-full flex-1">
<div
{...getRootProps()}
className={`relative grid h-80 w-full cursor-pointer place-items-center rounded-lg p-12 text-center focus:outline-none focus:ring-2 focus:ring-custom-primary focus:ring-offset-2 ${
className={`relative grid h-full w-full cursor-pointer place-items-center rounded-lg p-12 text-center focus:outline-none focus:ring-2 focus:ring-custom-primary focus:ring-offset-2 ${
(image === null && isDragActive) || !value
? "border-2 border-dashed border-custom-border-200 hover:bg-custom-background-90"
: ""
Expand Down Expand Up @@ -229,8 +225,18 @@ export const ImagePickerPopover: React.FC<Props> = ({ label, value, onChange })
</div>
</div>

<div className="mt-5 sm:mt-6 flex justify-end flex-auto">
<div className="sm:grid sm:grid-flow-row-dense sm:grid-cols-2 sm:gap-3">
<SecondaryButton
className="w-full"
onClick={() => {
setIsOpen(false);
setImage(null);
}}
>
Cancel
</SecondaryButton>
<PrimaryButton
className="w-full"
onClick={handleSubmit}
disabled={!image}
loading={isImageUploading}
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/project/create-project-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const CreateProjectModal: React.FC<Props> = ({ isOpen, setIsOpen, user })
<XMarkIcon className="h-5 w-5 text-white" />
</button>
</div>
<div className="hidden group-hover:block absolute bottom-2 right-2">
<div className="absolute bottom-2 right-2">
<ImagePickerPopover
label="Change Cover"
onChange={(image) => {
Expand Down

0 comments on commit 4fb11cb

Please sign in to comment.