From 61c0d1c3f06107a40bd30279e098be590b6caf73 Mon Sep 17 00:00:00 2001
From: Dani Yanani
Date: Mon, 24 Feb 2025 12:04:06 +0000
Subject: [PATCH 1/3] parte_1
---
"src/pages/A\303\261adirCoontacto.jsx" | 0
src/pages/EditarContacto.jsx | 0
src/pages/EliminarContacto.jsx | 0
src/pages/ListaDeContactos.jsx | 47 +++++++++++++++++++++++
src/store.js | 52 ++++++++++++++++----------
5 files changed, 80 insertions(+), 19 deletions(-)
create mode 100644 "src/pages/A\303\261adirCoontacto.jsx"
create mode 100644 src/pages/EditarContacto.jsx
create mode 100644 src/pages/EliminarContacto.jsx
create mode 100644 src/pages/ListaDeContactos.jsx
diff --git "a/src/pages/A\303\261adirCoontacto.jsx" "b/src/pages/A\303\261adirCoontacto.jsx"
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/pages/EditarContacto.jsx b/src/pages/EditarContacto.jsx
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/pages/EliminarContacto.jsx b/src/pages/EliminarContacto.jsx
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/pages/ListaDeContactos.jsx b/src/pages/ListaDeContactos.jsx
new file mode 100644
index 000000000..55ba25a5e
--- /dev/null
+++ b/src/pages/ListaDeContactos.jsx
@@ -0,0 +1,47 @@
+import { useEffect } from "react"
+import useGlobalReducer from "../hooks/useGlobalReducer"
+
+
+export const ListaDeContactos = async () => {
+ const { store, dispatch } = useGlobalReducer()
+ const getContacts = async () => {
+ try {
+ const response = await fletch()
+ if (!response.ok) throw new Error("No se pudo cargar los datos.")
+ const data = await response.json()
+
+ console.log (data.contacts);
+
+ dispatch(
+ {
+ type: actualizarContacto,
+ payload: data.contacts
+ }
+ )
+ } catch (error) {
+
+ }
+
+ return (
+
+ <>
+
+ {store.contacts.lengh === 0 ? (
+ No Hay .
+ ) :
+ (
+ toDoArray.map(toDo) => (
+ eliminarTarea(toDo.idCounter)}
+ ))
+ )}
+
+ >
+
+
+ useEffect(() => {getContacts()},[])
+ }
+
diff --git a/src/store.js b/src/store.js
index 933c7bc40..aada54963 100644
--- a/src/store.js
+++ b/src/store.js
@@ -1,32 +1,46 @@
-export const initialStore=()=>{
- return{
- message: null,
- todos: [
- {
- id: 1,
- title: "Make the bed",
- background: null,
- },
+export const initialStore = () => {
+ return {
+
+ "contacts": [
{
- id: 2,
- title: "Do my homework",
- background: null,
+ "name": "",
+ "phone": "",
+ "email": "",
+ "address": "",
+ "id": 0
}
]
}
}
+
export default function storeReducer(store, action = {}) {
- switch(action.type){
- case 'add_task':
+ switch (action.type) {
- const { id, color } = action.payload
+ case 'aƱadirContacto':
+ return {
+ ...store, agendas: action.payload
+ };
+ case 'editarContacto':
return {
+
...store,
- todos: store.todos.map((todo) => (todo.id === id ? { ...todo, background: color } : todo))
+ contacts: store.contacts.map(contact =>
+ contact.id === action.payload.id ? action.payload :
+ contact.name
+ )
};
+
+ case 'eliminarContacto':
+
+ return {
+ ...store,
+ contacts: store.contact.filter(contact => contact.id !== action.payload)
+ };
+
default:
- throw Error('Unknown action.');
- }
-}
+ throw new Error("Unknow Action.");
+
+ }
+}
\ No newline at end of file
From b50ebf52b1591b0f38d5ca7be09b2baa6993efbd Mon Sep 17 00:00:00 2001
From: Dani Yanani
Date: Mon, 24 Feb 2025 14:57:23 +0000
Subject: [PATCH 2/3] paso_2
---
.../pages/AddContact.jsx | 0
src/pages/ContactList.jsx | 64 +++++++++++++++++++
.../{EditarContacto.jsx => DeleteContact.jsx} | 0
.../{EliminarContacto.jsx => EditContact.jsx} | 0
src/pages/ListaDeContactos.jsx | 47 --------------
src/routes.jsx | 7 +-
src/store.js | 30 +++++----
7 files changed, 84 insertions(+), 64 deletions(-)
rename "src/pages/A\303\261adirCoontacto.jsx" => src/pages/AddContact.jsx (100%)
create mode 100644 src/pages/ContactList.jsx
rename src/pages/{EditarContacto.jsx => DeleteContact.jsx} (100%)
rename src/pages/{EliminarContacto.jsx => EditContact.jsx} (100%)
delete mode 100644 src/pages/ListaDeContactos.jsx
diff --git "a/src/pages/A\303\261adirCoontacto.jsx" b/src/pages/AddContact.jsx
similarity index 100%
rename from "src/pages/A\303\261adirCoontacto.jsx"
rename to src/pages/AddContact.jsx
diff --git a/src/pages/ContactList.jsx b/src/pages/ContactList.jsx
new file mode 100644
index 000000000..3acc3ea13
--- /dev/null
+++ b/src/pages/ContactList.jsx
@@ -0,0 +1,64 @@
+import { useEffect } from "react"
+import { useNavigate } from "react-router-dom"
+import useGlobalReducer from "../hooks/useGlobalReducer"
+import { func } from "prop-types"
+
+
+export const ContactList = () => {
+
+ const { store, dispatch } = useGlobalReducer();
+
+ useEffect(() => {
+ const getContacts = async () => {
+ try {
+ const response = await fletch('https://playground.4geeks.com/contact/agendas/Dani');
+
+ if (!response.ok) {
+ throw new Error("No se pudo cargar los datos.");
+ }
+
+ const data = await response.json();
+
+ setContacts(data.contact)
+
+ console.log(data.contacts);
+
+ dispatch(
+ {
+ type: editontact,
+ payload: {contact: data.contact}
+ }
+ )
+ }
+
+ catch (error) { console.error("No se descargaron los datos"); };
+
+
+ return (
+ <>
+
+ {store.contacts.length === 0 ? (
+ No Hay Tareas Pendientes
+ ) : (
+ store.contacts.map((contact) => (
+
+ deleteTask(toDo.idCounter)}
+ />
+ ))
+ )}
+
+ >
+ );
+
+
+
+
+
+
+ useEffect(() => { getContacts() }, [])
+ }
+ };
diff --git a/src/pages/EditarContacto.jsx b/src/pages/DeleteContact.jsx
similarity index 100%
rename from src/pages/EditarContacto.jsx
rename to src/pages/DeleteContact.jsx
diff --git a/src/pages/EliminarContacto.jsx b/src/pages/EditContact.jsx
similarity index 100%
rename from src/pages/EliminarContacto.jsx
rename to src/pages/EditContact.jsx
diff --git a/src/pages/ListaDeContactos.jsx b/src/pages/ListaDeContactos.jsx
deleted file mode 100644
index 55ba25a5e..000000000
--- a/src/pages/ListaDeContactos.jsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { useEffect } from "react"
-import useGlobalReducer from "../hooks/useGlobalReducer"
-
-
-export const ListaDeContactos = async () => {
- const { store, dispatch } = useGlobalReducer()
- const getContacts = async () => {
- try {
- const response = await fletch()
- if (!response.ok) throw new Error("No se pudo cargar los datos.")
- const data = await response.json()
-
- console.log (data.contacts);
-
- dispatch(
- {
- type: actualizarContacto,
- payload: data.contacts
- }
- )
- } catch (error) {
-
- }
-
- return (
-
- <>
-
- {store.contacts.lengh === 0 ? (
- No Hay .
- ) :
- (
- toDoArray.map(toDo) => (
- eliminarTarea(toDo.idCounter)}
- ))
- )}
-
- >
-
-
- useEffect(() => {getContacts()},[])
- }
-
diff --git a/src/routes.jsx b/src/routes.jsx
index 0557df614..23ef8e1f8 100644
--- a/src/routes.jsx
+++ b/src/routes.jsx
@@ -9,6 +9,7 @@ import { Layout } from "./pages/Layout";
import { Home } from "./pages/Home";
import { Single } from "./pages/Single";
import { Demo } from "./pages/Demo";
+import { ContactList } from "./pages/ContactList";
export const router = createBrowserRouter(
createRoutesFromElements(
@@ -22,9 +23,9 @@ export const router = createBrowserRouter(
} errorElement={Not found! } >
{/* Nested Routes: Defines sub-routes within the BaseHome component. */}
- } />
- } /> {/* Dynamic route for single items */}
- } />
+ } />
+ } /> {/* Dynamic route for single items */}
+ } />
)
);
\ No newline at end of file
diff --git a/src/store.js b/src/store.js
index aada54963..0f3160b33 100644
--- a/src/store.js
+++ b/src/store.js
@@ -1,7 +1,7 @@
export const initialStore = () => {
return {
- "contacts": [
+ contacts: [
{
"name": "",
"phone": "",
@@ -17,30 +17,32 @@ export const initialStore = () => {
export default function storeReducer(store, action = {}) {
switch (action.type) {
- case 'aƱadirContacto':
+ case "addContact":
return {
- ...store, agendas: action.payload
+ ...store,
+ contacts: action.payload
};
- case 'editarContacto':
+ case "editcontact":
return {
-
...store,
- contacts: store.contacts.map(contact =>
- contact.id === action.payload.id ? action.payload :
- contact.name
- )
+ contacts: [...store.contacts, action.payload]
};
- case 'eliminarContacto':
+ case "deleteContact":
return {
...store,
- contacts: store.contact.filter(contact => contact.id !== action.payload)
+ contacts: store.contacts.filter(contact => contact.id !== action.payload)
};
- default:
- throw new Error("Unknow Action.");
+
+
+ default: return store;
}
-}
\ No newline at end of file
+
+
+}
+
+
\ No newline at end of file
From 40464a10f11445a6aa5bc694521c3053235765d9 Mon Sep 17 00:00:00 2001
From: Dani Yanani
Date: Tue, 25 Feb 2025 16:58:46 +0000
Subject: [PATCH 3/3] parte_3
---
src/components/CardContact.jsx | 31 ++++++++++++++
src/components/Navbar.jsx | 44 ++++++++++++++------
src/main.jsx | 4 ++
src/pages/AddContact.jsx | 0
src/pages/ContactList.jsx | 64 -----------------------------
src/pages/Contacts/AddContact.jsx | 14 +++++++
src/pages/Contacts/ContactList.jsx | 53 ++++++++++++++++++++++++
src/pages/Contacts/EditContact.jsx | 14 +++++++
src/pages/Contacts/ViewContacts.jsx | 13 ++++++
src/pages/DeleteContact.jsx | 0
src/pages/EditContact.jsx | 0
src/pages/Home.jsx | 6 ++-
src/pages/Layout.jsx | 6 ++-
src/pages/Single.jsx | 37 -----------------
src/routes.jsx | 43 ++++++++-----------
src/store.js | 19 +++++----
16 files changed, 197 insertions(+), 151 deletions(-)
create mode 100644 src/components/CardContact.jsx
delete mode 100644 src/pages/AddContact.jsx
delete mode 100644 src/pages/ContactList.jsx
create mode 100644 src/pages/Contacts/AddContact.jsx
create mode 100644 src/pages/Contacts/ContactList.jsx
create mode 100644 src/pages/Contacts/EditContact.jsx
create mode 100644 src/pages/Contacts/ViewContacts.jsx
delete mode 100644 src/pages/DeleteContact.jsx
delete mode 100644 src/pages/EditContact.jsx
delete mode 100644 src/pages/Single.jsx
diff --git a/src/components/CardContact.jsx b/src/components/CardContact.jsx
new file mode 100644
index 000000000..288eac7f5
--- /dev/null
+++ b/src/components/CardContact.jsx
@@ -0,0 +1,31 @@
+import React from "react";
+import { useNavigate } from "react-router-dom";
+
+
+function CardContact(props) {
+
+ const navigate = useNavigate()
+
+ return (
+
+ <>
+
+
+
+
+
{props.contactName}
+
+
+ {props.contactMail}
+ {props.contactPhone}
+ {props.contactAddress}
+
+
+
+ >
+ )
+}
+export default CardContact;
\ No newline at end of file
diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx
index 30d43a263..3bd123556 100644
--- a/src/components/Navbar.jsx
+++ b/src/components/Navbar.jsx
@@ -1,19 +1,37 @@
+import React from "react";
+import { useNavigate } from "react-router-dom";
import { Link } from "react-router-dom";
-export const Navbar = () => {
+function Navbar() {
+ const navigate = useNavigate();
+
+ const goHome =() => {
+ navigate('/');
+ };
+ const goBack = () => {
+ navigate(-1);
+ };
+
return (
-
-
-
-
React Boilerplate
-
-
-
- Check the Context in action
-
-
-
+
+
+
+ Lista de contactos
+
+
+
+ Acerca de
+
+
+
+ Contacto
+
+
+
+
);
-};
\ No newline at end of file
+};
+
+export default Navbar;
\ No newline at end of file
diff --git a/src/main.jsx b/src/main.jsx
index 3a122d76a..f83d4cede 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -5,8 +5,12 @@ import { RouterProvider } from "react-router-dom"; // Import RouterProvider to
import { router } from "./routes"; // Import the router configuration
import { StoreProvider } from './hooks/useGlobalReducer'; // Import the StoreProvider for global state management
+
+
+
const Main = () => {
return (
+
{/* Provide global state to all components */}
diff --git a/src/pages/AddContact.jsx b/src/pages/AddContact.jsx
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/pages/ContactList.jsx b/src/pages/ContactList.jsx
deleted file mode 100644
index 3acc3ea13..000000000
--- a/src/pages/ContactList.jsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import { useEffect } from "react"
-import { useNavigate } from "react-router-dom"
-import useGlobalReducer from "../hooks/useGlobalReducer"
-import { func } from "prop-types"
-
-
-export const ContactList = () => {
-
- const { store, dispatch } = useGlobalReducer();
-
- useEffect(() => {
- const getContacts = async () => {
- try {
- const response = await fletch('https://playground.4geeks.com/contact/agendas/Dani');
-
- if (!response.ok) {
- throw new Error("No se pudo cargar los datos.");
- }
-
- const data = await response.json();
-
- setContacts(data.contact)
-
- console.log(data.contacts);
-
- dispatch(
- {
- type: editontact,
- payload: {contact: data.contact}
- }
- )
- }
-
- catch (error) { console.error("No se descargaron los datos"); };
-
-
- return (
- <>
-
- {store.contacts.length === 0 ? (
- No Hay Tareas Pendientes
- ) : (
- store.contacts.map((contact) => (
-
- deleteTask(toDo.idCounter)}
- />
- ))
- )}
-
- >
- );
-
-
-
-
-
-
- useEffect(() => { getContacts() }, [])
- }
- };
diff --git a/src/pages/Contacts/AddContact.jsx b/src/pages/Contacts/AddContact.jsx
new file mode 100644
index 000000000..7afc05bc9
--- /dev/null
+++ b/src/pages/Contacts/AddContact.jsx
@@ -0,0 +1,14 @@
+import React from "react";
+import useGlobalReducer from "../../hooks/useGlobalReducer.jsx";
+
+ const AddContact = () => {
+
+ const {store, dispatch} =useGlobalReducer()
+ return (
+
+
, Add Contacts
+ );
+};
+
+export default AddContact;
+
\ No newline at end of file
diff --git a/src/pages/Contacts/ContactList.jsx b/src/pages/Contacts/ContactList.jsx
new file mode 100644
index 000000000..2ff0c6685
--- /dev/null
+++ b/src/pages/Contacts/ContactList.jsx
@@ -0,0 +1,53 @@
+import React, { useEffect } from "react";
+import useGlobalReducer from "../../hooks/useGlobalReducer.jsx";
+import CardContact from "../../components/CardContact.jsx"
+
+const ContactList = () => {
+
+ const { store, dispatch } = useGlobalReducer()
+
+ useEffect(() => { fetchContacts() }, []);
+
+ const fetchContacts = async () => {
+ try {
+ const response = await fetch('https://playground.4geeks.com/contact/agendas/Dani');
+ if (!response.ok) {
+ throw new Error(`HTTP error! Status: ${response.status}`);
+ }
+ const data = await response.json();
+ console.log(data);
+ dispatch({ type: 'setContacts', payload: data.contacts });
+
+ } catch (error) {
+ console.error("Hubo un problema con la solicitud:", error);
+ }
+ };
+
+ return (
+
+ <>
+
+
Contact List
+
+ {store.contacts.map((contact, index) => {
+ return (
+
+
+
+
+ )
+ })}
+
+
+ >
+ );
+};
+
+export default ContactList;
+
+
+
diff --git a/src/pages/Contacts/EditContact.jsx b/src/pages/Contacts/EditContact.jsx
new file mode 100644
index 000000000..512222fba
--- /dev/null
+++ b/src/pages/Contacts/EditContact.jsx
@@ -0,0 +1,14 @@
+import React from "react";
+import useGlobalReducer from "../../hooks/useGlobalReducer.jsx";
+
+const EditContact = () => {
+
+ const {store, dispatch} =useGlobalReducer()
+
+ return (
+
+
, Edit Contacts
+ );
+};
+
+export default EditContact;
\ No newline at end of file
diff --git a/src/pages/Contacts/ViewContacts.jsx b/src/pages/Contacts/ViewContacts.jsx
new file mode 100644
index 000000000..9a604b5b0
--- /dev/null
+++ b/src/pages/Contacts/ViewContacts.jsx
@@ -0,0 +1,13 @@
+import React, { useContext } from "react";
+import useGlobalReducer from "../../hooks/useGlobalReducer.jsx";
+
+const ViewContacts = () => {
+
+ const {store, dispatch} =useGlobalReducer()
+ return (
+
+
, View Contacts
+ );
+};
+
+export default ViewContacts;
\ No newline at end of file
diff --git a/src/pages/DeleteContact.jsx b/src/pages/DeleteContact.jsx
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/pages/EditContact.jsx b/src/pages/EditContact.jsx
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx
index 3e9f1aefa..5b62c53c4 100644
--- a/src/pages/Home.jsx
+++ b/src/pages/Home.jsx
@@ -1,7 +1,7 @@
import rigoImageUrl from "../assets/img/rigo-baby.jpg";
import useGlobalReducer from "../hooks/useGlobalReducer.jsx";
-export const Home = () => {
+const Home = () => {
const {store, dispatch} =useGlobalReducer()
@@ -13,4 +13,6 @@ export const Home = () => {
);
-};
\ No newline at end of file
+};
+
+export default Home;
\ No newline at end of file
diff --git a/src/pages/Layout.jsx b/src/pages/Layout.jsx
index 9bfa31325..ce9953a11 100644
--- a/src/pages/Layout.jsx
+++ b/src/pages/Layout.jsx
@@ -1,6 +1,6 @@
import { Outlet } from "react-router-dom/dist"
import ScrollToTop from "../components/ScrollToTop"
-import { Navbar } from "../components/Navbar"
+import Navbar from "../components/Navbar"
import { Footer } from "../components/Footer"
// Base component that maintains the navbar and footer throughout the page and the scroll to top functionality.
@@ -12,4 +12,6 @@ export const Layout = () => {
)
-}
\ No newline at end of file
+}
+
+export default Layout;
\ No newline at end of file
diff --git a/src/pages/Single.jsx b/src/pages/Single.jsx
deleted file mode 100644
index 7e68487da..000000000
--- a/src/pages/Single.jsx
+++ /dev/null
@@ -1,37 +0,0 @@
-// Import necessary hooks and components from react-router-dom and other libraries.
-import { Link, useParams } from "react-router-dom"; // To use link for navigation and useParams to get URL parameters
-import PropTypes from "prop-types"; // To define prop types for this component
-import rigoImageUrl from "../assets/img/rigo-baby.jpg" // Import an image asset
-import useGlobalReducer from "../hooks/useGlobalReducer"; // Import a custom hook for accessing the global state
-
-// Define and export the Single component which displays individual item details.
-export const Single = props => {
- // Access the global state using the custom hook.
- const { store } = useGlobalReducer()
-
- // Retrieve the 'theId' URL parameter using useParams hook.
- const { theId } = useParams()
- const singleTodo = store.todos.find(todo => todo.id === parseInt(theId));
-
- return (
-
- {/* Display the title of the todo element dynamically retrieved from the store using theId. */}
-
Todo: {singleTodo?.title}
- {/* A horizontal rule for visual separation. */}
-
- {/* A Link component acts as an anchor tag but is used for client-side routing to prevent page reloads. */}
-
-
- Back home
-
-
-
- );
-};
-
-// Use PropTypes to validate the props passed to this component, ensuring reliable behavior.
-Single.propTypes = {
- // Although 'match' prop is defined here, it is not used in the component.
- // Consider removing or using it as needed.
- match: PropTypes.object
-};
diff --git a/src/routes.jsx b/src/routes.jsx
index 23ef8e1f8..0fc7bf37c 100644
--- a/src/routes.jsx
+++ b/src/routes.jsx
@@ -1,31 +1,24 @@
-// Import necessary components and functions from react-router-dom.
-
-import {
- createBrowserRouter,
- createRoutesFromElements,
- Route,
-} from "react-router-dom";
+import { createBrowserRouter, createRoutesFromElements, Route, Navigate } from "react-router-dom";
import { Layout } from "./pages/Layout";
-import { Home } from "./pages/Home";
-import { Single } from "./pages/Single";
-import { Demo } from "./pages/Demo";
-import { ContactList } from "./pages/ContactList";
+import Home from "./pages/Home";
+import ContactList from "./pages/Contacts/ContactList"
+import ViewContacts from "./pages/Contacts/ViewContacts";
+import AddContact from "./pages/Contacts/AddContact";
+import EditContact from "./pages/Contacts/EditContact";
export const router = createBrowserRouter(
- createRoutesFromElements(
- // CreateRoutesFromElements function allows you to build route elements declaratively.
- // Create your routes here, if you want to keep the Navbar and Footer in all views, add your new routes inside the containing Route.
- // Root, on the contrary, create a sister Route, if you have doubts, try it!
- // Note: keep in mind that errorElement will be the default page when you don't get a route, customize that page to make your project more attractive.
- // Note: The child paths of the Layout element replace the Outlet component with the elements contained in the "element" attribute of these child paths.
+ createRoutesFromElements(
+ } errorElement={Not found! }>
- // Root Route: All navigation will start from here.
- } errorElement={Not found! } >
+
+ } />
+ } />
+ } />
+ } />
+ } />
- {/* Nested Routes: Defines sub-routes within the BaseHome component. */}
- } />
- } /> {/* Dynamic route for single items */}
- } />
- )
-);
\ No newline at end of file
+ )
+);
+
+export default router;
diff --git a/src/store.js b/src/store.js
index 0f3160b33..63360997d 100644
--- a/src/store.js
+++ b/src/store.js
@@ -1,3 +1,5 @@
+
+
export const initialStore = () => {
return {
@@ -8,16 +10,17 @@ export const initialStore = () => {
"email": "",
"address": "",
"id": 0
- }
- ]
- }
-}
-
+ },
+ ],
+ userRole:""
+ };
+};
-export default function storeReducer(store, action = {}) {
+export default function storeReducer(store, action) {
switch (action.type) {
- case "addContact":
+
+ case "setContacts":
return {
...store,
contacts: action.payload
@@ -36,8 +39,8 @@ export default function storeReducer(store, action = {}) {
contacts: store.contacts.filter(contact => contact.id !== action.payload)
};
+
-
default: return store;
}