-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pouriya moshfegh
committed
Jun 1, 2023
1 parent
874bae5
commit 1aaab0f
Showing
26 changed files
with
433 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { useState, useEffect } from "react"; | ||
import DeleteRoundedIcon from "@mui/icons-material/DeleteRounded"; | ||
import { DataGrid } from "@mui/x-data-grid"; | ||
import DeletModal from "../Modal/DeletModal"; | ||
import EditIcon from "@mui/icons-material/Edit"; | ||
|
||
export default function Commetns() { | ||
|
||
// ___________ states ___________ | ||
const [targetItem, setTargetItem] = useState(""); | ||
const [rows, setRows] = useState([]); | ||
const [open, setOpen] = useState(false); | ||
|
||
const columns = [ | ||
{ | ||
field: "userID", | ||
headerName: "user", | ||
width: 100, | ||
headerClassName: " text-white font-bold", | ||
}, | ||
{ | ||
field: "productID", | ||
headerName: "product", | ||
sortable: false, | ||
width: 130, | ||
headerClassName: "text-white font-bold", | ||
}, | ||
{ | ||
field: "body", | ||
headerName: "Comment", | ||
width: 350, | ||
headerClassName: "text-white font-bold", | ||
}, | ||
{ | ||
field: "date", | ||
headerName: "Date", | ||
width: 150, | ||
headerClassName: "text-white font-bold", | ||
}, | ||
{ | ||
field: "hour", | ||
headerName: "Time", | ||
width: 100, | ||
headerClassName: "text-white font-bold", | ||
}, | ||
{ | ||
field: "Edit", | ||
headerName: "", | ||
description: "delet item info", | ||
sortable: false, | ||
width: 110, | ||
headerClassName: "text-white font-bold", | ||
renderCell: (params) => { | ||
return ( | ||
<div> | ||
<button | ||
onClick={() => { | ||
handleOpen(); | ||
setTargetItem(params.row.id); | ||
}} | ||
> | ||
<DeleteRoundedIcon /> | ||
</button> | ||
<button | ||
className="mx-4" | ||
onClick={() => { | ||
handleOpen(); | ||
setTargetItem(params.row.id); | ||
}} | ||
> | ||
<EditIcon /> | ||
</button> | ||
</div> | ||
); | ||
}, | ||
}, | ||
]; | ||
|
||
// ___________ data ___________ | ||
const getProdcuts = useEffect(() => { | ||
fetch("http://localhost:8000/api/comments") | ||
.then((res) => res.json()) | ||
.then((res) => setRows(res)); | ||
}, []); | ||
const commentDeleteApi = fetch( | ||
`http://localhost:8000/api/comments/${targetItem.toString()}`, | ||
{ | ||
method: "DELETE", | ||
} | ||
).then((res) => console.log(res)); | ||
|
||
// ___________ functions ___________ | ||
const commentDeleteDom = () => { | ||
setRows((pervRows) => | ||
pervRows.filter((eachrow) => { | ||
return eachrow.id !== targetItem; | ||
}) | ||
); | ||
}; | ||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
|
||
|
||
|
||
return ( | ||
<section className="box-container"> | ||
<div className="mx-auto border-none"> | ||
<h1 className="text-2xl">Comments</h1> | ||
<DataGrid | ||
className={`border-none mt-4`} | ||
rows={rows} | ||
columns={columns} | ||
disableRowSelectionOnClick | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 5, | ||
}, | ||
}, | ||
}} | ||
pageSizeOptions={[5]} | ||
/> | ||
</div> | ||
{/* ___________ delete Modal ___________ */} | ||
<DeletModal | ||
open={open} | ||
handleClose={handleClose} | ||
targetItem={targetItem} | ||
targetDelete={commentDeleteDom} | ||
fetchFunc={commentDeleteApi} | ||
/> | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable react/prop-types */ | ||
|
||
import Button from "@mui/material/Button"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
|
||
export default function DeletModal({ | ||
open, | ||
handleClose, | ||
targetDelete, | ||
fetchFunc | ||
|
||
}) { | ||
return ( | ||
<Dialog open={open} keepMounted onClose={handleClose}> | ||
<div className="h-40 w-50 bg-secondary text-white pt-8 p-4"> | ||
<h2 className="font-bold text-xl"> | ||
Are You sure you want to delete the Products? | ||
</h2> | ||
</div> | ||
<DialogActions className="bg-secondary/90"> | ||
<Button variant="contained" color="success" onClick={handleClose}> | ||
Ignore | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="error" | ||
onClick={() => { | ||
handleClose(); | ||
targetDelete(); | ||
fetchFunc | ||
|
||
}} | ||
> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable react/prop-types */ | ||
|
||
import Button from "@mui/material/Button"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
|
||
export default function DeletModal({ | ||
open, | ||
handleClose, | ||
targetEdit, | ||
fetchFunc | ||
|
||
}) { | ||
return ( | ||
<Dialog open={open} keepMounted onClose={handleClose}> | ||
<div className="h-40 w-50 bg-secondary text-white pt-8 p-4"> | ||
<h2 className="font-bold text-xl"> | ||
Are You sure you want to delete the Products? | ||
</h2> | ||
</div> | ||
<DialogActions className="bg-secondary/90"> | ||
<Button variant="contained" color="success" onClick={handleClose}> | ||
Ignore | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="error" | ||
onClick={() => { | ||
handleClose(); | ||
targetEdit(); | ||
fetchFunc | ||
|
||
}} | ||
> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
Oops, something went wrong.