Skip to content
This repository was archived by the owner on Jul 11, 2026. It is now read-only.

Mara y Fer / PR para Code Review :-)#17

Open
keupa wants to merge 44 commits into
Laboratoria:masterfrom
keupa:master
Open

Mara y Fer / PR para Code Review :-)#17
keupa wants to merge 44 commits into
Laboratoria:masterfrom
keupa:master

Conversation

@keupa

@keupa keupa commented Aug 12, 2020

Copy link
Copy Markdown

Nos encantaría tener feedback sobre como modularizar un poco mas los componentes y en qué podemos mejorar, gracias :-)

Mara Mulato and others added 30 commits June 17, 2020 13:23
* trying navbar

* Nabvar with burger menu, doubt about css

* changing burger-menu css

Co-authored-by: Mara Mulato <maramulato@MacBook-Mara.local>
* trying navbar

* Nabvar with burger menu, doubt about css

* changing burger-menu css

* new order pages, before pull commit

* React-Router. Render conflict in progress

Co-authored-by: Mara Mulato <maramulato@MacBook-Mara.local>
* trying navbar

* Nabvar with burger menu, doubt about css

* changing burger-menu css

* new order pages, before pull commit

* React-Router. Render conflict in progress

* minor css changes on navbar and menu, react router ok

* starting login, minor css changes and corrections

Co-authored-by: Mara Mulato <maramulato@MacBook-Mara.local>
Co-authored-by: Fernanda de la Peña ☆ <56372578+keupa@users.noreply.github.com>
Comment on lines +8 to +9
const Forms = ({ history }) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Forms = ({ history }) => {
import { useHistory } from 'react-router-dom';
const Forms = () => {
const history = useHistory();

} catch (err) {
alert(err);
}
}, [history]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por qué history es una dependencia de useCallback?, pueden elaborar un poco?

}

return (
<>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parece que <> no sería de ayuda acá. Pienso que pueden removerlo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gracias, me di cuenta que fuimos dejando varios <> innecesarios, los vamos a remover :-)

return <Redirect to='/login' />
}

const signOut = () => { auth.signOut() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const signOut = () => { auth.signOut() }
const signOut = () => auth.signOut()

const signOut = () => { auth.signOut() }

return(
<>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parece que <> no sería de ayuda acá. Pienso que pueden removerlo.

Comment on lines +19 to +24
<img
className="logout"
onClick={signOut}
src={logoutIcon}
alt="logout icon">
</img>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<img
className="logout"
onClick={signOut}
src={logoutIcon}
alt="logout icon">
</img>
<img
className="logout"
onClick={signOut}
src={logoutIcon}
alt="logout icon" />

Comment on lines +6 to +9
return( breakfastData.map(elem =>
<MenuElement data={elem} key={elem.id}/>
)
)

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return( breakfastData.map(elem =>
<MenuElement data={elem} key={elem.id}/>
)
)
return breakfastData.map(elem => <MenuElement data={elem} key={elem.id} />)

Comment on lines +4 to +6
function MenuElement (props) {
const {url, item, price, tag} = props.data
const addProduct = props.addProduct

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function MenuElement (props) {
const {url, item, price, tag} = props.data
const addProduct = props.addProduct
function MenuElement ({ data: { url, item, price, tag }, addProduct}) {

+
</button>
</div>
<h4>${price}.00</h4>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que es una mejor idea usar Intl.NumberFormat para manejo de monedas

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gracias, no sabía que eso existía, oops

Comment on lines +8 to +12
onChange={ e => {
const table = e.target.value;
setTable(table)
}
}

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onChange={ e => {
const table = e.target.value;
setTable(table)
}
}
onChange={e => setTable(e.target.value)}

Comment on lines +11 to +15
style={
{ backgroundColor: tab === 'breakfast' ? '#FFF' : '#DED2FF',
fontWeight: tab === 'breakfast' ? 'bold' : 'normal',
fontSize: tab === 'breakfast' ? '26px' : '25px'
}

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sería más legible realizarlo mediante classname

Ejemplo

Mis clases css

.toogle {
  // ... some styles
  background-color: #DED2FF;
  font-weight: normal;
  font-size: 25px;
}

.toggle--active {
  background-color: #FFF;
  font-weight: bold;
  font-size: 26px;
}

Y en mi component

<button className={`toggle ${tab === 'breakfast' ? 'toggle--active': ''}`} onClick={() => setTab('breakfast')}>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo intentamos hacer así, pero cuando dabamos click en otro lado de la pantalla (por ejemplo en los elementos para agregarlos al menú), el botón dejaba de estar activo y la clase cambiaba a la primera :(

Comment on lines +22 to +25
style={{ backgroundColor: tab === 'restOttd' ? '#FFF' : '#DED2FF',
fontWeight: tab === 'restOttd' ? 'bold' : 'normal',
fontSize: tab === 'restOttd' ? '26px' : '25px'
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La misma idea que arriba ☝️

Comment on lines +103 to +109
toast.warn('Asigna la mesa y productos a la orden 🍔🍟', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Estas propiedades pueden ser declaradas en el top y reutilizadas para todos las notificaciones toast.

Suggested change
toast.warn('Asigna la mesa y productos a la orden 🍔🍟', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
toast.warn('Asigna la mesa y productos a la orden 🍔🍟', toastProps);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okis, el objeto con todas esas propiedades lo cambiamos a una carpeta que se llama utils, y lo mandamos a llamar en donde se necesita, gracias :- )

Comment on lines +86 to +122
if(order.items.length >0 && order.table <= 0){
toast.warn('Por favor asigna la mesa', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else if(order.items.length === 0 && order.table >= 1){
toast.warn('Agrega al menos un producto a la orden 🍔', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else if (order.items.length === 0 && order.table <= 0){
toast.warn('Asigna la mesa y productos a la orden 🍔🍟', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else{
await db
.collection('orders')
.add(order)
setOrder({...initialValues})
toast.success('Pedido enviado a cocina! ✨', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(order.items.length >0 && order.table <= 0){
toast.warn('Por favor asigna la mesa', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else if(order.items.length === 0 && order.table >= 1){
toast.warn('Agrega al menos un producto a la orden 🍔', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else if (order.items.length === 0 && order.table <= 0){
toast.warn('Asigna la mesa y productos a la orden 🍔🍟', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}else{
await db
.collection('orders')
.add(order)
setOrder({...initialValues})
toast.success('Pedido enviado a cocina! ✨', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
transition: Slide
});
}
if (order.items.length === 0)
return toast.warn('Agrega al menos un producto a la orden 🍔',toastProps)
if(order.table <= 0)
return toast.warn('Por favor asigna la mesa', toastProps);
await db.collection('orders').add(order)
setOrder({...initialValues})
toast.success('Pedido enviado a cocina! ✨', toastProps);

Comment on lines +126 to +147
const restOtdComponents = restOfTheDayData.map(elem =>
<MenuElement addProduct={addProduct} data={elem} key={elem.id} />
)

// prints the breakfast components
const breakfastComponents = breakfastData.map(elem =>
<MenuElement addProduct={addProduct} data={elem} key={elem.id}/>
)

return(
<div className="menu-parent">
<div className="menu-container" >
<ToggleMenu
className="toggle-btn"
setTab={setTab}
tab={tab}
/>

{tab === 'breakfast' ? <div className="items-container">{breakfastComponents}</div> :
<div className="items-container">{restOtdComponents}</div>
}
</div>

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acá esamos creando por adelantado ambas colecciones de components <MenuElement ...> tanto para restOtdComponents como para breakfastComponents, sola una colección debería ser creada dependiendo del tab seleccionado por lo cual esta sugerencia que les dejo es más conveniente y con mejor performance.

Suggested change
const restOtdComponents = restOfTheDayData.map(elem =>
<MenuElement addProduct={addProduct} data={elem} key={elem.id} />
)
// prints the breakfast components
const breakfastComponents = breakfastData.map(elem =>
<MenuElement addProduct={addProduct} data={elem} key={elem.id}/>
)
return(
<div className="menu-parent">
<div className="menu-container" >
<ToggleMenu
className="toggle-btn"
setTab={setTab}
tab={tab}
/>
{tab === 'breakfast' ? <div className="items-container">{breakfastComponents}</div> :
<div className="items-container">{restOtdComponents}</div>
}
</div>
return (
<div className="menu-parent">
<div className="menu-container">
<ToggleMenu className="toggle-btn" setTab={setTab} tab={tab} />
<div className="items-container">
{(tab === 'breakfast' ? breakfastData : restOfTheDayData).map(elem =>
<MenuElement addProduct={addProduct} data={elem} key={elem.id}/>
)}
</div>
</div>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:0, gracias, no sabía que se estaba creando doble. Lo cambiamos y en próximos proyectos lo tendremos en cuenta :))

addQuantity={addQuantity}
/>
) )}
<p className="total">Total: ${addTotal}.00</p>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es una mejor idea usar Intl.NumberFormat

@@ -0,0 +1,168 @@
import React, { useState, useEffect } from "react";

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El nombre del archivo creo que no relación con el nombre del componente Meal

src/components/MenuSelector/prueba.js ??

Comment on lines +103 to +146
onChange={(total) => {
let newProduct;
let add;
let totalPay;
if (product.find((p) => p.productId === item.uid)) {
newProduct = product.map((p) => {
if (p.productId !== item.uid) {
return p;
}
return {
...p,
quant: total,
payment: total * item.price,
};
});
} else {
newProduct = [
...product,
{
productId: item.uid,
produItem: item.item,
unitaryPrice: item.price,
quant: total,
payment: total * item.price,
},
];
}
setProduct(newProduct);
add = newProduct.reduce(
(sum, value) => sum + value.quant,
0
);
setTotalQuantity(add);
{
}
totalPay = newProduct.reduce(
(sum, value) => sum + value.payment,
0
);
setPayment(totalPay);
{
// console.log(totalPay);
}
}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que sería una mejor idea separar la lógica de la app de la lógica de presentación (components), la idea sería como llevar esta lógica a una función fuera.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siempre he tenido problema con la modularización y eso. No sé si tengas algún recurso que me sirva para aprender a separar las funciones de los componentes, casi siempre lo pongo todo en el mismo archivo y se vuelve super confuso

import { Link } from 'react-router-dom';
import './BMenu.css';

function BMenu(props) {

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No es necesario declarar este param props porque no es usado en el componente.

Suggested change
function BMenu(props) {
function BMenu() {

Comment on lines +43 to +53
toast.success('Pedidos actualizados', {
className: "rounder-edges",
position: "top-center",
autoClose: 4000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
transition: Slide
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colocar estas propiedades de los toast en el top sería mejor para evitar declararlos una y otra vez.

Comment on lines +102 to +108
// breakpoints for responsive CSS Masonry
const breakpointColumnsObj = {
default: 3,
1100: 3,
700: 2,
500: 1
};

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colocar esta objeto con propiedades constantes en el top es una mejor idea para evitar recrear el objeto siempre que el componente haga un re-render.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entendido!

<div className="no-orders-message"> Aún no hay pedidos para entregar :-) </div>
</div>
)
} else{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No es necesario este bloque } else{ puesto que estamos haciendo un return dentro del bloque if más arriba.

Sería algo como

if (ready.length <=0) {
        return (
            <div className="no-orders-message-container">
                <div className="no-orders-message"> Aún no hay pedidos para entregar :-) </div> 
            </div>
        )
}

return(
        <div className='container'>
            <Masonry
                breakpointCols={breakpointColumnsObj}
                className="my-masonry-grid"
                columnClassName="my-masonry-grid_column">
                    {readyOrders}
            </Masonry>
        </div>
    )

Comment thread src/data/breakfastData.js
@@ -0,0 +1,38 @@
import americanCoffee from '../img/american-coffee.webp'

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pienso que esta data debería venir del servidor, podriamos tener una colección products donde guardamos todos los productos disponibles, sugiero esto porque de esa forma el administrador del restaurante o negocio puede mantener (add/update/delete) productos de forma dinámica y conveniente.

Los contras de tener la data de forma estática sería que para realizar un cambio deberiamos hacerlo en el código y luego desplegar la app nuevamente. Esto no resulta conveniente para el negocio.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

síp, pensamos mas adelante añadir una sección en donde se puedan subir productos nuevos a la base de datos. Así que esto sería lo mas conveniente :D

Comment thread src/firebase.js
import 'firebase/firestore'
import 'firebase/auth'

var firebaseConfig = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mantengamos consistencia y usemos const o var. Creo que const aquí ajusta mejor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vale, esque así venía en la documentación de firebase y pues así se quedó.

Comment thread src/firebase.js
import 'firebase/auth'

var firebaseConfig = {
apiKey: "AIzaSyBLfsFNhBD1kNio0wyF0i1eesnf0MV-FE8",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No es una buena idea exponer keys en el código, creo que es una mejor idea usar variables de entorno (envars).

Ref: https://create-react-app.dev/docs/adding-custom-environment-variables/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gracias! hay un pequeño detallito con esta parte y firebase, todas las keys que pongo en el .env las lee sin problema, excepto la de projectId, si no la pongo directamente en el file, la consola me dice que projectId tiene que ser un string y no jala.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sé que es lo que pasa en esa porque con todas las demas keys sirve.

Comment thread src/firebase.js
databaseURL: "https://burgerqueeeeeeen.firebaseio.com",
projectId: "burgerqueeeeeeen",
storageBucket: "burgerqueeeeeeen.appspot.com",
messagingSenderId: "650761219478",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que no se esta haciendo uso de Firebase Notifications, por lo cual no es necesario este key messagingSenderId

Comment thread src/firebase.js
authDomain: "burgerqueeeeeeen.firebaseapp.com",
databaseURL: "https://burgerqueeeeeeen.firebaseio.com",
projectId: "burgerqueeeeeeen",
storageBucket: "burgerqueeeeeeen.appspot.com",

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estamos haciendo uso de Firebase Storage?, en caso de que no creo que no sería necesario este key storageBucket

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La vamos a usar después para poder agregar los productos :)

Comment thread src/pages/Login.js
@@ -0,0 +1,13 @@

@raulingg raulingg Aug 13, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parece que este componente no tiene más hijos que <Forms>, repensaría si realmente es necesario tener <Forms> como un componente, tal vez el contenido de este debería estar directamente en Login

@raulingg
raulingg self-requested a review August 13, 2020 21:21

@raulingg raulingg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buen trabajo @keupa y @maranyil 💯 !!

He dejado algunos comentario que estoy seguro les serán de mucha ayuda para seguir refinando su proyecto.

Les recomiendo que ignoren usando git el folder build.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants