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

feat: add parent id hidden input field #412

Merged
merged 2 commits into from
Aug 15, 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
11 changes: 8 additions & 3 deletions assets/new-request-form.js

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

7 changes: 7 additions & 0 deletions src/modules/new-request-form/NewRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TextInput } from "./fields/TextInput";
import { TextArea } from "./fields/TextArea";
import { DropDown } from "./fields/DropDown";
import { TicketFormField } from "./ticket-form-field/TicketFormField";
import { ParentTicketField } from "./parent-ticket-field/ParentTicketField";
import { Button } from "@zendeskgarden/react-buttons";
import styled from "styled-components";
import { Alert } from "@zendeskgarden/react-notifications";
Expand All @@ -11,6 +12,7 @@ import { useSubmitHandler } from "./useSubmitHandler";
export interface NewRequestFormProps {
ticketForms: TicketForm[];
requestForm: RequestForm;
parentId: string;
}

const Form = styled.form`
Expand All @@ -26,6 +28,7 @@ const Footer = styled.div`
export function NewRequestForm({
ticketForms,
requestForm,
parentId
}: NewRequestFormProps) {
const {
fields,
Expand All @@ -35,6 +38,7 @@ export function NewRequestForm({
errors,
ticket_form_field,
ticket_forms_instructions,
parent_id_field,
} = requestForm;
const handleSubmit = useSubmitHandler();

Expand All @@ -47,6 +51,9 @@ export function NewRequestForm({
onSubmit={handleSubmit}
>
{errors && <Alert type="error">{errors}</Alert>}
{parentId && (
<ParentTicketField field={parent_id_field} />
)}
{ticketForms.length > 0 && (
<TicketFormField
label={ticket_forms_instructions}
Expand Down
1 change: 1 addition & 0 deletions src/modules/new-request-form/data-types/RequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export interface RequestForm {
errors: string | null;
ticket_forms_instructions: string;
ticket_form_field: Field;
parent_id_field: Field;
fields: Field[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Field } from "../data-types";

interface ParentTicketFieldProps {
field: Field;
}

export function ParentTicketField({ field }: ParentTicketFieldProps): JSX.Element {
const { value, name } = field;
return (
<input
type="hidden"
name={name}
value={value}
/>
);
}
4 changes: 3 additions & 1 deletion templates/new_request_page.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
{{id}}, url: "{{url}}", display_name: "{{display_name}}" });
{{/each}}

const parentId = "{{ parent_id }}";

const container = document.getElementById("new-request-form");
const props = { ticketForms, requestForm };
const props = { ticketForms, requestForm, parentId };
renderNewRequestForm(props, container);
</script>