Skip to content

Commit

Permalink
feat: added lookup fields
Browse files Browse the repository at this point in the history
chore: updated translations
  • Loading branch information
Fredx87 authored and gosiexon-zen committed Sep 3, 2024
1 parent 6edc745 commit 7e3dcbd
Show file tree
Hide file tree
Showing 100 changed files with 40,414 additions and 97 deletions.
32 changes: 31 additions & 1 deletion assets/flash-notifications-bundle.js

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

1,404 changes: 1,362 additions & 42 deletions assets/new-request-form-bundle.js

Large diffs are not rendered by default.

3,184 changes: 3,183 additions & 1 deletion assets/new-request-form-translations-bundle.js

Large diffs are not rendered by default.

35,215 changes: 35,191 additions & 24 deletions assets/shared-bundle.js

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion assets/wysiwyg-bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dompurify": "3.0.11",
"eslint-plugin-check-file": "^2.6.2",
"i18next": "^23.10.1",
"mime": "^4.0.4",
"lodash.debounce": "^4.0.8",
"node-fetch": "2.6.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down Expand Up @@ -63,6 +63,7 @@
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^14.4.3",
"@types/lodash.debounce": "^4.0.9",
"@types/react": "^17.0.62",
"@types/react-dom": "^17.0.20",
"@types/styled-components": "^5.1.26",
Expand Down
49 changes: 37 additions & 12 deletions src/modules/new-request-form/NewRequestForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnswerBot, Field, RequestForm } from "./data-types";
import { useState } from "react";
import { useCallback, useState } from "react";
import { Input } from "./fields/Input";
import { TextArea } from "./fields/textarea/TextArea";
import { DropDown } from "./fields/DropDown";
Expand All @@ -22,6 +22,8 @@ import { SuggestedArticles } from "./suggested-articles/SuggestedArticles";
import { AnswerBotModal } from "./answer-bot-modal/AnswerBotModal";
import { useTranslation } from "react-i18next";
import { Paragraph } from "@zendeskgarden/react-typography";
import { LookupField } from "./fields/LookupField";
import type { Organization } from "./data-types/Organization";

export interface NewRequestFormProps {
requestForm: RequestForm;
Expand All @@ -33,7 +35,9 @@ export interface NewRequestFormProps {
baseLocale: string;
hasAtMentions: boolean;
userRole: string;
userId: number;
brandId: number;
organizations: Array<Organization>;
answerBotModal: {
answerBot: AnswerBot;
hasRequestManagement: boolean;
Expand Down Expand Up @@ -68,7 +72,9 @@ export function NewRequestForm({
baseLocale,
hasAtMentions,
userRole,
userId,
brandId,
organizations,
answerBotModal,
}: NewRequestFormProps) {
const {
Expand Down Expand Up @@ -102,7 +108,6 @@ export function NewRequestForm({
organizationField: organization_field,
dueDateField: due_date_field,
});

const [ticketFields, setTicketFields] = useState(prefilledTicketFields);
const [organizationField, setOrganizationField] = useState(
prefilledOrganizationField
Expand All @@ -111,16 +116,22 @@ export function NewRequestForm({
const visibleFields = getVisibleFields(ticketFields, end_user_conditions);
const { formRefCallback, handleSubmit } = useFormSubmit(ticketFields);
const { t } = useTranslation();

function handleChange(field: Field, value: Field["value"]) {
setTicketFields(
ticketFields.map((ticketField) =>
ticketField.name === field.name
? { ...ticketField, value }
: ticketField
)
);
}
const defaultOrganizationId =
organizations.length > 0 && organizations[0]?.id
? organizations[0]?.id?.toString()
: null;
const handleChange = useCallback(
(field: Field, value: Field["value"]) => {
setTicketFields(
ticketFields.map((ticketField) =>
ticketField.name === field.name
? { ...ticketField, value }
: ticketField
)
);
},
[ticketFields]
);

function handleOrganizationChange(value: string) {
if (organizationField === null) {
Expand Down Expand Up @@ -301,6 +312,20 @@ export function NewRequestForm({
onChange={(value) => handleChange(field, value)}
/>
);
case "lookup":
return (
<LookupField
key={field.name}
field={field}
userId={userId}
organizationId={
organizationField !== null
? (organizationField.value as string)
: defaultOrganizationId
}
onChange={(value) => handleChange(field, value)}
/>
);
default:
return <></>;
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/new-request-form/data-types/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Field {
description: string;
type: string;
options: FieldOption[];
relationship_target_type?: string;
}

export interface FieldOption {
Expand Down
4 changes: 4 additions & 0 deletions src/modules/new-request-form/data-types/Organization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Organization {
id: number;
name: string;
}
Loading

0 comments on commit 7e3dcbd

Please sign in to comment.