Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion core/app/(user)/communities/AddCommunityForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import React from "react";
import React, { useEffect } from "react";
import dynamic from "next/dynamic";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -18,12 +19,17 @@
name: z.string().min(1),
slug: z.string().min(1),
avatar: z.string().url().optional().or(z.literal("")),
template: z.string().min(1),
});

type Props = {
setOpen: (open: false) => void;
};

const MonacoEditor = dynamic(() => import("@monaco-editor/react").then((mod) => mod.Editor), {
ssr: false,
});

export const AddCommunityForm = (props: Props) => {
const runCreateCommunity = useServerAction(createCommunity);

Expand All @@ -43,9 +49,30 @@
name: "",
slug: "",
avatar: "",
template: JSON.stringify({ community: { name: "", slug: "", avatar: "" } }),
},
});

const name = form.watch("name");
const slug = form.watch("slug");
const avatar = form.watch("avatar");
const template = form.watch("template");

useEffect(() => {
const parsedTemplate = JSON.parse(template ?? "{}");

const newTemplate = {
community: {
...parsedTemplate.community,
name,
slug,
avatar,
},
};

form.setValue("template", JSON.stringify(newTemplate, null, 2));
}, [name, slug, avatar]);

Check warning on line 74 in core/app/(user)/communities/AddCommunityForm.tsx

View workflow job for this annotation

GitHub Actions / ci / ci (lint)

React Hook useEffect has missing dependencies: 'form' and 'template'. Either include them or remove the dependency array

return (
<>
<Form {...form}>
Expand Down Expand Up @@ -92,6 +119,24 @@
</FormItem>
)}
/>

<FormField
control={form.control}
name="template"
render={({ field }) => (
<FormItem>
<FormLabel>Template</FormLabel>
<MonacoEditor
language="json"
value={template}
height="50vh"
onChange={field.onChange}
/>
<FormDescription>Template</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? (
<Loader2 />
Expand Down
11 changes: 11 additions & 0 deletions core/app/c/[communitySlug]/settings/export/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { exportCommunity } from "~/prisma/seeds/jsonExport";

export default async function Page() {
const exp = await exportCommunity();
return (
<div>
<h1>Export</h1>
<pre className="rounded-md bg-muted p-4 text-xs">{JSON.stringify(exp, null, 2)}</pre>
</div>
);
}
39 changes: 39 additions & 0 deletions core/app/components/Monaco/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useRef, useState } from "react";
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

import { cn } from "utils";

export const Editor = ({
className,
language = "json",
value = '{ "hello": "world" }',
}: {
className?: string;
language?: string;
value?: string;
}) => {
const [editor, setEditor] = useState<monaco.editor.IStandaloneCodeEditor | null>(null);
const monacoEl = useRef(null);

useEffect(() => {
if (monacoEl) {
setEditor((editor) => {
if (editor) return editor;

return monaco.editor.create(monacoEl.current!, {
value: '{ "hello": "world" }',
language: "json",
});
});
}

return () => editor?.dispose();
}, [monacoEl.current]);

return (
<div
className={cn("h-96 overflow-scroll [&_.monaco-editor]:!h-96", className)}
ref={monacoEl}
></div>
);
};
6 changes: 5 additions & 1 deletion core/lib/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { afterEach, beforeEach, vi } from "vitest";

import type { PublicSchema } from "db/public";

import type { SQB } from "../server/cache/types";
import { beginTransaction } from "./transactions";

export const mockServerCode = async () => {
Expand All @@ -29,7 +30,10 @@ export const mockServerCode = async () => {
}));

vi.mock("~/lib/server/cache/autoCache", () => ({
autoCache: (db: any) => {
autoCache: (db: SQB<any>) => {
Object.assign(db, {
qb: db,
});
return db;
},
}));
Expand Down
5 changes: 3 additions & 2 deletions core/lib/server/pubtype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ export const getPubTypesForCommunity = async (
orderBy = GET_MANY_DEFAULT.orderBy,
orderDirection = GET_MANY_DEFAULT.orderDirection,
name,
}: GetManyParams & { name?: string[] } = GET_MANY_DEFAULT
trx = db,
}: GetManyParams & { name?: string[] } & { trx?: typeof db } = GET_MANY_DEFAULT
) =>
autoCache(
getPubTypeBase()
getPubTypeBase(trx)
.where("pub_types.communityId", "=", communityId)
.$if(Boolean(name), (eb) => eb.where("pub_types.name", "in", name!))
.orderBy(orderBy, orderDirection)
Expand Down
11 changes: 7 additions & 4 deletions core/lib/server/stages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { ExpressionBuilder } from "kysely";
import type { ExpressionBuilder, Kysely } from "kysely";

import { cache } from "react";
import { QueryCreator, sql } from "kysely";
import { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/postgres";
import { jsonArrayFrom } from "kysely/helpers/postgres";

import type { Database } from "db/Database";
import type {
CommunitiesId,
NewMoveConstraint,
Expand Down Expand Up @@ -136,6 +137,7 @@ type CommunityStageProps = { communityId: CommunitiesId; stageId?: StagesId; use
type CommunityStageOptions = {
withActionInstances?: "count" | "full" | false;
withMembers?: "count" | "full" | false;
trx?: Kysely<Database>;
};

export const actionConfigDefaultsSelect = <EB extends ExpressionBuilder<any, any>>(eb: EB) => {
Expand Down Expand Up @@ -166,9 +168,10 @@ export const getStages = (
) => {
const withActionInstances = options.withActionInstances ?? "count";

const trx = options.trx ?? db;
return autoCache(
db
.with("viewableStages", (db) => viewableStagesCte({ db: db, userId, communityId }))
trx
.with("viewableStages", (db) => viewableStagesCte({ db, userId, communityId }))
.selectFrom("stages")
.innerJoin("viewableStages", "viewableStages.stageId", "stages.id")
.where("communityId", "=", communityId)
Expand Down
4 changes: 3 additions & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@honeycombio/opentelemetry-node": "catalog:",
"@hookform/resolvers": "catalog:",
"@icons-pack/react-simple-icons": "^10.2.0",
"@monaco-editor/react": "^4.7.0",
"@neshca/cache-handler": "^1.9.0",
"@nimpl/getters": "^2.2.0",
"@node-rs/argon2": "^1.8.3",
Expand Down Expand Up @@ -120,15 +121,16 @@
"lucia": "^3.2.2",
"lucide-react": "^0.469.0",
"micromark-extension-directive": "^3.0.2",
"monaco-editor": "^0.54.0",
"mudder": "^2.1.1",
"next": "catalog:",
"next-connect": "^1.0.0",
"nodemailer": "^6.10.1",
"nuqs": "catalog:",
"openapi3-ts": "^4.5.0",
"oslo": "^1.2.1",
"parse-english": "^7.0.0",
"p-map": "^7.0.3",
"parse-english": "^7.0.0",
"pg": "^8.16.3",
"prosemirror-markdown": "^1.13.2",
"prosemirror-model": "catalog:",
Expand Down
Loading
Loading