-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support adding
questFields
to a questStep
; display form fie…
…lds within a quest (#113)
- Loading branch information
Showing
8 changed files
with
230 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"namesake": minor | ||
--- | ||
|
||
Display form fields within quest steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { api } from "@convex/_generated/api"; | ||
import type { Doc, Id } from "@convex/_generated/dataModel"; | ||
import { useQuery } from "convex/react"; | ||
import Markdown from "react-markdown"; | ||
import { Card } from "../Card"; | ||
import { Checkbox } from "../Checkbox"; | ||
import { DateField } from "../DateField"; | ||
import { NumberField } from "../NumberField"; | ||
import { Select, SelectItem } from "../Select"; | ||
import { TextArea } from "../TextArea"; | ||
import { TextField } from "../TextField"; | ||
|
||
export interface QuestStepProps { | ||
title: string; | ||
description?: string; | ||
fields?: Id<"questFields">[]; | ||
} | ||
|
||
export function QuestFields(props: { questFields: Doc<"questFields">[] }) { | ||
const markupForField = (field: Doc<"questFields">) => { | ||
switch (field.type) { | ||
case "text": | ||
return ( | ||
<TextField | ||
label={field.label} | ||
description={field.helpText} | ||
type="text" | ||
/> | ||
); | ||
case "email": | ||
return ( | ||
<TextField | ||
label={field.label} | ||
description={field.helpText} | ||
type="email" | ||
/> | ||
); | ||
case "phone": | ||
return ( | ||
<TextField | ||
label={field.label} | ||
description={field.helpText} | ||
type="tel" | ||
/> | ||
); | ||
case "textarea": | ||
return <TextArea label={field.label} description={field.helpText} />; | ||
case "number": | ||
return <NumberField label={field.label} description={field.helpText} />; | ||
case "select": | ||
return ( | ||
<Select label={field.label} description={field.helpText}> | ||
{/* TODO: Add select options */} | ||
<SelectItem /> | ||
</Select> | ||
); | ||
case "checkbox": | ||
return <Checkbox label={field.label} description={field.helpText} />; | ||
case "date": | ||
return <DateField label={field.label} description={field.helpText} />; | ||
default: | ||
return undefined; | ||
} | ||
}; | ||
|
||
// TODO: Add skeleton loaders | ||
return props.questFields.map((field) => ( | ||
<div key={field._id}>{markupForField(field)}</div> | ||
)); | ||
} | ||
|
||
export function QuestStep({ title, description, fields }: QuestStepProps) { | ||
const questFields = useQuery(api.questFields.getFields, { | ||
fieldIds: fields ?? [], | ||
}); | ||
|
||
return ( | ||
<Card className="flex flex-col gap-2"> | ||
<h2 className="text-xl font-semibold">{title}</h2> | ||
{description && ( | ||
<div> | ||
<Markdown className="prose dark:prose-invert">{description}</Markdown> | ||
</div> | ||
)} | ||
{questFields && <QuestFields questFields={questFields} />} | ||
</Card> | ||
); | ||
} |
Oops, something went wrong.