Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering DropDown and TextArea ticket fields #397

Merged
merged 6 commits into from
Jul 28, 2023
Merged
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
49 changes: 49 additions & 0 deletions assets/new-request-form.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions assets/shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21,798 changes: 21,798 additions & 0 deletions assets/vendor.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import replace from "@rollup/plugin-replace";
import { generateImportMap } from "./generate-import-map.mjs"
import { generateImportMap } from "./generate-import-map.mjs";
import { defineConfig } from "rollup";

export default defineConfig([
Expand All @@ -19,6 +19,7 @@ export default defineConfig([
},
},
{
context: "this",
input: {
"new-request-form": "src/modules/new-request-form/index.tsx",
shared: "src/modules/shared.tsx",
Expand Down
8 changes: 8 additions & 0 deletions src/modules/new-request-form/NewRequestForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Field, TicketForm } from "./data-types";
import { TextInput } from "./fields/TextInput";
import { TextArea } from "./fields/TextArea";
import { DropDown } from "./fields/DropDown";
import { TicketFormField } from "./ticket-form-field/TicketFormField";

export interface NewRequestFormProps {
Expand All @@ -13,8 +15,14 @@ export function NewRequestForm({ ticketForms, fields }: NewRequestFormProps) {
<TicketFormField ticketForms={ticketForms} />
{fields.map((field) => {
switch (field.type) {
case "anonymous_requester_email":
case "subject":
return <TextInput field={field} />;
case "description":
case "textarea":
return <TextArea field={field} />;
case "priority":
return <DropDown field={field} />;
default:
return <></>;
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/new-request-form/data-types/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ export interface Field {
description: string;
type: string;
id: string;
options: Option[];
}

interface Option {
name: string;
value: string;
}
39 changes: 39 additions & 0 deletions src/modules/new-request-form/fields/DropDown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Field as GardenField,
Label,
Hint,
Combobox,
Option,
Message,
} from "@zendeskgarden/react-dropdowns.next";
import type { Field } from "../data-types";

interface DropDownProps {
field: Field;
}

export function DropDown({ field }: DropDownProps): JSX.Element {
const { label, options, error, value, name, required, description } = field;
return (
<GardenField>
<Label>{label}</Label>
{description && <Hint>{description}</Hint>}
<Combobox
inputProps={{ name, required }}
isEditable={false}
validation={error ? "error" : undefined}
>
{options.map((option) => (
<Option
key={option.value}
value={option.value}
isSelected={option.value === value}
>
{option.name}
</Option>
))}
</Combobox>
{error && <Message validation="error">{error}</Message>}
</GardenField>
);
}
29 changes: 29 additions & 0 deletions src/modules/new-request-form/fields/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
Field as GardenField,
Hint,
Textarea,
Label,
Message,
} from "@zendeskgarden/react-forms";
import type { Field } from "../data-types";

interface TextAreaProps {
field: Field;
}

export function TextArea({ field }: TextAreaProps): JSX.Element {
const { label, error, value, name, required, description } = field;
return (
<GardenField>
<Label>{label}</Label>
{description && <Hint>{description}</Hint>}
<Textarea
name={name}
value={value}
validation={error ? "error" : undefined}
required={required}
/>
{error && <Message validation="error">{error}</Message>}
</GardenField>
);
}
14 changes: 13 additions & 1 deletion templates/new_request_page.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@

{{#with new_request_form}}
{{#each fields}}
fields.push({ name: "{{name}}", value: "{{value}}", error: "{{error}}", label: {{ json_stringify label }}, required: {{required}}, description: "{{description}}", type: "{{type}}", id: "{{id}}" })
fields.push({
name: "{{name}}",
value: "{{value}}",
error: "{{error}}",
label: {{ json_stringify label }},
required: {{required}},
description: "{{description}}",
type: "{{type}}",
id: "{{id}}",
options: [{{#each options}}
{ name: "{{name}}", value: "{{value}}" },
{{/each}}],
})
{{/each}}
{{/with}}

Expand Down