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

frontend: add a scrollDown for issue replies and Delete buttom #355

Merged
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
27 changes: 17 additions & 10 deletions src/frontend/src/Pages/Issue.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useParams } from "react-router-dom";
import { useState, useEffect, useContext } from "react";
import { useState, useEffect, useContext, useRef } from "react";
import fetchData from "../utilities/fetchData";
import { UserContext } from "./Root";
import Button from "../components/generalPurpose/Button";
export default function Issue() {
const scrollRef = useRef();
const {user} = useContext(UserContext);
const { issueId } = useParams();
const [error, setError] = useState(false);
Expand Down Expand Up @@ -38,7 +40,11 @@ export default function Issue() {
}
fetchIssue();
}, [issueId]);

useEffect(()=>{
if(scrollRef.current){
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
}
},[issue]);
const handleClickDeleteIssue = async () => {
const response = await fetchData(
`http://localhost:3000/api/issues/${issueId}`,
Expand Down Expand Up @@ -95,6 +101,7 @@ export default function Issue() {
<p className="text-gray-700">{issue.description}</p>
</div>
<div className="p-1">
<div ref={scrollRef} className="overflow-y-scroll h-80">
{issue.replies.map((reply) => (
<div key={reply._id} className="mb-1 p-4 bg-gray-100">
<p className="text-gray-800">{reply.body}</p>
Expand All @@ -105,6 +112,7 @@ export default function Issue() {
</div>
))}
</div>
</div>

<div className="p-4">
<textarea
Expand All @@ -117,12 +125,15 @@ export default function Issue() {
{!isTextAreaValid && (
<p className="text-red-500">This field is required</p>
)}
<button
className="mt-2 px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:outline-none"
<button
className={`bg-blue-500 hover:bg-blue-600 text-white font-semibold px-4 py-2 rounded`}
onClick={handleReply}
>
Reply
</button>
{/* <Button handler={(e)=>handleReply(e)} text="Reply" color="blue" inline={true}/> */}
<Button handler={()=>setDeleteBtn(true)} color={"red"} text={"delete"} inline={true}/>

{!replySucceeded&&<span className="text-red-500"> failed to send the reply</span>}
</div>
</div>
Expand All @@ -148,12 +159,8 @@ export default function Issue() {
<span className="text-red-500">issue {issueId}</span>?
</p>
<div className="flex justify-end">
<button
className="bg-red-500 hover:bg-red-600 text-white font-semibold px-4 py-2 rounded mr-4"
onClick={handleClickDeleteIssue}
>
Delete
</button>
<Button handler={handleClickDeleteIssue} color={"red"} text={"delete"} inline={true}/>

<button
className="bg-gray-200 hover:bg-gray-300 text-gray-800 font-semibold px-4 py-2 rounded"
onClick={() => setDeleteBtn(false)}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/generalPurpose/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function Button({ type="", handler, value = null, text, color, in
<div className={`m-1 ${inline ? "inline" : "block"}`}>
<button
type={type}
onClick={() => handler && handler(value)}
onClick={() => handler(value) && handler}

className={`bg-${color}-500 hover:bg-${color}-600 text-white font-semibold px-4 py-2 rounded`}
>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/components/header/AccountDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function showAccountButton(setToken,user){
<Link to="user/reservation"><p className={"p-2 block cursor-pointer hover:bg-gray-600"}/* onClick={()=> window.open("/user/reservation", "_self")}*/>My Reservations</p></Link>
{(user && user.role === "admin") && <Link to="dashboard"><p className={"p-2 block cursor-pointer hover:bg-slate-600"}>Admin Dashboard</p></Link>}
{(user && user.role === "representative") && <Link to="/csr/dashboard"><p className={"p-2 block cursor-pointer hover:bg-slate-600"}>CSR Dashboard</p></Link>}
{(user && user.role === "customer") && <Link to="issues"><p className={"p-2 block cursor-pointer hover:bg-slate-600"}>Report an Issue</p></Link>}
<hr/>
<Link to="/"><p className={"p-2 block cursor-pointer hover:bg-slate-600"} onClick={()=>logoutAccount(setToken)}>Logout</p></Link>

Expand Down
Loading