forked from github/plane
Merge pull request #365 from makeplane/fix/workspace_settings_logo
fix: upload button on workspace settings page not working
This commit is contained in:
commit
76b615d964
@ -7,15 +7,13 @@ import useSWR, { mutate } from "swr";
|
|||||||
|
|
||||||
// react-hook-form
|
// react-hook-form
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
// react-dropzone
|
|
||||||
import Dropzone from "react-dropzone";
|
|
||||||
// icons
|
// icons
|
||||||
import { LinkIcon } from "@heroicons/react/24/outline";
|
import { LinkIcon } from "@heroicons/react/24/outline";
|
||||||
// lib
|
// lib
|
||||||
import { requiredWorkspaceAdmin } from "lib/auth";
|
import { requiredWorkspaceAdmin } from "lib/auth";
|
||||||
// services
|
// services
|
||||||
import workspaceService from "services/workspace.service";
|
import workspaceService from "services/workspace.service";
|
||||||
import fileServices from "services/file.service";
|
|
||||||
// layouts
|
// layouts
|
||||||
import AppLayout from "layouts/app-layout";
|
import AppLayout from "layouts/app-layout";
|
||||||
// hooks
|
// hooks
|
||||||
@ -52,7 +50,6 @@ type TWorkspaceSettingsProps = {
|
|||||||
|
|
||||||
const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [image, setImage] = useState<File | null>(null);
|
|
||||||
const [isImageUploading, setIsImageUploading] = useState(false);
|
const [isImageUploading, setIsImageUploading] = useState(false);
|
||||||
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
||||||
|
|
||||||
@ -122,9 +119,11 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
<ImageUploadModal
|
<ImageUploadModal
|
||||||
isOpen={isImageUploadModalOpen}
|
isOpen={isImageUploadModalOpen}
|
||||||
onClose={() => setIsImageUploadModalOpen(false)}
|
onClose={() => setIsImageUploadModalOpen(false)}
|
||||||
onSuccess={() => {
|
onSuccess={(imageUrl) => {
|
||||||
|
setIsImageUploading(true);
|
||||||
|
setValue("logo", imageUrl);
|
||||||
setIsImageUploadModalOpen(false);
|
setIsImageUploadModalOpen(false);
|
||||||
handleSubmit(onSubmit)();
|
handleSubmit(onSubmit)().then(() => setIsImageUploading(false));
|
||||||
}}
|
}}
|
||||||
value={watch("logo")}
|
value={watch("logo")}
|
||||||
/>
|
/>
|
||||||
@ -147,24 +146,11 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
<div className="col-span lg:col-span-5">
|
<div className="col-span lg:col-span-5">
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Logo</h4>
|
<h4 className="text-md mb-1 leading-6 text-gray-900">Logo</h4>
|
||||||
<div className="flex w-full gap-2">
|
<div className="flex w-full gap-2">
|
||||||
<Dropzone
|
<button type="button" onClick={() => setIsImageUploadModalOpen(true)}>
|
||||||
multiple={false}
|
{watch("logo") && watch("logo") !== null && watch("logo") !== "" ? (
|
||||||
accept={{
|
|
||||||
"image/*": [],
|
|
||||||
}}
|
|
||||||
onDrop={(files) => {
|
|
||||||
setImage(files[0]);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{({ getRootProps, getInputProps }) => (
|
|
||||||
<div>
|
|
||||||
<input {...getInputProps()} />
|
|
||||||
<div {...getRootProps()}>
|
|
||||||
{(watch("logo") && watch("logo") !== null && watch("logo") !== "") ||
|
|
||||||
(image && image !== null) ? (
|
|
||||||
<div className="relative mx-auto flex h-12 w-12">
|
<div className="relative mx-auto flex h-12 w-12">
|
||||||
<Image
|
<Image
|
||||||
src={image ? URL.createObjectURL(image) : watch("logo") ?? ""}
|
src={watch("logo")!}
|
||||||
alt="Workspace Logo"
|
alt="Workspace Logo"
|
||||||
objectFit="cover"
|
objectFit="cover"
|
||||||
layout="fill"
|
layout="fill"
|
||||||
@ -177,32 +163,14 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
{activeWorkspace?.name?.charAt(0) ?? "N"}
|
{activeWorkspace?.name?.charAt(0) ?? "N"}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</button>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Dropzone>
|
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2 text-sm text-gray-500">
|
<p className="mb-2 text-sm text-gray-500">
|
||||||
Max file size is 5MB. Supported file types are .jpg and .png.
|
Max file size is 5MB. Supported file types are .jpg and .png.
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (image === null) return;
|
setIsImageUploadModalOpen(true);
|
||||||
setIsImageUploading(true);
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("asset", image);
|
|
||||||
formData.append("attributes", JSON.stringify({}));
|
|
||||||
fileServices
|
|
||||||
.uploadFile(workspaceSlug as string, formData)
|
|
||||||
.then((response) => {
|
|
||||||
const imageUrl = response.asset;
|
|
||||||
setValue("logo", imageUrl);
|
|
||||||
handleSubmit(onSubmit)();
|
|
||||||
setIsImageUploading(false);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setIsImageUploading(false);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isImageUploading ? "Uploading..." : "Upload"}
|
{isImageUploading ? "Uploading..." : "Upload"}
|
||||||
|
Loading…
Reference in New Issue
Block a user