-
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.
Merge pull request #44 from dwm-2023-2/feature/listando_reg_diarios
Feature/listando reg diarios
- Loading branch information
Showing
7 changed files
with
191 additions
and
76 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
// DiaryPageStyles.js | ||
|
||
export const ADDbuttonStyle = { | ||
position: "fixed", | ||
bottom: "250px", | ||
right: "20px", | ||
}; | ||
|
||
export const EDITbuttonStyle = { | ||
position: "fixed", | ||
bottom: "150px", | ||
right: "20px", | ||
}; | ||
|
||
export const DELETEbuttonStyle = { | ||
position: "fixed", | ||
bottom: "50px", | ||
right: "20px", | ||
color: "white", | ||
}; | ||
|
||
export const diarios = { | ||
display: "flex", | ||
flexWrap: "wrap", | ||
gap: "20px", | ||
padding: "40px", | ||
justifyContent: "center", | ||
}; | ||
|
||
export const regDiarios = { | ||
display: "flex", | ||
flexWrap: "wrap", | ||
gap: "20px", | ||
padding: "40px", | ||
justifyContent: "center", | ||
}; | ||
|
||
export const diarioTitulo = { | ||
fontSize: "14px", | ||
fontFamily: "Arial", | ||
color: "white", | ||
fontWeight: "bold", | ||
textAlign: "center", | ||
padding: "5px", | ||
}; | ||
|
||
export const diarioStyle = { | ||
backgroundColor: "#1976D2", | ||
padding: "10px", | ||
borderRadius: "10px", | ||
cursor: "pointer", | ||
width: "500px", | ||
}; |
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,108 @@ | ||
import { Header } from "../layout/Header"; | ||
import { Section } from "../layout/Section"; | ||
import { Footer } from "../layout/Footer"; | ||
import { useParams } from "react-router-dom"; | ||
import api from "../services/api"; | ||
import { useEffect, useState } from "react"; | ||
import { format } from "date-fns"; | ||
import Box from "@mui/material/Box"; | ||
import Fab from "@mui/material/Fab"; | ||
import EditIcon from "@mui/icons-material/Edit"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { | ||
EDITbuttonStyle, | ||
DELETEbuttonStyle, | ||
diarios, | ||
diarioTitulo, | ||
} from "./DiaryPageStyles"; | ||
|
||
export const RegDiaryPage = () => { | ||
const { param1 } = useParams(); | ||
const [note, setNote] = useState(null); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const submitDeleteNote = () => { | ||
const shouldDelete = window.confirm( | ||
"Are you sure you want to delete this note?" | ||
); | ||
|
||
if (shouldDelete) { | ||
api | ||
.delete(`registrosdiario/registroDiario/${param1}`) | ||
.then((response) => { | ||
console.log(response); | ||
navigate(`/diary`); | ||
}) | ||
.catch((err) => { | ||
console.error("ops! ocorreu um erro " + err); | ||
}); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await api.get( | ||
`/registrosdiario/registroDiario/${param1}` | ||
); | ||
setNote(response.data); | ||
} catch (error) { | ||
console.error("Erro ao buscar dados:", error); | ||
} | ||
}; | ||
fetchData(); | ||
}, [param1]); | ||
|
||
const formatDate = (dateString) => { | ||
const date = new Date(dateString); | ||
return format(date, "yyyy-MM-dd"); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Header></Header> | ||
<Section> | ||
<div style={diarios}> | ||
{note && ( | ||
<div key={note.tituloRegistro} style={diarioTitulo}> | ||
<p style={diarioTitulo}> | ||
<h1>Nota: {note?.tituloRegistro}</h1> | ||
</p> | ||
<br /> | ||
<p style={{ textAlign: "center" }}> | ||
<h4>Data de criação: {formatDate(note?.createdAt)}</h4> | ||
</p> | ||
<p style={{ textAlign: "center" }}> | ||
<h4>Última atualização: {formatDate(note?.updatedAt)}</h4> | ||
</p> | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: note?.conteudoRegistro || "", | ||
}} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
<Box sx={{ "& > :not(style)": { m: 1 } }}> | ||
<Fab color="secondary" aria-label="edit" style={EDITbuttonStyle}> | ||
<EditIcon /> | ||
</Fab> | ||
</Box> | ||
<Box | ||
onClick={() => submitDeleteNote()} | ||
sx={{ "& > :not(style)": { m: 1 } }} | ||
> | ||
<Fab | ||
aria-label="delete" | ||
style={{ ...DELETEbuttonStyle, backgroundColor: "#FF0000" }} | ||
> | ||
<DeleteIcon /> | ||
</Fab> | ||
</Box> | ||
</Section> | ||
<Footer></Footer> | ||
</div> | ||
); | ||
}; |