This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| src/ | |
| ├── api/ | |
| │ ├── productsApi.ts | |
| │ └── cartApi.ts | |
| ├── components/ | |
| │ ├── base/ | |
| │ │ ├── Button/ | |
| │ │ ├── Input/ | |
| │ │ ├── Modal/ | |
| │ │ ├── Text/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const [state, dispatch] = useReducer(productDetailsReducer, { | |
| showModal: false, | |
| quantity: 1, | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ProductDetails/ | |
| ├── components/ | |
| │ └── ... | |
| ├── state/ | |
| │ ├── actions/ | |
| │ │ ├── add-to-cart.ts | |
| │ │ ├── get-current-cart.ts | |
| │ │ └── resolve-error-message.ts | |
| │ ├── index.ts | |
| │ ├── reducer.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ProductDetailsProvider | |
| product={product} | |
| quantity={quantity} | |
| increaseQuantity={increaseQuantity} | |
| decreaseQuantity={decreaseQuantity} | |
| > | |
| {/* ...your components */} | |
| </ProductDetailsProvider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createContext, PropsWithChildren, useContext } from 'react'; | |
| import { ProductDetailContext } from './types'; | |
| const context = createContext<ProductDetailContext>(undefined); | |
| const { Provider } = context; | |
| const ProductDetailsProvider = (props: PropsWithChildren<ProductDetailContext>) => { | |
| const { children, ...rest } = props; | |
| return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this should go on the types.ts file discussed previously | |
| export interface ProductDetailContext { | |
| product: ProductModel; | |
| quantity: number; | |
| increaseQuantity: () => void; | |
| decreaseQuantity: () => void; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function actionGenerator( | |
| dispatch: CustomDispatch, | |
| <...extraParamsNeeded>, | |
| ) { | |
| // the actual action to be called by the UI | |
| return (<...paramsToReceivedFromUI>) => {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default handleFormChange(dispatch: CustomDispatch) { | |
| return (newValues: FormState) => { | |
| dispatch({ type: 'update_form_state', values: newValues }); | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ProductDetailsPage = () => { | |
| const { | |
| isLoading, | |
| product, | |
| error, | |
| quantity, | |
| showModal, | |
| goBack, | |
| openModal, | |
| closeModal, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useReducer } from 'react'; | |
| import { useHistory } from 'react-router-dom'; | |
| import { useParams } from 'react-router'; | |
| import { useQuery } from 'react-query'; | |
| import { AppwriteException } from 'appwrite'; | |
| import productsApi from 'api/products'; | |
| import { QueryKey } from 'components/providers/Query'; | |
| import productDetailsReducer from './reducer'; | |
| import addToCart from './actions/add-to-cart'; |
NewerOlder