Skip to content

Commit

Permalink
Merge pull request #1565 from bcgov/refactor/naics-ui-improvements
Browse files Browse the repository at this point in the history
refactor: naics UI improvements
  • Loading branch information
dleard authored Mar 29, 2021
2 parents 0386c62 + 111fe11 commit aff729f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 36 deletions.
12 changes: 10 additions & 2 deletions app/components/Admin/CreateNaicsCodeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from 'react';
import {Button, Form, Modal, Container, Col, Row} from 'react-bootstrap';
import {Button, Form, Modal, Container, Col, Row, Alert} from 'react-bootstrap';

interface Props {
validated: boolean;
onSubmit: (e: React.SyntheticEvent<any>) => Promise<void>;
show: boolean;
onClose: () => void;
showActiveCodeError: boolean;
}

export const CreateNaicsCodeModal: React.FunctionComponent<Props> = ({
validated,
onSubmit,
show,
onClose
onClose,
showActiveCodeError
}) => {
return (
<>
Expand Down Expand Up @@ -53,6 +55,12 @@ export const CreateNaicsCodeModal: React.FunctionComponent<Props> = ({
NAICS Description is required
</Form.Control.Feedback>
</Form.Group>
{showActiveCodeError && (
<Alert variant="danger">
This NAICS code already exists. Please delete the currently
active code before entering new information
</Alert>
)}
<Button variant="primary" type="submit">
Submit
</Button>
Expand Down
36 changes: 23 additions & 13 deletions app/components/Admin/DeleteConfirmationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Button, Modal} from 'react-bootstrap';
import {Button, Modal, Alert, Col, Row} from 'react-bootstrap';

interface Props {
deleteObject: {
Expand All @@ -19,25 +19,35 @@ export const DeleteConfirmationModal: React.FunctionComponent<Props> = ({
onClose
}) => {
return (
<Modal
centered
size="sm"
show={show}
onHide={() => onClose()}
aria-modal="true"
>
<Modal.Header closeButton>
<Modal centered show={show} onHide={() => onClose()} aria-modal="true">
<Modal.Header>
<Modal.Title style={{margin: 'auto'}}>
Delete {deleteObject.deleteName}
</Modal.Title>
</Modal.Header>
<Modal.Body style={{textAlign: 'center'}}>
<p>Confirm delete {deleteObject.deleteName}:</p>
<Alert variant="danger">
<p>Are you sure you want to delete this {deleteObject.deleteName}?</p>
<p>
Doing so will immediately remove it as an option for in-progress
applications and those not yet started. Submitted applications will
not be affected.
</p>
</Alert>
<h5>{deleteObject.deleteItem}</h5>
<p>{deleteObject.deleteItemDescription}</p>
<Button onClick={handleDelete} variant="danger">
Confirm Delete
</Button>
<Row>
<Col md={{span: 4, offset: 4}}>
<Button onClick={handleDelete} variant="danger">
Confirm Delete
</Button>
</Col>
<Col md={{span: 3, offset: 1}}>
<Button onClick={onClose} variant="secondary">
Cancel
</Button>
</Col>
</Row>
</Modal.Body>
</Modal>
);
Expand Down
25 changes: 21 additions & 4 deletions app/containers/Admin/NaicsCode/NaicsCodeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,30 @@ export const NaicsCodeTableContainer: React.FunctionComponent<Props> = (
) => {
const [validated, setValidated] = useState(false);
const [showCreateModal, setShowCreateModal] = useState(false);
const [showActiveCodeError, setShowActiveCodeError] = useState(false);
const {query} = props;

const handleClose = () => {
setShowCreateModal(false);
setValidated(false);
setShowActiveCodeError(false);
};

const naicsCodeIsActive = (naicsCode) => {
return query.allNaicsCodes.edges.some(
(edge) => edge.node.naicsCode === naicsCode
);
};

const handleCreateNaicsCode = async (e: React.SyntheticEvent<any>) => {
const form = e.currentTarget;
e.stopPropagation();
e.preventDefault();
e.persist();
setValidated(true);
if (form.checkValidity() === true) {

if (naicsCodeIsActive(e.target[0].value)) setShowActiveCodeError(true);
else if (form.checkValidity() === true) {
const {environment} = props.relay;
const variables = {
input: {
Expand All @@ -38,7 +53,7 @@ export const NaicsCodeTableContainer: React.FunctionComponent<Props> = (
} catch (e) {
console.error(e);
}
setShowCreateModal(false);
handleClose();
}
};

Expand All @@ -49,14 +64,15 @@ export const NaicsCodeTableContainer: React.FunctionComponent<Props> = (
style={{marginTop: '-100px'}}
onClick={() => setShowCreateModal(true)}
>
New Naics Code
New NAICS Code
</Button>
</div>
<CreateNaicsCodeModal
validated={validated}
onSubmit={handleCreateNaicsCode}
show={showCreateModal}
onClose={() => setShowCreateModal(false)}
onClose={() => handleClose()}
showActiveCodeError={showActiveCodeError}
/>
<Table striped bordered hover>
<thead>
Expand Down Expand Up @@ -101,6 +117,7 @@ export default createFragmentContainer(NaicsCodeTableContainer, {
edges {
node {
id
naicsCode
...NaicsCodeTableRow_naicsCode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('CreateNaicsCodeModal', () => {
);
expect(renderer).toMatchSnapshot();
});
it('should call handleCreateNaicsCode when the form is submitted', async () => {
it('should call handleDelete when the Confirm button is clicked', async () => {
const handleDelete = jest.fn();
const renderer = shallow(
<DeleteConfirmationModal
Expand All @@ -32,7 +32,7 @@ describe('CreateNaicsCodeModal', () => {
onClose={jest.fn()}
/>
);
renderer.find('Button').prop('onClick')({} as any);
renderer.find('Button').at(0).prop('onClick')({} as any);
expect(handleDelete).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ exports[`CreateNaicsCodeModal should match the snapshot with the DeleteConfirmat
onHide={[Function]}
restoreFocus={true}
show={true}
size="sm"
>
<ModalHeader
closeButton={true}
closeButton={false}
closeLabel="Close"
>
<ModalTitle
Expand All @@ -43,25 +42,78 @@ exports[`CreateNaicsCodeModal should match the snapshot with the DeleteConfirmat
}
}
>
<p>
Confirm delete
NAICS Code
:
</p>
<Alert
closeLabel="Close alert"
show={true}
transition={
Object {
"$$typeof": Symbol(react.forward_ref),
"defaultProps": Object {
"appear": false,
"in": false,
"mountOnEnter": false,
"timeout": 300,
"unmountOnExit": false,
},
"displayName": "Fade",
"render": [Function],
}
}
variant="danger"
>
<p>
Are you sure you want to delete this
NAICS Code
?
</p>
<p>
Doing so will immediately remove it as an option for in-progress applications and those not yet started. Submitted applications will not be affected.
</p>
</Alert>
<h5>
1234
</h5>
<p>
description
</p>
<Button
active={false}
disabled={false}
onClick={[MockFunction]}
variant="danger"
<Row
noGutters={false}
>
Confirm Delete
</Button>
<Col
md={
Object {
"offset": 4,
"span": 4,
}
}
>
<Button
active={false}
disabled={false}
onClick={[MockFunction]}
variant="danger"
>
Confirm Delete
</Button>
</Col>
<Col
md={
Object {
"offset": 1,
"span": 3,
}
}
>
<Button
active={false}
disabled={false}
onClick={[MockFunction]}
variant="secondary"
>
Cancel
</Button>
</Col>
</Row>
</ModalBody>
</Modal>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ exports[`NaicsCodeTable should match the snapshot with the NaicsCodeTable contai
}
variant="primary"
>
New Naics Code
New NAICS Code
</Button>
</div>
<CreateNaicsCodeModal
onClose={[Function]}
onSubmit={[Function]}
show={false}
showActiveCodeError={false}
validated={false}
/>
<ForwardRef
Expand Down

0 comments on commit aff729f

Please sign in to comment.