import React, { useEffect, useState } from "react"; // next import Image from "next/image"; // react hook form import { useForm } from "react-hook-form"; // headless ui import { Tab } from "@headlessui/react"; // react dropzone import Dropzone from "react-dropzone"; // services import workspaceService from "lib/services/workspace.service"; import fileServices from "lib/services/file.service"; // hoc import withAuth from "lib/hoc/withAuthWrapper"; // layouts import AppLayout from "layouts/AppLayout"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // components import ConfirmWorkspaceDeletion from "components/workspace/confirm-workspace-deletion"; // 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 ( { setIsOpen(false); }} data={activeWorkspace ?? null} />
{activeWorkspace ? (
{["General", "Actions"].map((tab, index) => ( `text-md leading-6 text-gray-900 px-4 py-1 rounded outline-none ${ selected ? "bg-gray-700 text-white" : "hover:bg-gray-200" } duration-300` } > {tab} ))}
{ 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.

)}