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

Contacts flow #60

Merged
merged 5 commits into from
Nov 29, 2024
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
17 changes: 17 additions & 0 deletions src/assets/contacts-illustration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const CREATE_BILL = "/create-bill";
const PREVIEW_BILL = "/preview-bill";
const MINT_BILL = "/mint-bill";
const SELL_BILL = "/sell-bill";
const CONTACTS = "/contacts";
const CREATE_CONTACT = "/create-contact";

export default {
LOGIN,
Expand All @@ -35,4 +37,6 @@ export default {
PREVIEW_BILL,
MINT_BILL,
SELL_BILL,
CONTACTS,
CREATE_CONTACT,
};
148 changes: 148 additions & 0 deletions src/pages/contacts/Create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { FormattedMessage } from "react-intl";
import { ChevronDownIcon, ChevronLeftIcon, SearchIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
Select,
SelectGroup,
SelectValue,
SelectTrigger,
SelectContent,
SelectItem,
} from "@/components/ui/select";
import routes from "@/constants/routes";

function Header() {
return (
<div className="flex flex-col gap-5 w-full">
<button className="flex items-center justify-center w-8 h-8 bg-[#1B0F00]/20 rounded-full border-[1px] border-[#1B0F00]/6">
<ChevronLeftIcon width={16} strokeWidth={1} color="#1B0F00" />
</button>
<div className="flex justify-between items-center">
<h1 className="text-text-300 text-xl font-medium">
<FormattedMessage
id="pages.createContact.header.title"
defaultMessage="New contact"
description="Title for create contact page"
/>
</h1>

<Button
className="gap-1 w-fit text-text-300 bg-transparent text-sm font-medium p-0 border-none hover:bg-transparent"
variant="outline"
>
<SearchIcon className="w-4 h-4 text-text-300" />
<FormattedMessage
id="pages.createContact.search"
defaultMessage="Search contacts"
description="Search contacts button"
/>
</Button>
</div>
</div>
);
}

function Form() {
const [isExtraFieldsVisible, setIsExtraFieldsVisible] = useState(false);

return (
<div className="flex-1 flex flex-col gap-3 w-full">
<Input id="name" label="Name" required />
<Input id="email" label="Email address" required />
<Input id="address" label="Postal address" required />

<Button
className={`gap-1 w-fit text-text-200 bg-transparent text-sm font-medium p-0 border-none hover:bg-transparent mx-auto ${
isExtraFieldsVisible ? "hidden" : "flex"
}`}
variant="outline"
onClick={() => setIsExtraFieldsVisible(!isExtraFieldsVisible)}
>
<FormattedMessage
id="pages.createContact.viewAllFields"
defaultMessage="View more"
description="View more fields button"
/>
<ChevronDownIcon className="w-4 h-4 text-text-200" />
</Button>

<div
className={`flex flex-col gap-3 ${
isExtraFieldsVisible ? "block" : "hidden"
}`}
>
<Input id="dateOfBirth" label="Date of birth (MM/DD/YYYY" />
<Select>
<SelectTrigger label="Country of issuing" id="countryOfIssuing">
<SelectValue placeholder="Select an option" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should placeholders already be localized with FormattedMessage?

Suggested change
<SelectValue placeholder="Select an option" />
<SelectValue placeholder={<FormattedMessage
id="pages.createContact.select.country"
defaultMessage="Select an option"
description="Placeholder for country selection"
/>} />

This applies to other non-translated fields/placeholders/etc. in this file.

Copy link
Contributor

@mtbitcr mtbitcr Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjkeaton just FYI please check #85

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you! I'm gonna replace that. In this case, we must use the imperative API so we don't have to change the typedef for the component.

Ref: https://formatjs.github.io/docs/react-intl/api/#useintl-hook

</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="option1">Afghanistan</SelectItem>
<SelectItem value="option2">Albania</SelectItem>
<SelectItem value="option3">Algeria</SelectItem>
<SelectItem value="option4">Andorra</SelectItem>
<SelectItem value="option5">Angola</SelectItem>
<SelectItem value="option6">Antigua and Barbuda</SelectItem>
<SelectItem value="option7">Argentina</SelectItem>
<SelectItem value="option8">Armenia</SelectItem>
<SelectItem value="option9">Australia</SelectItem>
<SelectItem value="option10">Austria</SelectItem>
<SelectItem value="option11">Azerbaijan</SelectItem>
<SelectItem value="option12">Bahamas</SelectItem>
<SelectItem value="option13">Bahrain</SelectItem>
<SelectItem value="option14">Bangladesh</SelectItem>
<SelectItem value="option15">Barbados</SelectItem>
<SelectItem value="option16">Belarus</SelectItem>
<SelectItem value="option17">Belgium</SelectItem>
<SelectItem value="option18">Belize</SelectItem>
<SelectItem value="option19">Benin</SelectItem>
<SelectItem value="option20">Bhutan</SelectItem>
</SelectGroup>
</SelectContent>
</Select>

<Input id="cityOfIssuing" label="City of birth" />
</div>
</div>
);
}

export default function Create() {
const navigate = useNavigate();

return (
<div className="flex flex-col justify-between items-center gap-6 w-full min-h-fit h-screen py-4 px-5">
<Header />
<Form />

<div className="flex justify-between w-full gap-3">
<Button
className="flex-1 w-full text-text-300 bg-transparent text-sm font-medium border-text-300 rounded-[8px] py-3 px-6 hover:bg-transparent"
variant="outline"
onClick={() => navigate(routes.CONTACTS)}
>
<FormattedMessage
id="pages.createContact.cancel"
defaultMessage="Cancel"
description="Cancel contact creation button"
/>
</Button>

<Button
className="flex-1 w-full bg-text-300 text-white font-medium rounded-[8px] py-3 px-6"
onClick={() => navigate(routes.CONTACTS)}
>
<FormattedMessage
id="pages.createContact.save"
defaultMessage="Save"
description="Save contact button"
/>
</Button>
</div>
</div>
);
}
152 changes: 152 additions & 0 deletions src/pages/contacts/Overview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { useRef } from "react";
import { useNavigate } from "react-router-dom";
import { useIntl, FormattedMessage } from "react-intl";
import { EllipsisIcon, PlusIcon, SearchIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import routes from "@/constants/routes";
import contactsIllustration from "@/assets/contacts-illustration.svg";

function Search() {
const intl = useIntl();
const searchFieldRef = useRef<HTMLInputElement>(null);

const focusSearchField = () => {
searchFieldRef.current?.focus();
};

return (
<div
onClick={focusSearchField}
className="flex items-center gap-2 h-[46px] py-[14px] px-4 border-[1px] border-divider-75 rounded-[8px]"
>
<SearchIcon className="w-4 h-4 text-text-300" />

<input
ref={searchFieldRef}
type="text"
placeholder={intl.formatMessage({
id: "contacts.search.placeholder",
defaultMessage: "Search for contacts...",
description: "Placeholder text for search input",
})}
className="w-full bg-transparent text-text-300 text-sm font-medium placeholder-text-300 focus:outline-none"
/>
</div>
);
}

function Header() {
const navigate = useNavigate();

return (
<div className="flex flex-col gap-3 w-full">
<div className="flex justify-between items-center">
<h1 className="text-text-300 text-xl font-medium">
<FormattedMessage
id="contacts.header.title"
defaultMessage="Contacts"
description="Title for contacts page"
/>
</h1>

<Button
className="gap-1 p-0 h-fit text-text-300 text-xs font-medium no-underline hover:no-underline leading-[18px]"
variant="link"
onClick={() => navigate(routes.CREATE_CONTACT)}
>
<PlusIcon className="w-4 h-4 text-text-300" />
<FormattedMessage
id="contacts.header.create"
defaultMessage="New contact"
description="Create contact button"
/>
</Button>
</div>

<Search />
</div>
);
}

function Contact() {
return (
<div className="flex justify-between items-center bg-elevation-200 py-4 px-5 rounded-[12px] select-none">
<div className="flex gap-3">
<div className="flex justify-center items-center bg-brand-100 h-9 w-9 rounded-full">
<span className="text-brand-200 text-xs font-medium">PH</span>
</div>

<div className="flex flex-col">
<span className="text-text-300 text-base font-medium leading-6">
Phoenix Baker
</span>
<span className="text-text-200 text-xs leading-[18px]">Catelog</span>
</div>
</div>

<Button
className="gap-1 p-0 h-fit text-text-300 text-xs font-medium no-underline hover:no-underline leading-[18px]"
variant="link"
>
<EllipsisIcon className="w-6 h-6 text-text-300" />
</Button>
</div>
);
}

function ContactsList() {
return (
<div className="flex-1 flex flex-col gap-2 w-full">
<Contact />
<Contact />
<Contact />
<Contact />
</div>
);
}

function EmptyList() {

Check failure on line 108 in src/pages/contacts/Overview.tsx

View workflow job for this annotation

GitHub Actions / test (v22.11.0)

'EmptyList' is defined but never used
return (
<div className="flex-1 flex flex-col items-center justify-center w-52">
<img src={contactsIllustration} className="w-18 h-18 mx-auto mb-5" />

<div className="flex flex-col items-center gap-2 text-center mb-4">
<h2 className="text-text-300 text-xl font-medium leading-[30px]">
<FormattedMessage
id="contacts.empty.title"
defaultMessage="No contacts yet"
description="Title for empty contacts list"
/>
</h2>

<span className="text-text-200 text-md leading-6">
<FormattedMessage
id="contacts.empty.description"
defaultMessage="Create your first contact to start a relation"
description="Description for empty contacts list"
/>
</span>
</div>

<Button
className="w-fit text-text-300 bg-transparent text-sm font-medium border-text-300 rounded-[8px] py-3 px-6 hover:bg-transparent"
variant="outline"
>
<FormattedMessage
id="contacts.empty.create"
defaultMessage="Create contact"
description="Create contact button"
/>
</Button>
</div>
);
}

export default function Overview() {
return (
<div className="flex flex-col justify-between items-center gap-6 w-full min-h-fit h-screen py-4 px-5">
<Header />
<ContactsList />
</div>
);
}
Loading