-
Notifications
You must be signed in to change notification settings - Fork 2
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
Wokers list #7
Changes from 3 commits
099a168
9cbe82f
2cc53f1
8f6a497
2743797
ddaf5cc
51da30c
c6afa54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 = ({ kick }) => { | ||
const [list, setList] = useState([]); | ||
useEffect(() => getWorkers() | ||
.then((data) => setList(data.workers)) | ||
.catch((err) => console.error(err)),[kick]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking to have custom hook like form here https://www.digitalocean.com/community/tutorials/creating-a-custom-usefetch-react-hook. Then we would reuse it through our app and we would have |
||
|
||
|
||
if (list) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty array is a truthy value so this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { default as CreateWorkerForm } from "./CreateWorkerForm"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier doesn't delete empty lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import { Container } from "reactstrap"; | ||
import { ShowWorkersForm } from "../components"; | ||
|
||
const ShowWorkers = ({kick}) => { | ||
return ( | ||
<Container> | ||
<h2 className="text-center mt-4 mt-md-5 mb-5 mb-md-5"> | ||
Cleaners | ||
</h2> | ||
<ShowWorkersForm kick={kick} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ShowWorkers; |
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"; |
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 (data) => { | ||
const response = await get("/workers", data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
return response.data; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this a bit more descriptive, maybe
triggerFetch
ortriggerRefetch
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "trigger".