import React, { useEffect, useState } from "react"; // next import Image from "next/image"; // react hook form import { useForm } from "react-hook-form"; // react dropzone import Dropzone from "react-dropzone"; // services import workspaceService from "lib/services/workspace.service"; import fileServices from "lib/services/file.services"; // layouts import ProjectLayout from "layouts/ProjectLayout"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // components import ConfirmWorkspaceDeletion from "components/workspace/ConfirmWorkspaceDeletion"; // ui import { Spinner, Button, Input, Select } from "ui"; import { BreadcrumbItem, Breadcrumbs } from "ui/Breadcrumbs"; // types import type { IWorkspace } from "types"; const defaultValues: Partial = { name: "", }; const WorkspaceSettings = () => { const { activeWorkspace, mutateWorkspaces } = useUser(); const { setToastAlert } = useToast(); const [isOpen, setIsOpen] = useState(false); const [image, setImage] = useState(null); const [isImageUploading, setIsImageUploading] = useState(false); const { register, handleSubmit, reset, watch, setValue, formState: { errors, isSubmitting }, } = useForm({ defaultValues: { ...defaultValues, ...activeWorkspace }, }); useEffect(() => { activeWorkspace && reset({ ...activeWorkspace }); }, [activeWorkspace, reset]); const onSubmit = async (formData: IWorkspace) => { if (!activeWorkspace) return; const payload: Partial = { logo: formData.logo, name: formData.name, company_size: formData.company_size, }; await workspaceService .updateWorkspace(activeWorkspace.slug, payload) .then(async (res) => { await mutateWorkspaces((workspaces) => { return (workspaces ?? []).map((workspace) => { if (workspace.slug === activeWorkspace.slug) { return { ...workspace, ...res, }; } return workspace; }); }, false); setToastAlert({ title: "Success", type: "success", message: "Workspace updated successfully", }); }) .catch((err) => console.log(err)); }; return (
{activeWorkspace ? (

General

This information will be displayed to every member of the workspace.

{ setImage(files[0]); }} > {({ getRootProps, getInputProps }) => (
Logo
{((watch("logo") && watch("logo") !== null && watch("logo") !== "") || (image && image !== null)) && (
Workspace Logo
)}

Max file size is 500kb. Supported file types are .jpg and .png.

)}