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

add contact detail dialog #3

Open
wants to merge 1 commit into
base: initial
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions contacts-frontend/src/contacts/ContactDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Table from "react-bootstrap/Table";
import React, { useCallback, useEffect, useState } from "react";
import Button from "react-bootstrap/Button";
import Col from "react-bootstrap/Col";
import Form from "react-bootstrap/Form";
import Modal from "react-bootstrap/Modal";
import Row from "react-bootstrap/Row";
import { Contact } from "../apiclient";

export interface ContactDetailProps {
contact: Contact;
onCancel: () => void;
}

export default function ContactDetail({
contact,
onCancel,
}: ContactDetailProps): JSX.Element {
const [title, setTitle] = useState<string>();

setTitle(`Contact: ${contact.firstName} ${contact.lastName}`);

return (
<Modal show={true} onHide={onCancel} data-testid="ContactModal">
<Modal.Header closeButton>
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
<Modal.Body>
<Table striped bordered hover data-testid="ContactsTable">
<thead>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>First name</td>
<td>{contact.firstName}</td>
</tr>
<tr>
<td>Last name</td>
<td>{contact.lastName}</td>
</tr>
<tr>
<td>E-Mail</td>
<td>{contact.email}</td>
</tr>
<tr>
<td>Birthday</td>
<td>{contact.birthday}</td>
</tr>
<tr>
<td>Title</td>
<td>{contact.title}</td>
</tr>
<tr>
<td>Company</td>
<td>{contact.company}</td>
</tr>
</tbody>
</Table>
</Modal.Body>
</Modal>
);
}
19 changes: 19 additions & 0 deletions contacts-frontend/src/contacts/ContactPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import ApiContext from "../ApiContext";
import Table from "react-bootstrap/Table";
import { Button } from "react-bootstrap";
import ContactDialog from "./ContactDialog";
import ContactDetail from "./ContactDetail";

export default function ContactPanel(): JSX.Element {
const api = useContext(ApiContext);

const [contacts, setContacts] = useState<Contact[]>([]);
const [addNew, setAddNew] = useState(false);
const [showDetail, setShowDetail] = useState<Contact | undefined>(undefined);
const [editContact, setEditContact] = useState<Contact | undefined>(
undefined
);
Expand Down Expand Up @@ -86,6 +88,14 @@ export default function ContactPanel(): JSX.Element {
onSave={onSave}
/>
)}
{showDetail && (
<ContactDetail
contact={showDetail}
onCancel={() => {
setShowDetail(undefined);
}}
/>
)}
{editContact && (
<ContactDialog
contact={editContact}
Expand Down Expand Up @@ -127,6 +137,15 @@ export default function ContactPanel(): JSX.Element {
<td>{contact.title}</td>
<td>{contact.company}</td>
<td>
<Button
variant="secondary"
style={{ marginRight: "20px" }}
onClick={() => {
setShowDetail(contact);
}}
>
Show Contact
</Button>
<Button
variant="primary"
style={{ marginRight: "20px" }}
Expand Down