Skip to content

Commit

Permalink
edit comments start
Browse files Browse the repository at this point in the history
  • Loading branch information
pouriya moshfegh committed Jun 1, 2023
1 parent 874bae5 commit 1aaab0f
Show file tree
Hide file tree
Showing 26 changed files with 433 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',

'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
Expand Down
34 changes: 8 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"@ramonak/react-progress-bar": "^5.0.3",
"localforage": "^1.10.0",
"match-sorter": "^6.3.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.0",
"recharts": "^2.5.0",
"sort-by": "^1.2.0"
"sort-by": "^0.0.2"
},
"devDependencies": {
"@types/react": "^18.0.28",
Expand Down
36 changes: 19 additions & 17 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ import { useNavigate } from 'react-router-dom';


function App() {
const navigate = useNavigate();

// const navigate = useNavigate();
const [searchValue, setSearchValue] = useState("");
const [isSearchOpen, setIsSearchOpen] = useState(false);
const [isDark, setIsDark] = useState(true);

useEffect(() => {
alanBtn({
key: "ee46d96470e10e9466118216852e693d2e956eca572e1d8b807a3e2338fdd0dc/stage",
onCommand: (commandData) => {
commandData.command === "lite" && setIsDark(false);
commandData.command === "dark" && setIsDark(true);
commandData.command === "users" && navigate('/users', { replace: true });
commandData.command === "newUsers" && navigate('/newuser', { replace: true });
commandData.command === "products" && navigate('/products', { replace: true });
commandData.command === "home" && navigate('/', { replace: true });
// useEffect(() => {
// alanBtn({
// key: "ee46d96470e10e9466118216852e693d2e956eca572e1d8b807a3e2338fdd0dc/stage",
// onCommand: (commandData) => {
// commandData.command === "lite" && setIsDark(false);
// commandData.command === "dark" && setIsDark(true);
// commandData.command === "users" && navigate('/users', { replace: true });
// commandData.command === "newUsers" && navigate('/newuser', { replace: true });
// commandData.command === "products" && navigate('/products', { replace: true });
// commandData.command === "home" && navigate('/', { replace: true });

// },
// });
// }, []);

},
});
}, []);

localStorage.clear();

let router = useRoutes(routes);
return (

<MainContext.Provider
value={{
searchValue,
Expand All @@ -49,9 +51,9 @@ function App() {
<div className={isDark ? "" : "dark"}>
<TopBar />
<Sidebar />
<div className="flex ">
<div className="flex">
<div className="nav-size"></div>
<div className="right-side ">{router}</div>
<div className="right-side">{router}</div>
</div>
</div>
</MainContext.Provider>
Expand Down
138 changes: 138 additions & 0 deletions src/Components/Comments/CommentsComp.jsx
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>
);
}
2 changes: 1 addition & 1 deletion src/Components/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Dashboard() {
return (
<div className="w-full relative top-3 scale-105 md:hidden">
<Link to="..">
<CloseIcon className="absolute top-2 right-2 z-50" />
<CloseIcon className="absolute dark:text-secondary top-2 right-2 z-50" />
</Link>
<SideBaritems />
</div>
Expand Down
40 changes: 40 additions & 0 deletions src/Components/Modal/DeletModal.jsx
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>
);
}
40 changes: 40 additions & 0 deletions src/Components/Modal/EditModal.jsx
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>
);
}
Loading

0 comments on commit 1aaab0f

Please sign in to comment.