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

Wokers list #7

Merged
merged 8 commits into from
Dec 10, 2020
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
12 changes: 10 additions & 2 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from "react";
import React, { useState } from "react";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import "./App.css";
import { CreateWorker } from "./pages";
import { CreateWorker, ShowWorkers } from "./pages";


export function App() {
const [trigger, setTrigger] = useState(false);
const workersHandle = () => setTrigger(!trigger);
return (
<Router>
<main role="main">
<Link to="/">Home</Link>
<br />
<Link to="add-worker">Create cleaner</Link>
<br />
<Link to="workers" onClick={workersHandle}>Show cleaners</Link>
</main>
<Switch>
<Route path="/add-worker">
<CreateWorker />
</Route>
<Route path="/workers">
<ShowWorkers trigger={trigger} />
</Route>
</Switch>
</Router>
);
Expand Down
49 changes: 49 additions & 0 deletions client/src/components/ShowWorkersForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useState ,useEffect } from "react";
import { Table } from "reactstrap";


import { getWorkers } from "../service";
const ShowWorkersForm = ({ trigger }) => {
const [list, setList] = useState();
useEffect(() => getWorkers()
.then((data) => setList(data.workers))
.catch((err) => console.error(err)),[trigger]);


if (list) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty array is a truthy value so this if statement will always execute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

return (
<Table striped>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
<th>WhatsApp</th>
</tr>
</thead>
<tbody>
{list.map((worker) => {
return(
<tr key={worker.id}>
<th scope="row">{worker.id}</th>
<td>{worker.name}</td>
<td>{worker.address}</td>
<td>{worker.email}</td>
<td>{worker.phone_number}</td>
<td>{worker.whatsapp}</td>
</tr>
);
} )}


</tbody>
</Table>
);
} else {
return <> </>;
}
};

export default ShowWorkersForm;
2 changes: 2 additions & 0 deletions client/src/components/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as CreateWorkerForm } from "./CreateWorkerForm";

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please could you explain why you've added this commit? Thanks to version control there isn't any need to add white space - if you absolutely need to add a TODO you can add commented out lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just fixed the code according to all the comments from the reviews.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Harriethw I originally added that file to make it more clear and tidy when we will import them inside App.js or /pages. More info here https://www.digitalocean.com/community/tutorials/react-index-js-public-interfaces#using-indexjs

Copy link
Collaborator

Choose a reason for hiding this comment

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

@g1st ah I just meant that we don't need empty white space, which is all this commit seems to add unless I'm missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yesterday we made a customer list with Hadiyah. It doesn't work on her computer. I made the same code for workers and it works. I added empty spaces for her code. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry @Harriethw yes I agree. I already proposed @GTabala to use Prettier and it can take care of those empty spaces for us!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prettier doesn't delete empty lines.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I don't know who does it then but when I save a file with loads of empty lines they get deleted for me.

export { default as ShowWorkersForm } from "./ShowWorkersForm";
21 changes: 21 additions & 0 deletions client/src/pages/ShowWorkers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import PropTypes from "prop-types";
import { Container } from "reactstrap";
import { ShowWorkersForm } from "../components";

const ShowWorkers = ({ trigger }) => {
return (
<Container>
<h2 className="text-center mt-4 mt-md-5 mb-5 mb-md-5">
Cleaners
</h2>
<ShowWorkersForm trigger={trigger} />
</Container>
);
};

ShowWorkers.propTypes = {
trigger: PropTypes.bool,
};

export default ShowWorkers;
2 changes: 2 additions & 0 deletions client/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as CreateWorker } from "./CreateWorker.js";

export { default as ShowWorkers } from "./ShowWorkers.js";
14 changes: 13 additions & 1 deletion client/src/service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { post } from "./api";
import { post, get } from "./api";

export const postWorkers = async (data) => {
const response = await post("/workers", data);
return response.data;
};








export const getWorkers = async () => {
const response = await get("/workers");
return response.data;
};