From 4499f33f13d43385979c101229e278b9f8497e37 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Thu, 7 Jan 2021 16:49:26 -0300 Subject: [PATCH] Reordering --- README.md | 25 ++++++++++++++----- components/auth/LoginView.tsx | 2 +- components/auth/SignUpView.tsx | 2 +- components/cart/CartItem/CartItem.tsx | 2 +- .../cart/CartSidebarView/CartSidebarView.tsx | 2 +- components/common/UserNav/DropdownMenu.tsx | 2 +- components/common/UserNav/UserNav.tsx | 2 +- .../product/ProductCard/ProductCard.tsx | 2 +- .../product/ProductView/ProductView.tsx | 2 +- .../WishlistButton/WishlistButton.tsx | 2 +- .../wishlist/WishlistCard/WishlistCard.tsx | 2 +- framework/bigcommerce/auth/index.ts | 3 +++ .../bigcommerce/{ => auth}/use-login.tsx | 4 +-- .../bigcommerce/{ => auth}/use-logout.tsx | 2 +- .../bigcommerce/{ => auth}/use-signup.tsx | 4 +-- framework/bigcommerce/cart/index.ts | 5 ++++ framework/bigcommerce/customer/index.ts | 1 + .../{ => customer}/use-customer.tsx | 2 +- framework/bigcommerce/product/index.ts | 2 ++ .../bigcommerce/{ => product}/use-price.tsx | 0 .../{products => product}/use-search.tsx | 0 .../bigcommerce/wishlist/use-add-item.tsx | 2 +- .../bigcommerce/wishlist/use-remove-item.tsx | 2 +- .../bigcommerce/wishlist/use-wishlist.tsx | 2 +- pages/cart.tsx | 2 +- pages/profile.tsx | 2 +- pages/search.tsx | 2 +- 27 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 framework/bigcommerce/auth/index.ts rename framework/bigcommerce/{ => auth}/use-login.tsx (91%) rename framework/bigcommerce/{ => auth}/use-logout.tsx (94%) rename framework/bigcommerce/{ => auth}/use-signup.tsx (91%) create mode 100644 framework/bigcommerce/cart/index.ts create mode 100644 framework/bigcommerce/customer/index.ts rename framework/bigcommerce/{ => customer}/use-customer.tsx (93%) create mode 100644 framework/bigcommerce/product/index.ts rename framework/bigcommerce/{ => product}/use-price.tsx (100%) rename framework/bigcommerce/{products => product}/use-search.tsx (100%) diff --git a/README.md b/README.md index de1452b75..54f021f74 100644 --- a/README.md +++ b/README.md @@ -97,17 +97,30 @@ People actively working on this project: @okbel & @lfades. ## Framework -Framework is where the data comes from. Contains mostly hooks and functions. +Framework is where the data comes from. It contains mostly hooks and functions. ## Structure -- ## product -- wishlist +Main folder and its exposed functions + +- `product` + - usePrice + - useSearch +- `wishlist` - useWishlist - addWishlistItem - removeWishlistItem -- auth +- `auth` + - useLogin + - useLogout + - useSignup +- `cart` -- config.json + - useCart + - useAddItem + - useRemoveItem + - useCartActions + - useUpdateItem -## Wishlist +- `config.json` +- README.md diff --git a/components/auth/LoginView.tsx b/components/auth/LoginView.tsx index 9102a53c6..89d5bf893 100644 --- a/components/auth/LoginView.tsx +++ b/components/auth/LoginView.tsx @@ -1,6 +1,6 @@ import { FC, useEffect, useState, useCallback } from 'react' import { Logo, Button, Input } from '@components/ui' -import useLogin from '@framework/use-login' +import useLogin from '@framework/auth/use-login' import { useUI } from '@components/ui/context' import { validate } from 'email-validator' diff --git a/components/auth/SignUpView.tsx b/components/auth/SignUpView.tsx index c49637d47..1b619828b 100644 --- a/components/auth/SignUpView.tsx +++ b/components/auth/SignUpView.tsx @@ -3,7 +3,7 @@ import { validate } from 'email-validator' import { Info } from '@components/icons' import { useUI } from '@components/ui/context' import { Logo, Button, Input } from '@components/ui' -import useSignup from '@framework/use-signup' +import useSignup from '@framework/auth/use-signup' interface Props {} diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index 283f3fa40..ac78d1849 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -3,7 +3,7 @@ import cn from 'classnames' import Image from 'next/image' import Link from 'next/link' import { Trash, Plus, Minus } from '@components/icons' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import useUpdateItem from '@framework/cart/use-update-item' import useRemoveItem from '@framework/cart/use-remove-item' import s from './CartItem.module.css' diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx index b313bdea9..2a58fd74f 100644 --- a/components/cart/CartSidebarView/CartSidebarView.tsx +++ b/components/cart/CartSidebarView/CartSidebarView.tsx @@ -5,7 +5,7 @@ import { Button } from '@components/ui' import { Bag, Cross, Check } from '@components/icons' import { useUI } from '@components/ui/context' import useCart from '@framework/cart/use-cart' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import CartItem from '../CartItem' import s from './CartSidebarView.module.css' diff --git a/components/common/UserNav/DropdownMenu.tsx b/components/common/UserNav/DropdownMenu.tsx index 7b02c863a..a5bc5fd86 100644 --- a/components/common/UserNav/DropdownMenu.tsx +++ b/components/common/UserNav/DropdownMenu.tsx @@ -15,7 +15,7 @@ import { clearAllBodyScrollLocks, } from 'body-scroll-lock' -import useLogout from '@framework/use-logout' +import useLogout from '@framework/auth/use-logout' interface DropdownMenuProps { open?: boolean diff --git a/components/common/UserNav/UserNav.tsx b/components/common/UserNav/UserNav.tsx index 31852f658..7b912422d 100644 --- a/components/common/UserNav/UserNav.tsx +++ b/components/common/UserNav/UserNav.tsx @@ -2,7 +2,7 @@ import { FC } from 'react' import Link from 'next/link' import cn from 'classnames' import useCart from '@framework/cart/use-cart' -import useCustomer from '@framework/use-customer' +import useCustomer from '@framework/customer/use-customer' import { Heart, Bag } from '@components/icons' import { useUI } from '@components/ui/context' import DropdownMenu from './DropdownMenu' diff --git a/components/product/ProductCard/ProductCard.tsx b/components/product/ProductCard/ProductCard.tsx index 85e69b3f2..58a201e8b 100644 --- a/components/product/ProductCard/ProductCard.tsx +++ b/components/product/ProductCard/ProductCard.tsx @@ -5,7 +5,7 @@ import type { FC } from 'react' import s from './ProductCard.module.css' import WishlistButton from '@components/wishlist/WishlistButton' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import type { ProductNode } from '@framework/api/operations/get-all-products' interface Props { diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 9703156a1..97342242d 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -8,7 +8,7 @@ import { useUI } from '@components/ui/context' import { Swatch, ProductSlider } from '@components/product' import { Button, Container, Text } from '@components/ui' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import useAddItem from '@framework/cart/use-add-item' import type { ProductNode } from '@framework/api/operations/get-product' import { diff --git a/components/wishlist/WishlistButton/WishlistButton.tsx b/components/wishlist/WishlistButton/WishlistButton.tsx index fda78a4bf..ea4abbb51 100644 --- a/components/wishlist/WishlistButton/WishlistButton.tsx +++ b/components/wishlist/WishlistButton/WishlistButton.tsx @@ -4,7 +4,7 @@ import { Heart } from '@components/icons' import { useUI } from '@components/ui/context' import type { ProductNode } from '@framework/api/operations/get-all-products' -import useCustomer from '@framework/use-customer' +import useCustomer from '@framework/customer/use-customer' import useAddItem from '@framework/wishlist/use-add-item' import useWishlist from '@framework/wishlist/use-wishlist' import useRemoveItem from '@framework/wishlist/use-remove-item' diff --git a/components/wishlist/WishlistCard/WishlistCard.tsx b/components/wishlist/WishlistCard/WishlistCard.tsx index 8cbd38bc7..b9b1a2f3e 100644 --- a/components/wishlist/WishlistCard/WishlistCard.tsx +++ b/components/wishlist/WishlistCard/WishlistCard.tsx @@ -3,7 +3,7 @@ import cn from 'classnames' import Link from 'next/link' import Image from 'next/image' import type { WishlistItem } from '@framework/api/wishlist' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import useRemoveItem from '@framework/wishlist/use-remove-item' import useAddItem from '@framework/cart/use-add-item' import { useUI } from '@components/ui/context' diff --git a/framework/bigcommerce/auth/index.ts b/framework/bigcommerce/auth/index.ts new file mode 100644 index 000000000..36e757a89 --- /dev/null +++ b/framework/bigcommerce/auth/index.ts @@ -0,0 +1,3 @@ +export { default as useLogin } from './use-login' +export { default as useLogout } from './use-logout' +export { default as useSignup } from './use-signup' diff --git a/framework/bigcommerce/use-login.tsx b/framework/bigcommerce/auth/use-login.tsx similarity index 91% rename from framework/bigcommerce/use-login.tsx rename to framework/bigcommerce/auth/use-login.tsx index 62d4ecbd7..fa2294666 100644 --- a/framework/bigcommerce/use-login.tsx +++ b/framework/bigcommerce/auth/use-login.tsx @@ -2,8 +2,8 @@ import { useCallback } from 'react' import type { HookFetcher } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useCommerceLogin from '@commerce/use-login' -import type { LoginBody } from './api/customers/login' -import useCustomer from './use-customer' +import type { LoginBody } from '../api/customers/login' +import useCustomer from '../customer/use-customer' const defaultOpts = { url: '/api/bigcommerce/customers/login', diff --git a/framework/bigcommerce/use-logout.tsx b/framework/bigcommerce/auth/use-logout.tsx similarity index 94% rename from framework/bigcommerce/use-logout.tsx rename to framework/bigcommerce/auth/use-logout.tsx index a9131ed3a..6aaee29f9 100644 --- a/framework/bigcommerce/use-logout.tsx +++ b/framework/bigcommerce/auth/use-logout.tsx @@ -1,7 +1,7 @@ import { useCallback } from 'react' import type { HookFetcher } from '@commerce/utils/types' import useCommerceLogout from '@commerce/use-logout' -import useCustomer from './use-customer' +import useCustomer from '../customer/use-customer' const defaultOpts = { url: '/api/bigcommerce/customers/logout', diff --git a/framework/bigcommerce/use-signup.tsx b/framework/bigcommerce/auth/use-signup.tsx similarity index 91% rename from framework/bigcommerce/use-signup.tsx rename to framework/bigcommerce/auth/use-signup.tsx index 4d907c5ac..c68ce7b7a 100644 --- a/framework/bigcommerce/use-signup.tsx +++ b/framework/bigcommerce/auth/use-signup.tsx @@ -2,8 +2,8 @@ import { useCallback } from 'react' import type { HookFetcher } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useCommerceSignup from '@commerce/use-signup' -import type { SignupBody } from './api/customers/signup' -import useCustomer from './use-customer' +import type { SignupBody } from '../api/customers/signup' +import useCustomer from '../customer/use-customer' const defaultOpts = { url: '/api/bigcommerce/customers/signup', diff --git a/framework/bigcommerce/cart/index.ts b/framework/bigcommerce/cart/index.ts new file mode 100644 index 000000000..43c6db2b7 --- /dev/null +++ b/framework/bigcommerce/cart/index.ts @@ -0,0 +1,5 @@ +export { default as useCart } from './use-cart' +export { default as useAddItem } from './use-add-item' +export { default as useRemoveItem } from './use-remove-item' +export { default as useWishlistActions } from './use-cart-actions' +export { default as useUpdateItem } from './use-cart-actions' diff --git a/framework/bigcommerce/customer/index.ts b/framework/bigcommerce/customer/index.ts new file mode 100644 index 000000000..6c903ecc5 --- /dev/null +++ b/framework/bigcommerce/customer/index.ts @@ -0,0 +1 @@ +export { default as useCustomer } from './use-customer' diff --git a/framework/bigcommerce/use-customer.tsx b/framework/bigcommerce/customer/use-customer.tsx similarity index 93% rename from framework/bigcommerce/use-customer.tsx rename to framework/bigcommerce/customer/use-customer.tsx index 4a08a0330..f44f16c1f 100644 --- a/framework/bigcommerce/use-customer.tsx +++ b/framework/bigcommerce/customer/use-customer.tsx @@ -1,7 +1,7 @@ import type { HookFetcher } from '@commerce/utils/types' import type { SwrOptions } from '@commerce/utils/use-data' import useCommerceCustomer from '@commerce/use-customer' -import type { Customer, CustomerData } from './api/customers' +import type { Customer, CustomerData } from '../api/customers' const defaultOpts = { url: '/api/bigcommerce/customers', diff --git a/framework/bigcommerce/product/index.ts b/framework/bigcommerce/product/index.ts new file mode 100644 index 000000000..426a3edcd --- /dev/null +++ b/framework/bigcommerce/product/index.ts @@ -0,0 +1,2 @@ +export { default as usePrice } from './use-price' +export { default as useSearch } from './use-search' diff --git a/framework/bigcommerce/use-price.tsx b/framework/bigcommerce/product/use-price.tsx similarity index 100% rename from framework/bigcommerce/use-price.tsx rename to framework/bigcommerce/product/use-price.tsx diff --git a/framework/bigcommerce/products/use-search.tsx b/framework/bigcommerce/product/use-search.tsx similarity index 100% rename from framework/bigcommerce/products/use-search.tsx rename to framework/bigcommerce/product/use-search.tsx diff --git a/framework/bigcommerce/wishlist/use-add-item.tsx b/framework/bigcommerce/wishlist/use-add-item.tsx index 0c355c181..6e7d9de41 100644 --- a/framework/bigcommerce/wishlist/use-add-item.tsx +++ b/framework/bigcommerce/wishlist/use-add-item.tsx @@ -3,7 +3,7 @@ import { HookFetcher } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useWishlistAddItem from '@commerce/wishlist/use-add-item' import type { ItemBody, AddItemBody } from '../api/wishlist' -import useCustomer from '../use-customer' +import useCustomer from '../customer/use-customer' import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist' const defaultOpts = { diff --git a/framework/bigcommerce/wishlist/use-remove-item.tsx b/framework/bigcommerce/wishlist/use-remove-item.tsx index 5ff55b5f2..86614a21a 100644 --- a/framework/bigcommerce/wishlist/use-remove-item.tsx +++ b/framework/bigcommerce/wishlist/use-remove-item.tsx @@ -3,7 +3,7 @@ import { HookFetcher } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useWishlistRemoveItem from '@commerce/wishlist/use-remove-item' import type { RemoveItemBody } from '../api/wishlist' -import useCustomer from '../use-customer' +import useCustomer from '../customer/use-customer' import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist' const defaultOpts = { diff --git a/framework/bigcommerce/wishlist/use-wishlist.tsx b/framework/bigcommerce/wishlist/use-wishlist.tsx index 4ab581155..6ebc8459d 100644 --- a/framework/bigcommerce/wishlist/use-wishlist.tsx +++ b/framework/bigcommerce/wishlist/use-wishlist.tsx @@ -2,7 +2,7 @@ import { HookFetcher } from '@commerce/utils/types' import { SwrOptions } from '@commerce/utils/use-data' import useCommerceWishlist from '@commerce/wishlist/use-wishlist' import type { Wishlist } from '../api/wishlist' -import useCustomer from '../use-customer' +import useCustomer from '../customer/use-customer' const defaultOpts = { url: '/api/bigcommerce/wishlist', diff --git a/pages/cart.tsx b/pages/cart.tsx index 7e6d17b21..fc06c4ced 100644 --- a/pages/cart.tsx +++ b/pages/cart.tsx @@ -2,7 +2,7 @@ import type { GetStaticPropsContext } from 'next' import { getConfig } from '@framework/api' import getAllPages from '@framework/api/operations/get-all-pages' import useCart from '@framework/cart/use-cart' -import usePrice from '@framework/use-price' +import usePrice from '@framework/product/use-price' import { Layout } from '@components/common' import { Button } from '@components/ui' import { Bag, Cross, Check } from '@components/icons' diff --git a/pages/profile.tsx b/pages/profile.tsx index 63de0b234..8b8c1a3b1 100644 --- a/pages/profile.tsx +++ b/pages/profile.tsx @@ -1,7 +1,7 @@ import type { GetStaticPropsContext } from 'next' import { getConfig } from '@framework/api' import getAllPages from '@framework/api/operations/get-all-pages' -import useCustomer from '@framework/use-customer' +import useCustomer from '@framework/customer/use-customer' import { Layout } from '@components/common' import { Container, Text } from '@components/ui' diff --git a/pages/search.tsx b/pages/search.tsx index 5110aba55..18b0d9c1a 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -6,7 +6,7 @@ import { useRouter } from 'next/router' import { getConfig } from '@framework/api' import getAllPages from '@framework/api/operations/get-all-pages' import getSiteInfo from '@framework/api/operations/get-site-info' -import useSearch from '@framework/products/use-search' +import useSearch from '@framework/product/use-search' import { Layout } from '@components/common' import { ProductCard } from '@components/product' import { Container, Grid, Skeleton } from '@components/ui'