├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.jsx
├── components
├── Carrito.jsx
├── CartWidget.jsx
├── Checkout.jsx
├── Contacto.jsx
├── Item.jsx
├── ItemCount.jsx
├── ItemDetail.jsx
├── ItemDetailContainer.jsx
├── ItemList.jsx
├── ItemListContainer.jsx
├── Navbar.jsx
└── Nosotros.jsx
├── context
└── CartContext.jsx
├── data
└── data.json
├── firebase
└── config.js
├── helpers
├── pedirDatos.js
└── toCapital.js
├── index.js
└── main.css
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mi-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.5",
7 | "@testing-library/react": "^13.4.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "firebase": "^9.22.2",
10 | "react": "^18.2.0",
11 | "react-dom": "^18.2.0",
12 | "react-hook-form": "^7.43.9",
13 | "react-router-dom": "^6.11.1",
14 | "react-scripts": "5.0.1",
15 | "react-uuid": "^2.0.0",
16 | "uuid": "^9.0.0",
17 | "web-vitals": "^2.1.4"
18 | },
19 | "scripts": {
20 | "start": "react-scripts start",
21 | "build": "react-scripts build",
22 | "test": "react-scripts test",
23 | "eject": "react-scripts eject"
24 | },
25 | "eslintConfig": {
26 | "extends": [
27 | "react-app",
28 | "react-app/jest"
29 | ]
30 | },
31 | "browserslist": {
32 | "production": [
33 | ">0.2%",
34 | "not dead",
35 | "not op_mini all"
36 | ],
37 | "development": [
38 | "last 1 chrome version",
39 | "last 1 firefox version",
40 | "last 1 safari version"
41 | ]
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/carpicoder/e-commerce-react/d2281d0e67255bbf642ab61d9143188fc6f9a1ca/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 | You need to enable JavaScript to run this app.
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/carpicoder/e-commerce-react/d2281d0e67255bbf642ab61d9143188fc6f9a1ca/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/carpicoder/e-commerce-react/d2281d0e67255bbf642ab61d9143188fc6f9a1ca/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.jsx:
--------------------------------------------------------------------------------
1 | import Contacto from "./components/Contacto";
2 | import ItemDetailContainer from "./components/ItemDetailContainer";
3 | import ItemListContainer from "./components/ItemListContainer";
4 | import Navbar from "./components/Navbar";
5 | import Nosotros from "./components/Nosotros";
6 | import "./main.css";
7 | import { BrowserRouter, Route, Routes } from "react-router-dom";
8 | import { CartProvider } from "./context/CartContext";
9 | import Carrito from "./components/Carrito";
10 | import Checkout from "./components/Checkout";
11 |
12 | function App() {
13 | return (
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | } />
22 | }/>
23 | } />
24 | } />
25 | }/>
26 | }/>
27 | }/>
28 | }/>
29 |
30 |
31 |
32 |
33 |
34 | );
35 | }
36 |
37 | export default App;
--------------------------------------------------------------------------------
/src/components/Carrito.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react'
2 | import { CartContext } from '../context/CartContext'
3 | import { Link } from 'react-router-dom';
4 |
5 | const Carrito = () => {
6 |
7 | const { carrito, precioTotal, vaciarCarrito } = useContext(CartContext);
8 |
9 | const handleVaciar = () => {
10 | vaciarCarrito();
11 | }
12 |
13 | return (
14 |
15 |
Carrito
16 |
17 | {
18 | carrito.map((prod) => (
19 |
20 |
21 |
{prod.titulo}
22 |
Precio unit: ${prod.precio}
23 |
Precio total: ${prod.precio * prod.cantidad}
24 |
Cant: {prod.cantidad}
25 |
26 |
27 | ))
28 | }
29 |
30 | {
31 | carrito.length > 0 ?
32 | <>
33 |
Precio total: ${precioTotal()}
34 |
Vaciar
35 |
Finalizar compra
36 | > :
37 |
El carrito está vacío :(
38 | }
39 |
40 |
41 | )
42 | }
43 |
44 | export default Carrito
--------------------------------------------------------------------------------
/src/components/CartWidget.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react'
2 | import { Link } from 'react-router-dom'
3 | import { CartContext } from '../context/CartContext';
4 |
5 | const CartWidget = () => {
6 |
7 | const { cantidadEnCarrito } = useContext(CartContext);
8 |
9 | return (
10 |
11 |
12 | Carrito
13 | {cantidadEnCarrito()}
14 |
15 |
16 | )
17 | }
18 |
19 | export default CartWidget
--------------------------------------------------------------------------------
/src/components/Checkout.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext, useState } from 'react'
2 | import { CartContext } from '../context/CartContext';
3 | import { useForm } from 'react-hook-form';
4 | import { collection, addDoc } from "firebase/firestore";
5 | import { db } from '../firebase/config';
6 |
7 | const Checkout = () => {
8 |
9 |
10 | const [pedidoId, setPedidoId] = useState("");
11 |
12 | const { carrito, precioTotal, vaciarCarrito } = useContext(CartContext);
13 |
14 | const { register, handleSubmit } = useForm();
15 |
16 | const comprar = (data) => {
17 | const pedido = {
18 | cliente: data,
19 | productos: carrito,
20 | total: precioTotal()
21 | }
22 | console.log(pedido);
23 |
24 | const pedidosRef = collection(db, "pedidos");
25 |
26 | addDoc(pedidosRef, pedido)
27 | .then((doc) => {
28 | setPedidoId(doc.id);
29 | vaciarCarrito();
30 | })
31 |
32 | }
33 |
34 | if (pedidoId) {
35 | return (
36 |
37 |
Muchas gracias por tu compra
38 |
Tu número de pedido es: {pedidoId}
39 |
40 | )
41 | }
42 |
43 | return (
44 |
45 |
Finalizar compra
46 |
55 |
56 | )
57 | }
58 |
59 | export default Checkout
--------------------------------------------------------------------------------
/src/components/Contacto.jsx:
--------------------------------------------------------------------------------
1 | import { useForm } from "react-hook-form";
2 |
3 | const Contacto = () => {
4 |
5 | const { register, handleSubmit } = useForm();
6 |
7 | const enviar = (data) => {
8 | console.log(data);
9 | }
10 |
11 | return (
12 |
13 |
14 |
Contacto
15 |
24 |
25 |
26 | )
27 | }
28 |
29 | export default Contacto
--------------------------------------------------------------------------------
/src/components/Item.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Link } from 'react-router-dom'
3 | import { toCapital } from '../helpers/toCapital'
4 |
5 | const Item = ( {producto} ) => {
6 | return (
7 |
8 |
9 |
10 |
{producto.titulo}
11 |
Precio: ${producto.precio}
12 |
Categoría: {toCapital(producto.categoria)}
13 |
Ver más
14 |
15 |
16 | )
17 | }
18 |
19 | export default Item
--------------------------------------------------------------------------------
/src/components/ItemCount.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | const ItemCount = ( {cantidad, handleRestar, handleSumar, handleAgregar} ) => {
4 |
5 | return (
6 |
7 |
8 |
9 |
-
10 |
{cantidad}
11 |
+
12 |
13 |
Agregar al carrito
14 |
15 | )
16 | }
17 |
18 | export default ItemCount
--------------------------------------------------------------------------------
/src/components/ItemDetail.jsx:
--------------------------------------------------------------------------------
1 | import { useContext, useState } from "react";
2 | import { toCapital } from "../helpers/toCapital"
3 | import ItemCount from "./ItemCount"
4 | import { CartContext } from "../context/CartContext";
5 |
6 |
7 | const ItemDetail = ( {item} ) => {
8 |
9 | const { carrito, agregarAlCarrito } = useContext(CartContext);
10 | console.log(carrito);
11 |
12 | const [cantidad, setCantidad] = useState(1);
13 |
14 | const handleRestar = () => {
15 | cantidad > 1 && setCantidad(cantidad - 1)
16 | }
17 |
18 | const handleSumar = () => {
19 | cantidad < item.stock && setCantidad(cantidad + 1)
20 | }
21 |
22 | return (
23 |
24 |
25 |
26 |
27 |
{item.titulo}
28 |
{item.descripcion}
29 |
Categoría: {toCapital(item.categoria)}
30 |
${item.precio}
31 |
{ agregarAlCarrito(item, cantidad) }}
36 | />
37 |
38 |
39 |
40 | )
41 | }
42 |
43 | export default ItemDetail
--------------------------------------------------------------------------------
/src/components/ItemDetailContainer.jsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react"
2 | import ItemDetail from "./ItemDetail";
3 | import { useParams } from "react-router-dom";
4 | import { doc, getDoc } from "firebase/firestore";
5 | import { db } from "../firebase/config";
6 |
7 |
8 | const ItemDetailContainer = () => {
9 |
10 | const [item, setItem] = useState(null);
11 | const id = useParams().id;
12 |
13 | useEffect(() => {
14 |
15 | const docRef = doc(db, "productos", id);
16 | getDoc(docRef)
17 | .then((resp) => {
18 | setItem(
19 | { ...resp.data(), id: resp.id }
20 | );
21 | })
22 |
23 | }, [id])
24 |
25 |
26 | return (
27 |
28 | {item && }
29 |
30 | )
31 | }
32 |
33 | export default ItemDetailContainer
--------------------------------------------------------------------------------
/src/components/ItemList.jsx:
--------------------------------------------------------------------------------
1 | import Item from "./Item";
2 | import { toCapital } from "../helpers/toCapital";
3 |
4 |
5 | const ItemList = ( {productos, titulo} ) => {
6 |
7 | return (
8 |
9 |
{toCapital(titulo)}
10 |
11 |
12 | { productos.map((prod) => ) }
13 |
14 |
15 | )
16 | }
17 |
18 | export default ItemList
--------------------------------------------------------------------------------
/src/components/ItemListContainer.jsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import ItemList from "./ItemList";
3 | import { useParams } from "react-router-dom";
4 | import { collection, getDocs, query, where } from "firebase/firestore";
5 | import { db } from "../firebase/config";
6 |
7 | const ItemListContainer = () => {
8 |
9 | const [productos, setProductos] = useState([]);
10 |
11 | const [titulo, setTitulo] = useState("Productos");
12 |
13 | const categoria = useParams().categoria;
14 |
15 | useEffect(() => {
16 |
17 | const productosRef = collection(db, "productos");
18 | const q = categoria ? query(productosRef, where("categoria", "==", categoria)) : productosRef;
19 |
20 | getDocs(q)
21 | .then((resp) => {
22 |
23 | setProductos(
24 | resp.docs.map((doc) => {
25 | return { ...doc.data(), id: doc.id }
26 | })
27 | )
28 | })
29 |
30 | }, [categoria])
31 |
32 |
33 | return (
34 |
35 |
36 |
37 | )
38 | }
39 |
40 | export default ItemListContainer
--------------------------------------------------------------------------------
/src/components/Navbar.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Link } from 'react-router-dom'
3 | import CartWidget from './CartWidget'
4 |
5 | const Navbar = () => {
6 | return (
7 |
8 | Carpishop
9 |
10 | Inicio
11 | Productos
12 | Medias
13 | Pantalones
14 | Remeras
15 | Buzos
16 | Nosotros
17 | Contacto
18 |
19 |
20 |
21 | )
22 | }
23 |
24 | export default Navbar
--------------------------------------------------------------------------------
/src/components/Nosotros.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react'
2 |
3 | const Nosotros = () => {
4 |
5 | useEffect(() => {
6 |
7 | const clickear = () => {
8 | console.log("Click");
9 | }
10 |
11 | window.addEventListener("click", clickear)
12 |
13 | return () => {
14 | window.removeEventListener("click", clickear)
15 | }
16 |
17 | }, [])
18 |
19 | return (
20 |
21 |
Nosotros
22 |
Este es el componente "Nosotros"
23 |
24 | )
25 | }
26 |
27 | export default Nosotros
--------------------------------------------------------------------------------
/src/context/CartContext.jsx:
--------------------------------------------------------------------------------
1 | import { createContext, useEffect, useState } from "react";
2 |
3 |
4 | export const CartContext = createContext();
5 |
6 | const carritoInicial = JSON.parse(localStorage.getItem("carrito")) || [];
7 |
8 | export const CartProvider = ({children}) => {
9 |
10 | const [carrito, setCarrito] = useState(carritoInicial);
11 |
12 | const agregarAlCarrito = (item, cantidad) => {
13 | const itemAgregado = { ...item, cantidad };
14 |
15 | const nuevoCarrito = [...carrito];
16 | const estaEnElCarrito = nuevoCarrito.find((producto) => producto.id === itemAgregado.id);
17 |
18 | if (estaEnElCarrito) {
19 | estaEnElCarrito.cantidad += cantidad;
20 | } else {
21 | nuevoCarrito.push(itemAgregado);
22 | }
23 | setCarrito(nuevoCarrito);
24 | }
25 |
26 | const cantidadEnCarrito = () => {
27 | return carrito.reduce((acc, prod) => acc + prod.cantidad, 0);
28 | }
29 |
30 | const precioTotal = () => {
31 | return carrito.reduce((acc, prod) => acc + prod.precio * prod.cantidad, 0);
32 | }
33 |
34 | const vaciarCarrito = () => {
35 | setCarrito([]);
36 | }
37 |
38 | useEffect(() => {
39 | localStorage.setItem("carrito", JSON.stringify(carrito));
40 | }, [carrito])
41 |
42 |
43 | return (
44 |
51 | {children}
52 |
53 | )
54 |
55 |
56 |
57 | }
--------------------------------------------------------------------------------
/src/data/data.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "id": 1,
4 | "titulo": "Chocolate - Milk",
5 | "descripcion": "Aenean auctor gravida sem.",
6 | "categoria": "medias",
7 | "imagen": "http://dummyimage.com/200x100.png/cc0000/ffffff",
8 | "precio": 1500,
9 | "stock": 10
10 | },
11 | {
12 | "id": 2,
13 | "titulo": "Muffin - Mix - Strawberry Rhubarb",
14 | "descripcion": "Nulla ut erat id mauris vulputate elementum.",
15 | "categoria": "medias",
16 | "imagen": "http://dummyimage.com/200x100.png/cc0000/ffffff",
17 | "precio": 1500,
18 | "stock": 10
19 | },
20 | {
21 | "id": 3,
22 | "titulo": "Appetizer - Tarragon Chicken",
23 | "descripcion": "Aenean auctor gravida sem.",
24 | "categoria": "pantalones",
25 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
26 | "precio": 1500,
27 | "stock": 10
28 | },
29 | {
30 | "id": 4,
31 | "titulo": "Jam - Strawberry, 20 Ml Jar",
32 | "descripcion": "Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo.",
33 | "categoria": "remeras",
34 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
35 | "precio": 1500,
36 | "stock": 10
37 | },
38 | {
39 | "id": 5,
40 | "titulo": "Glass - Juice Clear 5oz 55005",
41 | "descripcion": "Sed accumsan felis.",
42 | "categoria": "buzos",
43 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
44 | "precio": 1500,
45 | "stock": 10
46 | },
47 | {
48 | "id": 6,
49 | "titulo": "Cheese - Brie, Cups 125g",
50 | "descripcion": "In hac habitasse platea dictumst.",
51 | "categoria": "remeras",
52 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
53 | "precio": 1500,
54 | "stock": 10
55 | },
56 | {
57 | "id": 7,
58 | "titulo": "Oneshot Automatic Soap System",
59 | "descripcion": "Morbi vel lectus in quam fringilla rhoncus.",
60 | "categoria": "buzos",
61 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
62 | "precio": 1500,
63 | "stock": 10
64 | },
65 | {
66 | "id": 8,
67 | "titulo": "Myers Planters Punch",
68 | "descripcion": "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis faucibus accumsan odio.",
69 | "categoria": "pantalones",
70 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
71 | "precio": 1500,
72 | "stock": 10
73 | },
74 | {
75 | "id": 9,
76 | "titulo": "Nut - Almond, Blanched, Ground",
77 | "descripcion": "Morbi vestibulum, velit id pretium iaculis, diam erat fermentum justo, nec condimentum neque sapien placerat ante.",
78 | "categoria": "pantalones",
79 | "imagen": "http://dummyimage.com/200x100.png/ff4444/ffffff",
80 | "precio": 1500,
81 | "stock": 10
82 | },
83 | {
84 | "id": 10,
85 | "titulo": "Pasta - Fett Alfredo, Single Serve",
86 | "descripcion": "Quisque arcu libero, rutrum ac, lobortis vel, dapibus at, diam.",
87 | "categoria": "remeras",
88 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
89 | "precio": 1500,
90 | "stock": 10
91 | },
92 | {
93 | "id": 11,
94 | "titulo": "Bread - Assorted Rolls",
95 | "descripcion": "Mauris sit amet eros.",
96 | "categoria": "remeras",
97 | "imagen": "http://dummyimage.com/200x100.png/ff4444/ffffff",
98 | "precio": 1500,
99 | "stock": 10
100 | },
101 | {
102 | "id": 12,
103 | "titulo": "Table Cloth 62x120 White",
104 | "descripcion": "Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl.",
105 | "categoria": "medias",
106 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
107 | "precio": 1500,
108 | "stock": 10
109 | },
110 | {
111 | "id": 13,
112 | "titulo": "Tuna - Sushi Grade",
113 | "descripcion": "Aenean sit amet justo.",
114 | "categoria": "medias",
115 | "imagen": "http://dummyimage.com/200x100.png/cc0000/ffffff",
116 | "precio": 1500,
117 | "stock": 10
118 | },
119 | {
120 | "id": 14,
121 | "titulo": "Wine - Barbera Alba Doc 2001",
122 | "descripcion": "In blandit ultrices enim.",
123 | "categoria": "buzos",
124 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
125 | "precio": 1500,
126 | "stock": 10
127 | },
128 | {
129 | "id": 15,
130 | "titulo": "Artichoke - Hearts, Canned",
131 | "descripcion": "Nullam varius.",
132 | "categoria": "remeras",
133 | "imagen": "http://dummyimage.com/200x100.png/ff4444/ffffff",
134 | "precio": 1500,
135 | "stock": 10
136 | },
137 | {
138 | "id": 16,
139 | "titulo": "Ham - Smoked, Bone - In",
140 | "descripcion": "Cras non velit nec nisi vulputate nonummy.",
141 | "categoria": "medias",
142 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
143 | "precio": 1500,
144 | "stock": 10
145 | },
146 | {
147 | "id": 17,
148 | "titulo": "Truffle Cups - Red",
149 | "descripcion": "Nulla tempus.",
150 | "categoria": "remeras",
151 | "imagen": "http://dummyimage.com/200x100.png/5fa2dd/ffffff",
152 | "precio": 1500,
153 | "stock": 10
154 | },
155 | {
156 | "id": 18,
157 | "titulo": "Ham - Smoked, Bone - In",
158 | "descripcion": "Etiam justo.",
159 | "categoria": "pantalones",
160 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
161 | "precio": 1500,
162 | "stock": 10
163 | },
164 | {
165 | "id": 19,
166 | "titulo": "Sugar - Brown",
167 | "descripcion": "Morbi non lectus.",
168 | "categoria": "buzos",
169 | "imagen": "http://dummyimage.com/200x100.png/cc0000/ffffff",
170 | "precio": 1500,
171 | "stock": 10
172 | },
173 | {
174 | "id": 20,
175 | "titulo": "Bread - Hot Dog Buns",
176 | "descripcion": "Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc.",
177 | "categoria": "buzos",
178 | "imagen": "http://dummyimage.com/200x100.png/dddddd/000000",
179 | "precio": 1500,
180 | "stock": 10
181 | }
182 | ]
--------------------------------------------------------------------------------
/src/firebase/config.js:
--------------------------------------------------------------------------------
1 | // Import the functions you need from the SDKs you need
2 | import { initializeApp } from "firebase/app";
3 | import { getFirestore } from "firebase/firestore";
4 |
5 | // Your web app's Firebase configuration
6 | const firebaseConfig = {
7 | apiKey: "AIzaSyDnrXcfm2DFzzbMwVd2ty4oydZ9qSnGiB8",
8 | authDomain: "carpishop-eb6ea.firebaseapp.com",
9 | projectId: "carpishop-eb6ea",
10 | storageBucket: "carpishop-eb6ea.appspot.com",
11 | messagingSenderId: "380430211990",
12 | appId: "1:380430211990:web:ad8ce8cba96769b84bdbb7"
13 | };
14 |
15 | // Initialize Firebase
16 | const app = initializeApp(firebaseConfig);
17 | export const db = getFirestore(app);
--------------------------------------------------------------------------------
/src/helpers/pedirDatos.js:
--------------------------------------------------------------------------------
1 | import data from "../data/data.json";
2 |
3 | export const pedirDatos = () => {
4 | return new Promise((resolve, reject) => {
5 | setTimeout( () => {
6 | resolve(data);
7 | }, 500)
8 | })
9 | }
10 |
11 | export const pedirItemPorId = (id) => {
12 | return new Promise((resolve, reject) => {
13 |
14 | const item = data.find((el) => el.id === id);
15 |
16 | if (item) {
17 | resolve(item);
18 | } else {
19 | reject({
20 | error: "No se encontró el producto"
21 | })
22 | }
23 |
24 | })
25 | }
--------------------------------------------------------------------------------
/src/helpers/toCapital.js:
--------------------------------------------------------------------------------
1 | export function toCapital(str) {
2 | return str.charAt(0).toUpperCase() + str.slice(1);
3 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import App from './App';
4 |
5 | const root = ReactDOM.createRoot(document.getElementById('root'));
6 | root.render(
7 | //
8 |
9 | //
10 | );
--------------------------------------------------------------------------------
/src/main.css:
--------------------------------------------------------------------------------
1 | * {
2 | margin: 0;
3 | padding: 0;
4 | box-sizing: border-box;
5 | font-family: sans-serif;
6 | }
7 |
8 | :root {
9 | --clr-main: #c56cee;
10 | --clr-main-light: #efdaf9;
11 | }
12 |
13 | .container {
14 | max-width: 1140px;
15 | padding-inline: 1.5rem;
16 | margin: 0 auto;
17 | }
18 |
19 | .main-title {
20 | margin-top: 2rem;
21 | }
22 |
23 | .navbar {
24 | padding: 2rem;
25 | display: flex;
26 | justify-content: space-between;
27 | align-items: center;
28 | background-color: var(--clr-main);
29 | border-bottom: 3px solid black;
30 | }
31 |
32 | .logo {
33 | text-decoration: none;
34 | color: black;
35 | }
36 |
37 | .menu {
38 | list-style-type: none;
39 | display: flex;
40 | align-items: center;
41 | gap: 1rem;
42 | }
43 |
44 | .menu-link {
45 | text-decoration: none;
46 | color: black;
47 | font-size: 1.2rem;
48 | }
49 |
50 | .menu-link:hover {
51 | text-decoration: underline;
52 | }
53 |
54 | .productos {
55 | display: grid;
56 | grid-template-columns: repeat(3, 1fr);
57 | gap: 2rem;
58 | padding-block: 2rem;
59 | }
60 |
61 | .producto {
62 | display: flex;
63 | flex-direction: column;
64 | border-radius: 1rem;
65 | overflow: hidden;
66 | }
67 |
68 | .producto > div {
69 | padding: 1rem;
70 | background-color: var(--clr-main-light);
71 | display: flex;
72 | flex-direction: column;
73 | gap: .5rem;
74 | }
75 |
76 | .producto > img {
77 | width: 100%;
78 | aspect-ratio: 2/1;
79 | object-fit: cover;
80 | }
81 |
82 | .producto .ver-mas {
83 | text-decoration: none;
84 | background-color: var(--clr-main);
85 | color: white;
86 | padding: .5rem;
87 | width: max-content;
88 | border-radius: .5rem;
89 | transition: .2s;
90 | }
91 |
92 | .producto .ver-mas:hover {
93 | background-color: black;
94 | color: white;
95 | }
96 |
97 | .producto-detalle {
98 | padding-block: 2rem;
99 | display: grid;
100 | grid-template-columns: 1fr 2fr;
101 | gap: 2rem;
102 | }
103 |
104 | .producto-detalle img {
105 | width: 100%;
106 | }
107 |
108 | .producto-detalle-info h3 {
109 | font-size: 2rem;
110 | }
111 |
112 | .categoria {
113 | font-size: .8rem;
114 | color: #424242;
115 | margin-top: 1rem;
116 | }
117 |
118 | .precio {
119 | font-size: 2rem;
120 | margin-top: 2rem;
121 | font-weight: 600;
122 | }
123 |
124 | .item-count {
125 | display: flex;
126 | align-items: center;
127 | gap: 1rem;
128 | margin-top: 1rem;
129 | }
130 |
131 | .item-count button, .agregar-al-carrito, .enviar {
132 | background-color: var(--clr-main);
133 | border: 0;
134 | width: 2rem;
135 | height: 2rem;
136 | color: white;
137 | border-radius: .5rem;
138 | cursor: pointer;
139 | font-size: 1rem;
140 | display: flex;
141 | align-items: center;
142 | justify-content: center;
143 | text-align: center;
144 | line-height: 1;
145 | border: 2px solid var(--clr-main);
146 | transition: .2s;
147 | }
148 |
149 | .item-count button:hover, .agregar-al-carrito:hover, .enviar:hover {
150 | background-color: white;
151 | color: black;
152 | }
153 |
154 | .agregar-al-carrito, .enviar {
155 | width: auto;
156 | height: auto;
157 | margin-top: 1rem;
158 | padding: 1rem;
159 | }
160 |
161 | .formulario {
162 | display: flex;
163 | flex-direction: column;
164 | gap: .5rem;
165 | align-items: flex-start;
166 | }
167 |
168 | .formulario input {
169 | padding: .5rem;
170 | width: 18rem;
171 | border-radius: .5rem;
172 | border: 2px solid black;
173 | }
174 |
175 | .formulario input:focus {
176 | outline: 0;
177 | border: 2px solid var(--clr-main);
178 | outline: 2px solid var(--clr-main);
179 | }
--------------------------------------------------------------------------------