Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredx87 committed Aug 14, 2023
1 parent ffe3482 commit 5c76802
Show file tree
Hide file tree
Showing 9 changed files with 3,683 additions and 770 deletions.
2,621 changes: 2,621 additions & 0 deletions assets/CcField.js

Large diffs are not rendered by default.

3 changes: 3 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.

1,511 changes: 779 additions & 732 deletions assets/vendor.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
"zcli": "zcli"
},
"dependencies": {
"@zag-js/react": "^0.15.0",
"@zag-js/tags-input": "^0.15.0",
"@zendeskgarden/react-buttons": "^8.69.1",
"@zendeskgarden/react-dropdowns.next": "^8.69.1",
"@zendeskgarden/react-forms": "^8.69.1",
"@zendeskgarden/react-notifications": "^8.69.1",
"@zendeskgarden/react-tags": "^8.69.1",
"@zendeskgarden/react-theming": "^8.69.1",
"node-fetch": "2.6.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"styled-components": "^5.3.11"
},
"devDependencies": {
Expand All @@ -34,14 +37,14 @@
"@semantic-release/changelog": "6.0.2",
"@semantic-release/exec": "6.0.3",
"@semantic-release/git": "10.0.1",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^14.4.3",
"@types/react": "^17.0.62",
"@types/react-dom": "^17.0.20",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@zendesk/zcli": "1.0.0-beta.38",
"concurrently": "8.0.1",
"dotenv": "16.0.3",
Expand Down Expand Up @@ -69,9 +72,9 @@
"wait-on": "7.0.1"
},
"resolutions": {
"@types/react": "^17.0.62"
"@types/react": "^18.x"
},
"commitlint": {
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineConfig([
dir: "assets",
format: "es",
manualChunks: (id) => {
if (id.includes("node_modules")) {
if (id.includes("node_modules") && !id.includes("@zag-js")) {
return "vendor";
}
},
Expand Down
9 changes: 9 additions & 0 deletions src/modules/new-request-form/NewRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button } from "@zendeskgarden/react-buttons";
import styled from "styled-components";
import { Alert } from "@zendeskgarden/react-notifications";
import { useSubmitHandler } from "./useSubmitHandler";
import { Suspense, lazy } from "react";

export interface NewRequestFormProps {
ticketForms: TicketForm[];
Expand All @@ -23,6 +24,8 @@ const Footer = styled.div`
margin-top: ${(props) => props.theme.space.md};
`;

const CcField = lazy(() => import("./fields/CcField"));

export function NewRequestForm({
ticketForms,
requestForm,
Expand Down Expand Up @@ -67,6 +70,12 @@ export function NewRequestForm({
case "organization_id":
case "tickettype":
return <DropDown field={field} />;
case "cc_email":
return (
<Suspense fallback={<></>}>
<CcField field={field} />
</Suspense>
);
default:
return <></>;
}
Expand Down
96 changes: 96 additions & 0 deletions src/modules/new-request-form/fields/CcField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import type { Field } from "../data-types";
import {
FauxInput,
Field as GardenField,
Hint,
Input,
Label,
Message,
} from "@zendeskgarden/react-forms";
import * as tagsInput from "@zag-js/tags-input";
import { useMachine, normalizeProps } from "@zag-js/react";
import styled from "styled-components";
import type { ComponentProps } from "react";
import { Tag } from "@zendeskgarden/react-tags";
import { focusStyles } from "@zendeskgarden/react-theming";

interface CcFieldProps {
field: Field;
}

const EMAIL_REGEX =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

export default function CcField({ field }: CcFieldProps): JSX.Element {
const { label, value, name, error, description, id } = field;
const initialValue = value
? value.split(",").map((email) => email.trim())
: [];
const [state, send] = useMachine(
tagsInput.machine({
id,
value: initialValue,
allowEditTag: false,
})
);

const api = tagsInput.connect(state, send, normalizeProps);

return (
<GardenField {...api.rootProps}>
<Label {...(api.labelProps as ComponentProps<typeof Label>)}>
{label}
</Label>
{description && <Hint>{description}</Hint>}
<Control {...api.controlProps} validation={error ? "error" : undefined}>
{api.value.map((email, index) => (
<span key={index}>
<StyledTag
{...api.getTagProps({ index, value: email })}
size="large"
hue={EMAIL_REGEX.test(email) ? undefined : "red"}
>
<span>{email}</span>
<Tag.Close
{...(api.getTagDeleteTriggerProps({
index,
value: email,
}) as ComponentProps<typeof Tag.Close>)}
/>
</StyledTag>
<input {...api.getTagInputProps({ index, value })} />
</span>
))}
<StyledInput
isBare
{...(api.inputProps as ComponentProps<typeof StyledInput>)}
/>
</Control>
{error && <Message validation="error">{error}</Message>}
{api.value.map((email) => (
<input key={email} type="hidden" name={name} value={email} />
))}
</GardenField>
);
}

const Control = styled(FauxInput)`
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: ${(p) => p.theme.space.sm};
`;

const StyledInput = styled(Input)`
width: revert;
flex: 1;
`;

const StyledTag = styled(Tag)`
${(props) =>
focusStyles({
theme: props.theme,
shadowWidth: "sm",
selector: "&[data-highlighted]",
})}
`;
3 changes: 2 additions & 1 deletion templates/document_head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"imports": {
"new-request-form": "{{asset 'new-request-form.js'}}",
"shared": "{{asset 'shared.js'}}",
"vendor": "{{asset 'vendor.js'}}"
"vendor": "{{asset 'vendor.js'}}",
"CcField": "{{asset 'CcField.js'}}"
}
}
</script>
Expand Down
Loading

0 comments on commit 5c76802

Please sign in to comment.