{product.price}
+Price: {`$${price}` || "Free, apparently!"}
(a photo here)
{info.description}
-Price: {info.price}
+Price: ${info.price}
: <>> ) diff --git a/client/src/components/User/Register.tsx b/client/src/components/User/Register.tsx index 1dd89c8..d8f0348 100644 --- a/client/src/components/User/Register.tsx +++ b/client/src/components/User/Register.tsx @@ -1,4 +1,5 @@ import { useEffect, useReducer, useState } from "react"; +import { useNavigate } from "react-router-dom"; import { initialState, reducer } from "../../store/store"; import { ActionType, emptySessionHeader } from "../../store/store_types"; import { userInfo } from '../../types/main'; @@ -16,6 +17,7 @@ function Register() { headers: emptySessionHeader } + const navigate = useNavigate(); const [state, dispatch] = useReducer(reducer, initialState); const [userInput, setUserInput] = useState(formInitialState); const [warningText, setWarningText] = useState('initial'); @@ -58,6 +60,7 @@ function Register() { if (register.ok) { setUserInput(formInitialState); + navigate('/'); } else { console.log('Something went wrong'); } diff --git a/client/src/store/store.ts b/client/src/store/store.ts index c88c42e..eea3d94 100644 --- a/client/src/store/store.ts +++ b/client/src/store/store.ts @@ -28,6 +28,18 @@ export const reducer = (state: appState, action: userAction) => { ...state, user: payload } + case ActionType.ADDTOCART: + let updatedContents = state.cart.contents; + console.log(action.payload); + updatedContents.push(action.payload); + + return { + ...state, + cart: { + ...state.cart, + contents: updatedContents + } + } default: return state; } diff --git a/client/src/store/store_types.ts b/client/src/store/store_types.ts index 90db9b6..c1899dd 100644 --- a/client/src/store/store_types.ts +++ b/client/src/store/store_types.ts @@ -8,7 +8,8 @@ export enum ActionType { REGISTERNEW, UPDATEONE, SEARCH, - USERLOGIN + USERLOGIN, + ADDTOCART } export interface userAction { diff --git a/client/src/types/main.d.ts b/client/src/types/main.d.ts index 0648493..30ce9dc 100644 --- a/client/src/types/main.d.ts +++ b/client/src/types/main.d.ts @@ -7,7 +7,7 @@ export type userInfo = { email: string id?: number - // NOTE: userInfo.name is deprecated + // NOTE: userInfo.name => displayName? name?: string password: string verifyPassword?: string diff --git a/client/src/util/helpers.ts b/client/src/util/helpers.ts new file mode 100644 index 0000000..3481f3a --- /dev/null +++ b/client/src/util/helpers.ts @@ -0,0 +1,7 @@ +import React from "react"; +import { ActionType, userAction } from "../store/store_types"; +import { Product } from "../types/main"; + +export const addToCart = (productData: Product, dispatch: React.DispatchSubtotal:
+{state.cart.subtotal || "Not found"}
{product.price}
+Quantity: {product.quantity || "1"}