Skip to content

Commit

Permalink
Agregando Boton de eliminar Gasto
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaga committed Apr 1, 2023
1 parent 8e1f527 commit 88e40b2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const App = () => {




return (
<div className="container">
<header >
Expand All @@ -59,8 +58,8 @@ export const App = () => {
<Formulario setcrearGasto={setcrearGasto} setGastoApp={setGastoApp} />
</div>
<div className="col-md-6">
<Listado gastos={gastos} />
<ControlPresupuesto total={total} presupuesto={presupuesto} />
<Listado total={total} setTotal={setTotal} gastos={gastos} setGastos={setGastos} />
<ControlPresupuesto total={total} presupuesto={presupuesto} />
</div>
</div>
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/ControlPresupuesto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { revisarPresupuesto } from "../helpers"
export const ControlPresupuesto = ({ total, presupuesto }: any) => {
return (
<>

<div className="alert alert-info">
Presupuesto: $ {presupuesto}
</div>

<div className={`alert ${revisarPresupuesto(presupuesto, total)}`}>
Restante : $ {total}
</div>

</>
)
}
38 changes: 21 additions & 17 deletions src/components/GastoIndividual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ import { Gasto } from "../interfaces/Gasto.interface"


interface Props {
gasto: Gasto
gasto: Gasto;
eliminarGasto: React.Dispatch<React.SetStateAction<any>>;
setTotal: React.Dispatch<React.SetStateAction<number>>;
total: number;

}


export const GastoIndividual = ({ gasto }: Props) => {
export const GastoIndividual = ({ gasto, eliminarGasto, setTotal, total }: Props) => {

return (
<li className="list-group ">
<div className="d-flex justify-content-between m-2 ">
<p className="p-1 m-2 text-capitalize">{gasto.nombre}</p>
<span className=" p-2 m-2 rounded-3 bg-dark text-light"><i className="bi bi-currency-dollar"></i> {gasto.cantidad}</span>
<li className="list-group">
<div className="d-flex justify-content-between align-items-center m-2">
<p className="p-1 m-0 text-capitalize">{gasto.nombre}</p>
<div className="d-flex align-items-center">
<span className=" p-2 m-2 rounded-3 bg-dark text-light"><i className="bi bi-currency-dollar"></i> {gasto.cantidad}</span>
<button onClick={()=> {
eliminarGasto(gasto.id);
setTotal(total + parseInt(gasto.cantidad.toString()));
}}

className="btn btn-danger">X</button>
</div>
</div>
</li>
)
}

/*
<li className="list-group">
<div className="d-flex justify-content-between align-items-center m-2">
<p className="p-1 m-0 text-capitalize">{gasto.nombre}</p>
<div className="d-flex align-items-center">
<span className=" p-2 m-2 rounded-3 bg-dark text-light"><i className="bi bi-currency-dollar"></i> {gasto.cantidad}</span>
<button className="btn btn-danger">X</button>
</div>
</div>
</li>
*/


14 changes: 12 additions & 2 deletions src/components/Listado.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ import { GastoIndividual } from "./GastoIndividual";

interface Props {
gastos: Gasto[];
setGastos : React.Dispatch<React.SetStateAction<Gasto[]>>;
setTotal: React.Dispatch<React.SetStateAction<number>>;
total: number;
}

export const Listado = ({ gastos }: Props) => {
export const Listado = ({ gastos, setGastos, setTotal, total}: Props) => {


const eliminarGasto = (gastoId: string) => {
const nuevosGastos = gastos.filter((gasto) => gasto.id !== gastoId);
setGastos(nuevosGastos);
}

return (
<div>

<h2 className="text-center ">Gastos Realizados <i className="bi bi-cash"></i></h2>
{gastos.map((gasto) => (
<GastoIndividual key={gasto.id} gasto={gasto} />
<GastoIndividual total={total} setTotal={setTotal} eliminarGasto = {eliminarGasto} key={gasto.id} gasto={gasto} />
))}

</div>
Expand Down

0 comments on commit 88e40b2

Please sign in to comment.