feat: workspace description

This commit is contained in:
Henry
2025-01-05 14:27:19 +00:00
parent f1b0860734
commit fa9be9d280
13 changed files with 1653 additions and 14 deletions

View File

@@ -55,13 +55,10 @@ export default async function handler(req: NextRequest) {
const metaData = checkoutSession.metadata;
if (metaData?.workspacePublicId && metaData.username) {
await workspaceRepo.update(
db,
metaData.workspacePublicId,
undefined,
metaData.username,
"pro",
);
await workspaceRepo.update(db, metaData.workspacePublicId, {
slug: metaData.username,
plan: "pro",
});
}
break;
}

View File

@@ -13,6 +13,7 @@ interface WorkspaceContextProps {
interface Workspace {
name: string;
description: string | null;
publicId: string;
slug: string;
plan: "free" | "pro" | "enterprise";
@@ -20,6 +21,7 @@ interface Workspace {
const initialWorkspace: Workspace = {
name: "",
description: null,
publicId: "",
slug: "",
plan: "free",
@@ -65,6 +67,7 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
publicId: workspace.publicId,
name: workspace.name,
slug: workspace.slug,
description: workspace.description,
plan: workspace.plan,
};
})
@@ -86,6 +89,7 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
name: selectedWorkspace.workspace.name,
slug: selectedWorkspace.workspace.slug,
plan: selectedWorkspace.workspace.plan,
description: selectedWorkspace.workspace.description,
});
} else {
const primaryWorkspace = data[0]?.workspace;
@@ -96,6 +100,7 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
name: primaryWorkspace.name,
slug: primaryWorkspace.slug,
plan: primaryWorkspace.plan,
description: primaryWorkspace.description,
});
}
}, [data]);

View File

@@ -0,0 +1,87 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import Button from "~/components/Button";
import Input from "~/components/Input";
import { usePopup } from "~/providers/popup";
import { api } from "~/utils/api";
const schema = z.object({
description: z
.string()
.min(3, {
message: "Workspace description must be at least 3 characters long",
})
.max(280, {
message: "Workspace description cannot exceed 280 characters",
}),
});
type FormValues = z.infer<typeof schema>;
const UpdateWorkspaceDescriptionForm = ({
workspacePublicId,
workspaceDescription,
}: {
workspacePublicId: string;
workspaceDescription: string;
}) => {
const utils = api.useUtils();
const { showPopup } = usePopup();
const {
register,
handleSubmit,
formState: { isDirty, errors },
} = useForm<FormValues>({
resolver: zodResolver(schema),
values: {
description: workspaceDescription,
},
});
const updateWorkspaceDescription = api.workspace.update.useMutation({
onSuccess: async () => {
try {
await utils.workspace.all.refetch();
} catch (e) {
console.error(e);
throw e;
}
},
onError: () => {
showPopup({
header: "Error updating workspace description",
message: "Please try again later, or contact customer support.",
});
},
});
const onSubmit = (data: FormValues) => {
updateWorkspaceDescription.mutate({
workspacePublicId,
description: data.description,
});
};
return (
<>
<div className="mb-4 flex max-w-[350px] items-center gap-2">
<Input
{...register("description")}
errorMessage={errors.description?.message}
/>
</div>
<Button
onClick={handleSubmit(onSubmit)}
variant="primary"
disabled={!isDirty || updateWorkspaceDescription.isPending}
isLoading={updateWorkspaceDescription.isPending}
>
Update
</Button>
</>
);
};
export default UpdateWorkspaceDescriptionForm;

View File

@@ -8,6 +8,7 @@ import { useModal } from "~/providers/modal";
import { useWorkspace } from "~/providers/workspace";
import { DeleteWorkspaceConfirmation } from "./components/DeleteWorkspaceConfirmation";
import { PremiumUsernameConfirmation } from "./components/PremiumUsernameConfirmation";
import UpdateWorkspaceDescriptionForm from "./components/UpdateWorkspaceDescriptionForm";
import UpdateWorkspaceNameForm from "./components/UpdateWorkspaceNameForm";
import UpdateWorkspaceUrlForm from "./components/UpdateWorkspaceUrlForm";
@@ -63,6 +64,14 @@ export default function SettingsPage() {
workspaceUrl={workspace.slug}
workspacePlan={workspace.plan}
/>
<h2 className="mb-4 mt-8 text-[14px] text-neutral-900 dark:text-dark-1000">
Workspace description
</h2>
<UpdateWorkspaceDescriptionForm
workspacePublicId={workspace.publicId}
workspaceDescription={workspace.description ?? ""}
/>
</div>
<div className="mb-8 border-t border-light-300 dark:border-dark-300">

View File

@@ -74,7 +74,7 @@ export default function WorkspaceSlugPage() {
{data?.name}
</h1>
<p className="mb-6 text-light-1000 dark:text-dark-900">
The open source Trello alternative.
{data?.description}
</p>
<div className="mb-4 h-[400px] w-[600px] rounded-xl border border-light-400 bg-light-200 p-4 dark:border-dark-200 dark:bg-dark-100">
{data?.boards && workspaceSlug && (