import React from "react"; // next import type { NextPage } from "next"; import { useRouter } from "next/router"; // react hook form import { useForm } from "react-hook-form"; // services import workspaceService from "lib/services/workspace.service"; // hooks import useUser from "lib/hooks/useUser"; // hoc import withAuth from "lib/hoc/withAuthWrapper"; // layouts import DefaultLayout from "layouts/DefaultLayout"; // ui import { Input, Button, Select } from "ui"; // types import type { IWorkspace } from "types"; const CreateWorkspace: NextPage = () => { const { register, handleSubmit, setError, formState: { errors, isSubmitting }, } = useForm({ defaultValues: { name: "", }, }); const router = useRouter(); const { mutateWorkspaces, user } = useUser(); const onSubmit = async (formData: IWorkspace) => { await workspaceService .createWorkspace(formData) .then((res) => { console.log(res); mutateWorkspaces((prevData) => [...(prevData ?? []), res], false); router.push("/"); }) .catch((err) => { Object.keys(err).map((key) => { const errorMessage = err[key]; setError(key as keyof IWorkspace, { message: Array.isArray(errorMessage) ? errorMessage.join(", ") : errorMessage, }); }); }); }; // const workspaceName = watch("name") ?? ""; // useEffect(() => { // workspaceName && workspaceName !== "" // ? setValue( // "url", // `${window.location.origin}/${workspaceName // .toLowerCase() // .replace(/ /g, "")}` // ) // : setValue("url", workspaceName); // }, [workspaceName, setValue]); return (
{user && (

logged in as {user.email}

)}

Create a new workspace

{/*