Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
feat: contact us modal component (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Jun 10, 2020
1 parent f6572ce commit 7c536fc
Show file tree
Hide file tree
Showing 26 changed files with 599 additions and 91 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ src/i18n
dist/
build/
coverage/
config-overrides.js
19 changes: 19 additions & 0 deletions src/__tests__/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`Application root should render without crashing 1`] = `
"COMMON_BACK": "Back",
"COMMON_BACKGROUND": "Background",
"COMMON_BIP39_LANGUAGE": "Passphrase Language (BIP39)",
"COMMON_CANCEL": "Cancel",
"COMMON_CATEGORY": "Category",
"COMMON_CONFIRM": "Confirm",
"COMMON_CURRENCY": "Currency",
Expand Down Expand Up @@ -56,6 +57,8 @@ exports[`Application root should render without crashing 1`] = `
"COMMON_PROFILE_NAME": "Profile name",
"COMMON_REMOVE": "Remove",
"COMMON_SAVE": "Save",
"COMMON_SELECT": "Select",
"COMMON_SEND": "Send",
"COMMON_SIZE": "Size",
"COMMON_SKIP": "Skip",
"COMMON_START": "Start",
Expand All @@ -69,6 +72,22 @@ exports[`Application root should render without crashing 1`] = `
"COMMON_WELCOME": "Welcome to ARK",
"COMMON_WILL": "will",
"COMMON_X_OF_Y": "{0} of {1}",
"HELP": Object {
"MODAL_CONTACT_US": Object {
"DESCRIPTION": "We'd be happy to answer your questions",
"FIELD_EMAIL": "Email",
"FIELD_MESSAGE": "Message",
"FIELD_NAME": "Name",
"FIELD_SUBJECT": "Subject",
"MESSAGE_REQUIRED": "Message is Required",
"SUBJECT_OPTION": Object {
"OTHER": "Other",
"SECURITY": "Security",
},
"SUBJECT_REQUIRED": "Subject is Required",
"TITLE": "Contact Us",
},
},
"WALLET": Object {
"MODAL_NAME_WALLET": Object {
"DESCRIPTION": "You can enter the name of your wallet for a quick search in your wallet.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ exports[`Dropdown should render with options 1`] = `
height="20"
width="20"
>
<div />
<div>
<div>
<div
data-src="settings.svg"
src=""
/>
</div>
</div>
</div>
</button>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ModalProps = {
description?: string;
isOpen: boolean;
onClose?: any;
onClick?: any;
};

type ModalContentProps = {
Expand All @@ -22,9 +23,9 @@ const ModalContent = (props: ModalContentProps) => {
return (
<div
data-testid="modal__inner"
className="fixed flex flex-col z-10 left-0 right-0 max-w-2xl rounded-xl bg-theme-background mx-auto mt-24 pt-6 pb-8 px-16"
className="fixed left-0 right-0 z-10 flex flex-col max-w-2xl px-16 pt-6 pb-8 mx-auto mt-24 rounded-xl bg-theme-background"
>
<div className="absolute right-0 top-0 mt-4 mr-4">
<div className="absolute top-0 right-0 mt-4 mr-4">
<Button color="neutral" variant="plain" size="icon" onClick={props.onClose}>
<Icon name="crossSlim" width={10} height={10} />
</Button>
Expand All @@ -33,7 +34,7 @@ const ModalContent = (props: ModalContentProps) => {
<div className="py-4">
<h2>{props.title}</h2>

<div className="flex-1 overflow-auto">
<div className="flex-1">
{props.description ? <div className="text-theme-neutral-500">{props.description}</div> : ""}

{props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports[`Modal should render a modal with content 1`] = `
data-testid="modal__overlay"
/>
<div
class="fixed flex flex-col z-10 left-0 right-0 max-w-2xl rounded-xl bg-theme-background mx-auto mt-24 pt-6 pb-8 px-16"
class="fixed left-0 right-0 z-10 flex flex-col max-w-2xl px-16 pt-6 pb-8 mx-auto mt-24 rounded-xl bg-theme-background"
data-testid="modal__inner"
>
<div
class="absolute right-0 top-0 mt-4 mr-4"
class="absolute top-0 right-0 mt-4 mr-4"
>
<button
class="sc-AxjAm jZZsoN"
Expand Down Expand Up @@ -43,7 +43,7 @@ exports[`Modal should render a modal with content 1`] = `
ark
</h2>
<div
class="flex-1 overflow-auto"
class="flex-1"
>
This is the Modal content
</div>
Expand All @@ -59,11 +59,11 @@ exports[`Modal should render a modal with description 1`] = `
data-testid="modal__overlay"
/>
<div
class="fixed flex flex-col z-10 left-0 right-0 max-w-2xl rounded-xl bg-theme-background mx-auto mt-24 pt-6 pb-8 px-16"
class="fixed left-0 right-0 z-10 flex flex-col max-w-2xl px-16 pt-6 pb-8 mx-auto mt-24 rounded-xl bg-theme-background"
data-testid="modal__inner"
>
<div
class="absolute right-0 top-0 mt-4 mr-4"
class="absolute top-0 right-0 mt-4 mr-4"
>
<button
class="sc-AxjAm jZZsoN"
Expand Down Expand Up @@ -93,7 +93,7 @@ exports[`Modal should render a modal with description 1`] = `
ark
</h2>
<div
class="flex-1 overflow-auto"
class="flex-1"
>
<div
class="text-theme-neutral-500"
Expand All @@ -113,11 +113,11 @@ exports[`Modal should render a modal with overlay 1`] = `
data-testid="modal__overlay"
/>
<div
class="fixed flex flex-col z-10 left-0 right-0 max-w-2xl rounded-xl bg-theme-background mx-auto mt-24 pt-6 pb-8 px-16"
class="fixed left-0 right-0 z-10 flex flex-col max-w-2xl px-16 pt-6 pb-8 mx-auto mt-24 rounded-xl bg-theme-background"
data-testid="modal__inner"
>
<div
class="absolute right-0 top-0 mt-4 mr-4"
class="absolute top-0 right-0 mt-4 mr-4"
>
<button
class="sc-AxjAm jZZsoN"
Expand Down Expand Up @@ -147,7 +147,7 @@ exports[`Modal should render a modal with overlay 1`] = `
ark
</h2>
<div
class="flex-1 overflow-auto"
class="flex-1"
>
This is the Modal content
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ exports[`Formatted Address should render with wallet data and optional icon 1`]
height="20"
width="20"
>
<div />
<div>
<div>
<div
data-src="settings.svg"
src=""
/>
</div>
</div>
</div>
</button>
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/domains/help/components/ContactUs/ContactUs.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { ContactUs } from "./";
import { boolean } from "@storybook/addon-knobs";

export default { title: "Help / Components / ContactUs" };

export const Default = () => (
<ContactUs
isOpen={boolean("Is Open", true)}
onClose={() => alert("closed")}
onCancel={() => alert("cancelled")}
onSend={() => alert("sent")}
/>
);
114 changes: 114 additions & 0 deletions src/domains/help/components/ContactUs/ContactUs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React from "react";
import { injectIntl, WrappedComponentProps } from "react-intl";
import { useForm } from "react-hook-form";
// UI Elements
import { Modal } from "app/components/Modal";
import { Button } from "app/components/Button";
import { Circle } from "app/components/Circle";
import { Form, FormField, FormLabel, FormHelperText } from "app/components/Form";
import { Input } from "app/components/Input";
import { Select } from "app/components/Select";
import { Icon } from "app/components/Icon";
import { Textarea } from "app/components/Textarea";

type ContactUsProps = {
isOpen: boolean;
onClose?: any;
onCancel?: any;
onSend: any;
} & WrappedComponentProps;

export const ContactUs = injectIntl(({ intl: { formatMessage }, ...props }: ContactUsProps) => {
const methods = useForm({ mode: "onChange" });

return (
<Modal
title={formatMessage({ id: "HELP.MODAL_CONTACT_US.TITLE" })}
description={formatMessage({ id: "HELP.MODAL_CONTACT_US.DESCRIPTION" })}
isOpen={props.isOpen}
onClose={props.onClose}
>
<div className="flex border-b border-gray-500 text-black mt-2 mb-8 -mx-16 px-16 pb-8">
<a href="https://twitter.ark.io" className="rounded-full mr-2 hover:bg-theme-neutral-300">
<Circle className="border-black hover:bg-transparent" noShadow={true}>
<Icon name="twitter" />
</Circle>
</a>

<a href="https://slack.ark.io" className="rounded-full mr-2 hover:bg-theme-neutral-300">
<Circle className="border-black hover:bg-transparent" noShadow={true}>
<Icon name="slack" />
</Circle>
</a>

<a href="https://discord.ark.io/" className="rounded-full mr-2 hover:bg-theme-neutral-300">
<Circle className="border-black hover:bg-transparent" noShadow={true}>
<Icon name="discord" />
</Circle>
</a>

<a href="mailto:info@ark.io" className="rounded-full hover:bg-theme-neutral-300">
<Circle className="border-black hover:bg-transparent" noShadow={true}>
<Icon name="send" />
</Circle>
</a>
</div>

<Form context={methods} onSubmit={props.onSend}>
<FormField name="name">
<FormLabel>{formatMessage({ id: "HELP.MODAL_CONTACT_US.FIELD_NAME" })}</FormLabel>
<Input ref={methods.register({ required: "Field required" })} />
<FormHelperText />
</FormField>

<FormField name="email">
<FormLabel>{formatMessage({ id: "HELP.MODAL_CONTACT_US.FIELD_EMAIL" })}</FormLabel>
<Input ref={methods.register({ required: "Field required" })} />
<FormHelperText />
</FormField>

<FormField name="subject">
<FormLabel>{formatMessage({ id: "HELP.MODAL_CONTACT_US.FIELD_SUBJECT" })}</FormLabel>
<Select
ref={methods.register({
required: formatMessage({ id: "HELP.MODAL_CONTACT_US.SUBJECT_REQUIRED" }),
})}
>
<option value="">{formatMessage({ id: "COMMON_SELECT" })}</option>
<option value="security">
{formatMessage({ id: "HELP.MODAL_CONTACT_US.SUBJECT_OPTION.SECURITY" })}
</option>
<option value="other">
{formatMessage({ id: "HELP.MODAL_CONTACT_US.SUBJECT_OPTION.OTHER" })}
</option>
</Select>
</FormField>

<FormField name="message">
<FormLabel>{formatMessage({ id: "HELP.MODAL_CONTACT_US.FIELD_MESSAGE" })}</FormLabel>
<Textarea
ref={methods.register({
required: formatMessage({ id: "HELP.MODAL_CONTACT_US.MESSAGE_REQUIRED" }),
})}
/>
</FormField>

<div className="mt-4">
<Button color="primary" variant="plain" onClick={props.onCancel} className="mr-2">
{formatMessage({ id: "COMMON_CANCEL" })}
</Button>

<Button type="submit" color="primary" variant="solid">
{formatMessage({ id: "COMMON_SEND" })}
</Button>
</div>
</Form>
</Modal>
);
});

ContactUs.defaultProps = {
isOpen: false,
};

ContactUs.displayName = "ContactUs";
40 changes: 40 additions & 0 deletions src/domains/help/components/ContactUs/__tests__/ContactUs.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { IntlProvider } from "react-intl";
import { render } from "@testing-library/react";

import { ContactUs } from "../";
// i18n
import { locales } from "i18n/locales";

describe("ContactUs", () => {
beforeEach(() => {
jest.spyOn(console, "error").mockImplementation(() => null);
});

it("should not render if not open", () => {
const { asFragment, getByTestId } = render(
<IntlProvider locale="en-US" messages={locales["en-US"].messages}>
<ContactUs isOpen={false} onSend={() => void 0} />
</IntlProvider>,
);

expect(() => getByTestId("modal__inner")).toThrow(/Unable to find an element by/);
expect(asFragment()).toMatchSnapshot();
});

it("should render a modal", () => {
const { asFragment, getByTestId } = render(
<IntlProvider locale="en-US" messages={locales["en-US"].messages}>
<ContactUs isOpen={true} onSend={() => void 0} />
</IntlProvider>,
);

expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.TITLE");
expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.DESCRIPTION");
expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.FIELD_NAME");
expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.FIELD_EMAIL");
expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.FIELD_SUBJECT");
expect(getByTestId("modal__inner")).toHaveTextContent("HELP.MODAL_CONTACT_US.FIELD_MESSAGE");
expect(asFragment()).toMatchSnapshot();
});
});
Loading

0 comments on commit 7c536fc

Please sign in to comment.