Skip to content

Commit

Permalink
Use a domain term (User) to name the entity
Browse files Browse the repository at this point in the history
  • Loading branch information
bespoyasov committed Jan 21, 2022
1 parent 72661ed commit b84ba84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";

import { useCart } from "./cart";
import { useStore } from "./user";
import { useUserStore } from "./user";

function UserInfo({ user }) {
return (
Expand Down Expand Up @@ -54,7 +54,7 @@ function App() {
let _userId, products;
const [status, setStatus] = useState("idle");
const [error, setError] = useState(null);
const { persona } = useStore();
const { user } = useUserStore();
const { cart } = useCart();

products = cart.products;
Expand All @@ -72,13 +72,13 @@ function App() {
try {
if (!cart.products.length) throw new Error("The cart is empty.");
if (
persona.account <
user.account <
cart.products.reduce((t, { price, count }) => t + price * count, 0)
) {
throw new Error("Not enough money.");
}

_userId = persona.name;
_userId = user.name;
let price = 0;
for (const p_i in products) {
price += products[p_i].price * products[p_i].count;
Expand Down Expand Up @@ -119,7 +119,7 @@ function App() {
if (status === "idle") {
return (
<form>
<UserInfo user={persona} />
<UserInfo user={user} />
<ProductList products={cart.products} />
<Coupon onEnter={handleSubmitByValidatingDataAndCreatingOrder} />
<button onClick={handleSubmitByValidatingDataAndCreatingOrder}>
Expand Down
6 changes: 3 additions & 3 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const user_ = {
account: 300,
};

export function useStore() {
const [persona, setPersona] = useState(user_);
return { persona, setPersona };
export function useUserStore() {
const [user, setUser] = useState(user_);
return { user, setUser };
}

0 comments on commit b84ba84

Please sign in to comment.