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
28 changes: 28 additions & 0 deletions core/actions/_lib/zodTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ class Stage extends z.ZodString {
})
}

class Member extends z.ZodString {
static create = () =>
new Member({
typeName: "Member" as z.ZodFirstPartyTypeKind.ZodString,
checks: [],
coerce: false,
})
}

class FormSlugType extends z.ZodString {
static create = () =>
new FormSlugType({
typeName: "FormSlug" as z.ZodFirstPartyTypeKind.ZodString,
checks: [],
coerce: false,
})
}

// @ts-expect-error FIXME: 'ZodObject<{ pubField: ZodString; responseField: ZodString; }, UnknownKeysParam, ZodTypeAny, { pubField: string; responseField: string; }, { pubField: string; responseField: string; }>' is assignable to the constraint of type 'El', but 'El' could be instantiated with a different subtype of constraint 'ZodTypeAny' blahblahblah
class OutputMap extends z.ZodArray<
z.ZodObject<{ pubField: z.ZodString; responseField: z.ZodString }>
Expand All @@ -69,4 +87,14 @@ export const markdown = Markdown.create
export const stringWithTokens = StringWithTokens.create
export const fieldName = FieldName.create
export const stage = Stage.create
export const member = Member.create
export const formSlug = FormSlugType.create
export const outputMap = OutputMap.create

// custom typeName constants used for detecting reference fields during config rewriting
export const REFERENCE_TYPE_NAMES = {
Stage: "Stage",
Member: "Member",
FormSlug: "FormSlug",
FieldName: "FieldName",
} as const
5 changes: 3 additions & 2 deletions core/actions/createPub/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import z from "zod"

import { Action } from "db/public"

import { formSlug, stage } from "../_lib/zodTypes"
import { defineAction } from "../types"

/**
Expand Down Expand Up @@ -36,8 +37,8 @@ export const action = defineAction({
description: "Create a new pub",
config: {
schema: z.object({
stage: z.string().uuid(),
formSlug: z.string(),
stage: stage().describe("The stage the new pub will be created in"),
formSlug: formSlug().describe("The form slug that determines the pub type"),
pubValues: z.record(z.unknown()),
relationConfig: relationConfigSchema.describe(
"Optional configuration for relating the new pub to an existing pub"
Expand Down
4 changes: 2 additions & 2 deletions core/actions/email/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RenderWithPubToken,
renderWithPubTokens,
} from "~/lib/server/render/pub/renderWithPubTokens"
import { markdown, stringWithTokens } from "../_lib/zodTypes"
import { markdown, member, stringWithTokens } from "../_lib/zodTypes"
import { defineAction } from "../types"

const emptyStringToUndefined = (arg: unknown) => {
Expand All @@ -34,7 +34,7 @@ const schema = z.object({
"The email address of the recipient(s). Either this or 'Recipient Member' must be set."
),
recipientMember: z
.preprocess(emptyStringToUndefined, z.string().uuid().optional())
.preprocess(emptyStringToUndefined, member().optional())
.optional()
.describe(
"Someone who is a member of the community. Either this or 'Recipient Email' must be set."
Expand Down
4 changes: 4 additions & 0 deletions core/actions/move/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export const action = defineAction({
description: "Move a pub into a different stage",
icon: MoveHorizontal,
})

// is this field a weak ref to foreignkey?
// is this field sensitive/should not be copied?
//
56 changes: 50 additions & 6 deletions core/app/(user)/communities/AddCommunityDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,39 @@
import React from "react"

import { Button } from "ui/button"
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "ui/dialog"
import { ListPlus } from "ui/icon"
import { Dialog, DialogContent, DialogDescription, DialogTitle, DialogTrigger } from "ui/dialog"
import { CurlyBraces, ListPlus } from "ui/icon"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui/tabs"
import { Tooltip, TooltipContent, TooltipTrigger } from "ui/tooltip"

import { AddCommunityForm } from "./AddCommunityForm"
import { BlueprintImportWizard } from "./BlueprintImportWizard"

export const AddCommunity = () => {
type AddCommunityProps = {
initialTemplate?: string
}

export const AddCommunity = ({ initialTemplate }: AddCommunityProps) => {
const [open, setOpen] = React.useState(false)
const [activeTab, setActiveTab] = React.useState<string>("basic")

React.useEffect(() => {
if (!open) {
setActiveTab("basic")
}
}, [open])

React.useEffect(() => {
if (initialTemplate) {
setActiveTab("blueprint")
setOpen(true)
}
}, [initialTemplate])

return (
<Dialog open={open} onOpenChange={setOpen}>
<Tooltip>
<TooltipContent> Create a new community</TooltipContent>
<TooltipContent>Create a new community</TooltipContent>
<TooltipTrigger asChild>
<DialogTrigger asChild>
<Button variant="outline" className="flex items-center gap-x-2">
Expand All @@ -24,9 +45,32 @@ export const AddCommunity = () => {
</TooltipTrigger>
</Tooltip>

<DialogContent>
<DialogContent className="max-w-2xl">
<DialogTitle>Create Community</DialogTitle>
<AddCommunityForm setOpen={setOpen} />
<DialogDescription>
Create a new community from scratch or import from a blueprint.
</DialogDescription>

<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="basic">Basic</TabsTrigger>
<TabsTrigger value="blueprint" className="gap-1.5">
<CurlyBraces size={14} />
From Blueprint
</TabsTrigger>
</TabsList>

<TabsContent value="basic" className="mt-4">
<AddCommunityForm setOpen={setOpen} />
</TabsContent>

<TabsContent value="blueprint" className="mt-4">
<BlueprintImportWizard
onComplete={() => setOpen(false)}
initialBlueprint={initialTemplate}
/>
</TabsContent>
</Tabs>
</DialogContent>
</Dialog>
)
Expand Down
2 changes: 1 addition & 1 deletion core/app/(user)/communities/AddCommunityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const AddCommunityForm = (props: Props) => {
</FormItem>
)}
/>
<Button type="submit" disabled={form.formState.isSubmitting}>
<Button size="sm" type="submit" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? (
<Loader2 />
) : (
Expand Down
Loading
Loading