├── .github
└── workflows
│ ├── export-repo-secrets.yml
│ └── publish.yaml
├── .gitignore
├── LICENSE
├── README.md
├── backend
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
└── src
│ ├── .env
│ ├── app.js
│ ├── controllers
│ └── product.js
│ ├── models
│ └── Product.js
│ ├── package-lock.json
│ ├── package.json
│ ├── routes
│ └── product.js
│ ├── server.js
│ └── utils
│ ├── apiFeatures.js
│ └── catchAsync.js
├── data
├── Dockerfile
├── data.js
├── docker-healthcheck.sh
├── init.sh
└── products.json
└── frontend
├── .dockerignore
├── Dockerfile
└── client
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── favicon.png
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.jsx
├── components
├── cartProduct
│ └── CartProduct.jsx
├── filters
│ ├── Checkbox.jsx
│ ├── Sizes.jsx
│ └── checkbox.css
├── footer
│ └── Footer.jsx
├── header
│ ├── Header.jsx
│ ├── StoreHeader.jsx
│ └── header.module.css
├── loader
│ ├── Loader.css
│ └── Loader.jsx
└── products
│ ├── Product.jsx
│ ├── ProductsGrid.jsx
│ └── products.module.css
├── context
├── cartContext.js
└── cartReducer.js
├── img
├── classic_boba.png
├── ginger_boba.png
├── mango_chill.png
├── matcha_chill.png
├── matcha_latte.png
├── pulumipus_chill.png
├── science.png
├── strawberry_chill.png
├── taro_boba.png
├── taro_chill.png
└── thai_boba.png
├── index.css
├── index.js
├── serviceWorker.js
├── setupProxy.js
├── utils
└── fetch.js
└── views
├── cart
├── Cart.jsx
└── cart.module.css
├── homepage
└── Home.jsx
└── product
├── ViewProduct.jsx
└── product.module.css
/.github/workflows/export-repo-secrets.yml:
--------------------------------------------------------------------------------
1 | permissions: write-all # Equivalent to default permissions plus id-token: write
2 | name: Export secrets to ESC
3 | on: [ workflow_dispatch ]
4 | jobs:
5 | export-to-esc:
6 | runs-on: ubuntu-latest
7 | name: export GitHub secrets to ESC
8 | steps:
9 | - name: Generate a GitHub token
10 | id: generate-token
11 | uses: actions/create-github-app-token@v1
12 | with:
13 | app-id: 1256780 # Export Secrets GitHub App
14 | private-key: ${{ secrets.EXPORT_SECRETS_PRIVATE_KEY }}
15 | - name: Export secrets to ESC
16 | uses: pulumi/esc-export-secrets-action@v1
17 | with:
18 | organization: pulumi
19 | org-environment: github-secrets/pulumi-tutorial-pulumi-fundamentals
20 | exclude-secrets: EXPORT_SECRETS_PRIVATE_KEY
21 | github-token: ${{ steps.generate-token.outputs.token }}
22 | oidc-auth: true
23 | oidc-requested-token-type: urn:pulumi:token-type:access_token:organization
24 | env:
25 | GITHUB_SECRETS: ${{ toJSON(secrets) }}
26 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yaml:
--------------------------------------------------------------------------------
1 | permissions: write-all # Equivalent to default permissions plus id-token: write
2 | name: Publish to Docker Hub
3 | on:
4 | push:
5 | branches:
6 | - main
7 | env:
8 | REGISTRY: docker.io
9 | FRONT_IMAGE_NAME: ${{ github.repository }}-frontend
10 | BACK_IMAGE_NAME: ${{ github.repository }}-backend
11 | DATABASE_IMAGE_NAME: ${{ github.repository }}-database
12 | ESC_ACTION_OIDC_AUTH: true
13 | ESC_ACTION_OIDC_ORGANIZATION: pulumi
14 | ESC_ACTION_OIDC_REQUESTED_TOKEN_TYPE: urn:pulumi:token-type:access_token:organization
15 | ESC_ACTION_ENVIRONMENT: github-secrets/pulumi-tutorial-pulumi-fundamentals
16 | ESC_ACTION_EXPORT_ENVIRONMENT_VARIABLES: false
17 |
18 | jobs:
19 | push-front-to-registry:
20 | name: Publish frontend image to Docker Hub
21 | runs-on: ubuntu-latest
22 | steps:
23 | - name: Fetch secrets from ESC
24 | id: esc-secrets
25 | uses: pulumi/esc-action@v1
26 | - name: Checkout
27 | uses: actions/checkout@v3
28 |
29 | - name: Log into Docker Hub
30 | uses: docker/login-action@v2
31 | with:
32 | username: ${{ steps.esc-secrets.outputs.DOCKERHUB_USERNAME }}
33 | password: ${{ steps.esc-secrets.outputs.DOCKERHUB_TOKEN }}
34 |
35 | - name: Add front metadata for Docker Hub
36 | id: meta-front
37 | uses: docker/metadata-action@v3
38 | with:
39 | images: ${{ env.REGISTRY }}/${{ env.FRONT_IMAGE_NAME }}
40 | flavor: |
41 | latest=true
42 |
43 |
44 | - name: Set up QEMU
45 | uses: docker/setup-qemu-action@v2
46 |
47 | - name: Set up Docker Buildx
48 | uses: docker/setup-buildx-action@v2
49 |
50 | - name: Build and push frontend image
51 | uses: docker/build-push-action@v3
52 | with:
53 | context: ./frontend/
54 | platforms: linux/amd64,linux/arm64
55 | push: true
56 | tags: ${{ steps.meta-front.outputs.tags }}
57 | labels: ${{ steps.meta-front.outputs.labels }}
58 |
59 | push-back-to-registry:
60 | name: Publish backend image to Docker Hub
61 | runs-on: ubuntu-latest
62 | steps:
63 | - name: Fetch secrets from ESC
64 | id: esc-secrets
65 | uses: pulumi/esc-action@v1
66 | - name: Checkout
67 | uses: actions/checkout@v3
68 |
69 | - name: Log into Docker Hub
70 | uses: docker/login-action@v2
71 | with:
72 | username: ${{ steps.esc-secrets.outputs.DOCKERHUB_USERNAME }}
73 | password: ${{ steps.esc-secrets.outputs.DOCKERHUB_TOKEN }}
74 |
75 | - name: Add back metadata for Docker Hub
76 | id: meta-back
77 | uses: docker/metadata-action@v3
78 | with:
79 | images: ${{ env.REGISTRY }}/${{ env.BACK_IMAGE_NAME }}
80 | flavor: |
81 | latest=true
82 |
83 |
84 | - name: Set up QEMU
85 | uses: docker/setup-qemu-action@v2
86 |
87 | - name: Set up Docker Buildx
88 | uses: docker/setup-buildx-action@v2
89 |
90 | - name: Build and push backend image
91 | uses: docker/build-push-action@v3
92 | with:
93 | context: ./backend/
94 | platforms: linux/amd64,linux/arm64
95 | push: true
96 | tags: ${{ steps.meta-back.outputs.tags }}
97 | labels: ${{ steps.meta-back.outputs.labels }}
98 |
99 | push-db-to-registry:
100 | name: Publish database image to Docker Hub
101 | runs-on: ubuntu-latest
102 | steps:
103 | - name: Fetch secrets from ESC
104 | id: esc-secrets
105 | uses: pulumi/esc-action@v1
106 | - name: Checkout
107 | uses: actions/checkout@v3
108 |
109 | - name: Log into Docker Hub
110 | uses: docker/login-action@v2
111 | with:
112 | username: ${{ steps.esc-secrets.outputs.DOCKERHUB_USERNAME }}
113 | password: ${{ steps.esc-secrets.outputs.DOCKERHUB_TOKEN }}
114 |
115 | - name: Add data metadata for Docker Hub
116 | id: meta-data
117 | uses: docker/metadata-action@v3
118 | with:
119 | images: ${{ env.REGISTRY }}/${{ env.DATABASE_IMAGE_NAME }}
120 | flavor: |
121 | latest=true
122 |
123 |
124 | - name: Set up QEMU
125 | uses: docker/setup-qemu-action@v2
126 |
127 | - name: Set up Docker Buildx
128 | uses: docker/setup-buildx-action@v2
129 |
130 | - name: Build and push database image
131 | uses: docker/build-push-action@v3
132 | with:
133 | context: ./data/
134 | platforms: linux/amd64,linux/arm64
135 | push: true
136 | tags: ${{ steps.meta-data.outputs.tags }}
137 | labels: ${{ steps.meta-data.outputs.labels }}
138 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # MacOS
2 | .DS_Store
3 | Icon?
4 | ._*
5 |
6 | # General building
7 | build/
8 | *.tgz
9 |
10 | # npm/yarn
11 | node_modules
12 | .npm/
13 | .yarn/
14 | *.log*
15 |
16 | # IDE
17 | .idea/
18 | */.idea/
19 | .vscode/
20 | */.vscode/
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pulumi Fundamentals Tutorial
2 |
3 | The code in this repository is used in conjunction with the [Pulumi Learn "Pulumi Fundamentals" pathway](https://www.pulumi.com/learn/pulumi-fundamentals/). Details and full instructions for using this code are found there.
4 |
5 | ## Prerequisites
6 |
7 | You will need the following tools to complete this tutorial:
8 |
9 | * A [Pulumi account and token](https://www.pulumi.com/docs/pulumi-cloud/accounts#access-tokens)
10 | * If you don't have an account, go to the [signup page](https://app.pulumi.com/signup).
11 | * The [Pulumi CLI](https://www.pulumi.com/docs/cli/)
12 | * If you don't have the CLI, go to the [installation page](https://www.pulumi.com/docs/install/).
13 | * [Docker](https://docs.docker.com/get-docker/)
14 | * One of the following languages:
15 | * For the TypeScript/JavaScript version, Node.js 14 or later
16 | * For the Python version, Python 3.8 or later
17 | * For the Java version, Java 11 or later and Gradle 7.4 or later
18 | * For the YAML version, nothing specific!
19 |
--------------------------------------------------------------------------------
/backend/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | First off, thank you for considering contributing to Shopping Cart. It's people like you that make Shopping Cart a nice place to getting started on React and NodeJS.
4 |
5 | When contributing to this repository, please first discuss the change you wish to make via issue,
6 | email, or any other method with the owners of this repository before making a change.
7 |
8 | Please note we have a code of conduct, please follow it in all your interactions with the project.
9 |
10 | ## Pull Request Process
11 |
12 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a
13 | build.
14 | 1. Update the README.md with details of changes to the interface, this includes new environment
15 | variables, exposed ports, useful file locations and container parameters.
16 | 1. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
17 | do not have permission to do that, you may request the second reviewer to merge it for you.
18 | 1. Please link your pull request to an existing issue.
19 |
20 | ## Folder Structure
21 |
22 | ```bash
23 | ├── app.js
24 | ├── client
25 | │ ├── package.json
26 | │ ├── package-lock.json
27 | │ ├── public
28 | │ │ ├── favicon.ico
29 | │ │ ├── index.html
30 | │ │ ├── logo192.png
31 | │ │ ├── logo512.png
32 | │ │ ├── manifest.json
33 | │ │ └── robots.txt
34 | │ ├── README.md
35 | │ └── src
36 | │ ├── App.css
37 | │ ├── App.jsx
38 | │ ├── App.test.js
39 | │ ├── components
40 | │ │ ├── cartProduct
41 | │ │ │ └── CartProduct.jsx
42 | │ │ ├── checkbox
43 | │ │ │ └── Checkbox.jsx
44 | │ │ ├── footer
45 | │ │ │ └── Footer.jsx
46 | │ │ ├── header
47 | │ │ │ └── Header.jsx
48 | │ │ ├── loader
49 | │ │ │ ├── Loader.css
50 | │ │ │ └── Loader.jsx
51 | │ │ ├── product
52 | │ │ │ └── Product.jsx
53 | │ │ ├── select
54 | │ │ │ └── Select.jsx
55 | │ │ └── sizes
56 | │ │ ├── Sizes.css
57 | │ │ └── Sizes.jsx
58 | │ ├── context
59 | │ │ ├── cartContext.js
60 | │ │ └── cartReducer.js
61 | │ ├── index.css
62 | │ ├── index.js
63 | │ ├── serviceWorker.js
64 | │ ├── setupTests.js
65 | │ ├── utils
66 | │ │ └── fetch.js
67 | │ └── views
68 | │ ├── cart
69 | │ │ ├── Cart.css
70 | │ │ └── Cart.jsx
71 | │ └── products
72 | │ ├── Products.css
73 | │ └── Products.jsx
74 | ├── controllers
75 | │ └── product.js
76 | ├── data
77 | │ └── products.json
78 | ├── github
79 | ├── LICENSE
80 | ├── models
81 | │ └── Product.js
82 | ├── package.json
83 | ├── package-lock.json
84 | ├── README.md
85 | ├── routes
86 | │ └── product.js
87 | ├── server.js
88 | └── utils
89 | ├── apiFeatures.js
90 | └── catchAsync.js
91 | ```
92 |
93 | ## Scripts
94 |
95 | An explanation of the `package.json` scripts.
96 |
97 | | Command | Description |
98 | | --------------- | ------------------------------------------------------------------|
99 | | start | Start a production server for Shopping Cart |
100 | | dev | Start a nodemon dev server for the backend and front-end react |
101 | | server | Start a nodemon dev server for backend |
102 | | dev:server | Build the front-end and run a production server for Shopping Cart |
103 | | client | Start a dev server for Front-End |
104 | | heorku-postbuild| Build the Front-End for deploying to heroku |
105 |
106 | ## Technologies
107 |
108 | | Tech | Description |
109 | | --------------- | --------------------------------------------- |
110 | | NodeJs | JavaScript Runtime to create backend services |
111 | | Express | Server framework |
112 | | React | Front end user interface |
113 | | MongoDB | NoSQL Database to store Data |
114 | | Mongoose | Object Modelling for MongoDB |
115 |
116 | ## Code of Conduct
117 |
118 | ### Our Pledge
119 |
120 | In the interest of fostering an open and welcoming environment, we as
121 | contributors and maintainers pledge to making participation in our project and
122 | our community a harassment-free experience for everyone, regardless of age, body
123 | size, disability, ethnicity, gender identity and expression, level of experience,
124 | nationality, personal appearance, race, religion, or sexual identity and
125 | orientation.
126 |
127 | ### Our Standards
128 |
129 | Examples of behavior that contributes to creating a positive environment
130 | include:
131 |
132 | * Using welcoming and inclusive language
133 | * Being respectful of differing viewpoints and experiences
134 | * Gracefully accepting constructive criticism
135 | * Focusing on what is best for the community
136 | * Showing empathy towards other community members
137 |
138 | Examples of unacceptable behavior by participants include:
139 |
140 | * The use of sexualized language or imagery and unwelcome sexual attention or
141 | advances
142 | * Trolling, insulting/derogatory comments, and personal or political attacks
143 | * Public or private harassment
144 | * Publishing others' private information, such as a physical or electronic
145 | address, without explicit permission
146 | * Other conduct which could reasonably be considered inappropriate in a
147 | professional setting
148 |
149 | ### Our Responsibilities
150 |
151 | Project maintainers are responsible for clarifying the standards of acceptable
152 | behavior and are expected to take appropriate and fair corrective action in
153 | response to any instances of unacceptable behavior.
154 |
155 | Project maintainers have the right and responsibility to remove, edit, or
156 | reject comments, commits, code, wiki edits, issues, and other contributions
157 | that are not aligned to this Code of Conduct, or to ban temporarily or
158 | permanently any contributor for other behaviors that they deem inappropriate,
159 | threatening, offensive, or harmful.
160 |
161 | ### Scope
162 |
163 | This Code of Conduct applies both within project spaces and in public spaces
164 | when an individual is representing the project or its community. Examples of
165 | representing a project or community include using an official project e-mail
166 | address, posting via an official social media account, or acting as an appointed
167 | representative at an online or offline event. Representation of a project may be
168 | further defined and clarified by project maintainers.
169 |
170 | ### Enforcement
171 |
172 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
173 | reported by contacting the project team at shubham.battoo@hotmail.com. All
174 | complaints will be reviewed and investigated and will result in a response that
175 | is deemed necessary and appropriate to the circumstances. The project team is
176 | obligated to maintain confidentiality with regard to the reporter of an incident.
177 | Further details of specific enforcement policies may be posted separately.
178 |
179 | Project maintainers who do not follow or enforce the Code of Conduct in good
180 | faith may face temporary or permanent repercussions as determined by other
181 | members of the project's leadership.
182 |
183 | ### Attribution
184 |
185 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
186 | available at [http://contributor-covenant.org/version/1/4][version]
187 |
188 | [homepage]: http://contributor-covenant.org
189 | [version]: http://contributor-covenant.org/version/1/4/
190 |
--------------------------------------------------------------------------------
/backend/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:14
2 |
3 | # Create app directory
4 | WORKDIR /usr/src/app
5 |
6 | COPY ./src/package*.json ./
7 |
8 | RUN npm install
9 | COPY ./src .
10 | RUN npm build
11 | EXPOSE 3000
12 |
13 | CMD [ "npm", "start" ]
--------------------------------------------------------------------------------
/backend/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Shubham Battoo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/backend/README.md:
--------------------------------------------------------------------------------
1 |
2 | Pulumipus Boba Tea Shop Demo using React and Express
3 |
4 |
5 | > MERN Shopping cart created with React, NodeJS, MongoDB
6 | >
7 | > Forked from https://github.com/shubhambattoo/shopping-cart
8 |
9 | ## Prerequisites
10 |
11 | If you are running from the tutorials, all you need is Pulumi and Docker. See
12 | [the start of the Docker lab](../README.md#Prerequisites) for more information.
13 |
14 | If you're running this app locally without the tutorial, you need the following tools:
15 |
16 | * NodeJS 12+
17 | * MongoDB installed locally
18 | * npm or yarn
19 |
20 | ## Getting Started
21 |
22 | Clone or Download
23 |
24 | ```sh
25 | git clone https://github.com/pulumi/tutorials.git
26 | cd tutorials/introduction-to-pulumi/docker/app/backend
27 | ```
28 |
29 | Run `npm install` to install all the dependencies
30 |
31 | Create a .env file:
32 |
33 | ```txt
34 | PORT=3000
35 | DATABASE_HOST=mongodb://yoururl/
36 | DATABASE_NAME=yourDBNAME
37 | NODE_ENV=development
38 | ```
39 |
40 | To import the mock product data to MongoDB, run the following command in your terminal from the app root:
41 |
42 | ```sh
43 | cd /data
44 | mongoimport --db [yourDBName] --collection products --file products.json --jsonArray
45 | ```
46 |
47 | To start up the backend services, run `npm start`. This command will start the backend service on port 3000.
48 |
49 | ## Client Side
50 |
51 | Development
52 |
53 | ```
54 | cd client
55 | npm install
56 | npm start
57 | ```
58 |
59 | This should start up the React application on port 3001.
60 |
61 | To view the web app, open [http://localhost:3001](http://localhost:3001).
62 |
63 | ## Contributing
64 |
65 | Contributions, issues and feature requests are welcome!
66 | Feel free to check [issues](https://github.com/pulumi/tutorials/issues) page.
67 |
68 | View [CONTRIBUTING.md](https://github.com/pulumi/tutorials/blob/master/CONTRIBUTING.md) to learn about the style guide, folder structure, scripts, and how to contribute.
69 |
70 | ## Contributors
71 |
72 |
124 |
125 | ## Show your support
126 |
127 | Give a ⭐️ if this project helped you!
128 |
--------------------------------------------------------------------------------
/backend/src/.env:
--------------------------------------------------------------------------------
1 | PORT=3000
2 | DATABASE_HOST=mongodb://mongo:27017
3 | DATABASE_NAME=cart
4 | NODE_ENV=development
--------------------------------------------------------------------------------
/backend/src/app.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const morgan = require('morgan');
3 | const cors = require('cors');
4 | const path = require('path');
5 | const productRoutes = require('./routes/product');
6 | const app = express();
7 |
8 | app.use(express.json({ limit: '10kb' }));
9 | app.use(cors());
10 | app.use(express.static('client/build'));
11 |
12 | if (process.env.NODE_ENV === 'development') {
13 | app.use(morgan('dev'));
14 | }
15 |
16 | app.use('/api/products', productRoutes);
17 |
18 | app.use((req, res) => {
19 | res.sendFile(path.join(__dirname, '/client/build/index.html'));
20 | });
21 |
22 | app.all('*', (req, res, next) => {
23 | res.sendFile(path.join(__dirname, '/client/build/index.html'));
24 | });
25 |
26 | module.exports = app;
27 |
--------------------------------------------------------------------------------
/backend/src/controllers/product.js:
--------------------------------------------------------------------------------
1 | const catchAsync = require('./../utils/catchAsync');
2 | const Product = require('./../models/Product');
3 | const ApiFeatures = require('./../utils/apiFeatures');
4 |
5 | exports.createProduct = catchAsync(async (req, res, next) => {
6 | const doc = await Product.create(req.body);
7 |
8 | res.status(201).json({
9 | status: 'ok',
10 | data: {
11 | product: doc,
12 | },
13 | });
14 | });
15 |
16 | exports.getProducts = catchAsync(async (req, res, next) => {
17 | const features = new ApiFeatures(Product.find(), req.query)
18 | .filter()
19 | .sort()
20 | .paginate()
21 | .limitFields();
22 |
23 | const docs = await features.query;
24 |
25 | res.json({
26 | status: 'ok',
27 | results: docs.length,
28 | data: { products: docs },
29 | });
30 | });
31 |
32 | exports.getProduct = catchAsync(async (req, res, next) => {
33 | const product = await Product.findOne({ _id: req.params.id });
34 |
35 | res.status(200).json({
36 | status: 'ok',
37 | data: {
38 | product,
39 | },
40 | });
41 | });
42 |
--------------------------------------------------------------------------------
/backend/src/models/Product.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 |
3 | const productSchema = new mongoose.Schema({
4 | name: {
5 | type: String,
6 | required: [true, 'product name is required'],
7 | },
8 | price: {
9 | type: Number,
10 | required: [true, 'price is required'],
11 | },
12 | description: {
13 | type: String,
14 | maxlength: 300,
15 | },
16 | created: {
17 | type: Number,
18 | default: Date.now(),
19 | },
20 | currency: {
21 | type: Object,
22 | default: {
23 | id: 'USD',
24 | format: '$',
25 | },
26 | },
27 | sizes: {
28 | type: Array,
29 | required: true,
30 | },
31 | productCode: String,
32 | images: [
33 | {
34 | src: String
35 | },
36 | ],
37 | category: {
38 | type: String,
39 | default: 'tea',
40 | required: [true, 'product category is required'],
41 | },
42 | teaType: {
43 | type: Number,
44 | default: 1, // 1:All 2:Boba 3:Latte 4:Chills
45 | },
46 | status: {
47 | type: Number,
48 | default: 1, // 0:Out of stock, 1:New 2:Available 3:Upcoming
49 | },
50 | ratings: {
51 | total: Number,
52 | avg: Number,
53 | reviews: [Object],
54 | },
55 | });
56 |
57 | module.exports = mongoose.model('Product', productSchema);
58 |
--------------------------------------------------------------------------------
/backend/src/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "pulumipus-boba-tea-shop",
3 | "version": "0.0.1",
4 | "description": "Pulumipus Boba Tea Shop Demo App",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node server.js",
8 | "client": "cd client && npm start",
9 | "server": "nodemon server.js",
10 | "dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
11 | "dev:server": "cd client && yarn build && cd .. && yarn start"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/pulumi/tutorials.git"
16 | },
17 | "keywords": [
18 | "pulumi",
19 | "demo",
20 | "react",
21 | "javsacript",
22 | "nodejs",
23 | "mongodb",
24 | "shopping-cart",
25 | "backend-services",
26 | "hooks-api-react",
27 | "context-api",
28 | "usereducer",
29 | "tea",
30 | "create-react-app",
31 | "mern-stack"
32 | ],
33 | "author": "Pulumi (forked from shubhambattoo)",
34 | "license": "ISC",
35 | "bugs": {
36 | "url": "https://github.com/pulumi/tutorials/issues"
37 | },
38 | "homepage": "https://learn.pulumi.com",
39 | "dependencies": {
40 | "cors": "^2.8.5",
41 | "dotenv": "^8.2.0",
42 | "express": "^4.17.1",
43 | "mongoose": "^5.12.2",
44 | "morgan": "^1.10.0"
45 | },
46 | "devDependencies": {
47 | "concurrently": "^5.3.0",
48 | "nodemon": "^2.0.3"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/backend/src/routes/product.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const router = express.Router();
3 | const productController = require('./../controllers/product');
4 |
5 | router.get('/', productController.getProducts);
6 | router.get('/:id', productController.getProduct);
7 | router.post('/', productController.createProduct);
8 |
9 | module.exports = router;
10 |
--------------------------------------------------------------------------------
/backend/src/server.js:
--------------------------------------------------------------------------------
1 | require('dotenv').config();
2 | const mongoose = require('mongoose');
3 |
4 | process.on('uncaughtException', (err) => {
5 | console.log('Unhandler Exception! Shutting Down...');
6 | console.log(err.name, err.message);
7 | process.exit(1);
8 | });
9 |
10 | mongoose
11 | .connect(process.env.DATABASE_HOST + "/" + process.env.DATABASE_NAME, {
12 | useNewUrlParser: true,
13 | useUnifiedTopology: true,
14 | useFindAndModify: false,
15 | useCreateIndex: true,
16 | })
17 | .then(() => {
18 | console.log(`${process.env.DATABASE_NAME} db connected successfully`);
19 | })
20 | .catch((err) => {
21 | console.log(err);
22 | console.log('db error');
23 | process.exit(1);
24 | });
25 |
26 | const app = require('./app');
27 |
28 | const PORT = process.env.PORT || 3000;
29 | app.listen(PORT, () => {
30 | console.log(`server started on ${PORT}`);
31 | });
32 |
--------------------------------------------------------------------------------
/backend/src/utils/apiFeatures.js:
--------------------------------------------------------------------------------
1 | class ApiFeatures {
2 | constructor(query, queryParams) {
3 | this.query = query;
4 | this.queryParams = queryParams;
5 | }
6 |
7 | filter() {
8 | const queryString = { ...this.queryParams };
9 | const excludedFields = ['page', 'sort', 'fields', 'limit'];
10 | excludedFields.forEach((el) => {
11 | delete queryString[el];
12 | });
13 |
14 | if (queryString.sizes && queryString.sizes.in) {
15 | const arrSizes = queryString.sizes.in.split(',');
16 | queryString.sizes = { in: arrSizes };
17 | }
18 |
19 | // replace the operators
20 | let queryStr = JSON.stringify(queryString);
21 | queryStr = queryStr.replace(/\b(gte|gt|lte|lt|in)\b/g, (str) => {
22 | return `$${str}`;
23 | });
24 |
25 | // make query
26 | this.query = this.query.find(JSON.parse(queryStr));
27 | return this;
28 | }
29 |
30 | limitFields() {
31 | if (this.queryParams.fields) {
32 | const fields = this.queryParams.fields.split(',').join(' ');
33 | this.query = this.query.select(fields);
34 | } else {
35 | this.query = this.query.select('-__v');
36 | }
37 | return this;
38 | }
39 |
40 | sort() {
41 | if (this.queryParams.sort) {
42 | const sortBy = this.queryParams.sort.split(',').join(' ');
43 | this.query = this.query.sort(sortBy);
44 | } else {
45 | this.query = this.query.sort('created');
46 | }
47 | return this;
48 | }
49 |
50 | paginate() {
51 | const page = this.queryParams.page * 1 || 1;
52 | const limit = this.queryParams.limit * 1 || 20;
53 | const skip = (page - 1) * limit;
54 |
55 | this.query = this.query.skip(skip).limit(limit);
56 |
57 | return this;
58 | }
59 | }
60 |
61 | module.exports = ApiFeatures;
62 |
--------------------------------------------------------------------------------
/backend/src/utils/catchAsync.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Taking the function and returning another function
3 | * to handle errors with async await
4 | */
5 | module.exports = (fn) => {
6 | return (req, res, next) => {
7 | fn(req, res, next).catch(next);
8 | };
9 | };
10 |
--------------------------------------------------------------------------------
/data/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mongo:focal
2 |
3 | ENV MONGO_INITDB_DATABASE=cart
4 |
5 | COPY data.js /docker-entrypoint-initdb.d/mongo-init.js
6 | COPY docker-healthcheck.sh /usr/local/bin
7 |
8 | RUN chmod +x /usr/local/bin/docker-healthcheck.sh
9 |
10 | HEALTHCHECK CMD ["/usr/local/bin/docker-healthcheck.sh"]
11 |
12 | ENTRYPOINT ["docker-entrypoint.sh"]
13 |
14 | EXPOSE 27017
15 | CMD ["mongod"]
--------------------------------------------------------------------------------
/data/data.js:
--------------------------------------------------------------------------------
1 | cartDb = db.getSiblingDB('cart')
2 |
3 | cartDb.createUser({
4 | user: "user",
5 | pwd: "secret",
6 | roles: [ { role: "readWrite", db: "data" } ]
7 | })
8 |
9 | cartDb.createCollection('products')
10 |
11 | productsColl = cartDb.products
12 |
13 | productsColl.insertMany([
14 | {
15 | "_id": "5f6d025008a1b6f0e5636bc3",
16 | "status": 1,
17 | "teaType": 2,
18 | "category": "boba",
19 | "images": [{
20 | "src": "classic_boba.png"
21 | }],
22 | "created": 1600979464563,
23 | "currency": {
24 | "id": "USD",
25 | "format": "$"
26 | },
27 | "sizes": [
28 | "M",
29 | "L"
30 | ],
31 | "name": "Classic Milk Tea",
32 | "price": 5.00,
33 | "description": "Black tea is shaken with frothy milk, crushed ice, and a few generous handfuls of marble-sized, caramelized tapioca pearls.",
34 | "productCode": "852542-105",
35 | "ratings": {
36 | "total": 63,
37 | "avg": 5,
38 | "reviews": []
39 | }
40 | },
41 | {
42 | "_id": "5f6d0ad908a1b6f0e5636bc4",
43 | "status": 1,
44 | "teaType": 2,
45 | "category": "boba",
46 | "images": [{
47 | "src": "ginger_boba.png"
48 | }],
49 | "created": 1600981421087,
50 | "currency": {
51 | "id": "USD",
52 | "format": "$"
53 | },
54 | "sizes": [
55 | "M",
56 | "L"
57 | ],
58 | "name": "Ginger Milk Tea",
59 | "price": 5.00,
60 | "description": "A creamy ice cold drink with a strong taste of ginger, added by a cool and refreshing tea flavor.",
61 | "productCode": "CT2816-100",
62 | "ratings": {
63 | "total": 0,
64 | "avg": 0,
65 | "reviews": []
66 | }
67 | },
68 | {
69 | "_id": "5f6d734f19ce90070b4837ce",
70 | "status": 2,
71 | "teaType": 2,
72 | "category": "boba",
73 | "images": [{
74 | "src": "taro_boba.png"
75 | }],
76 | "created": 1601008415022,
77 | "currency": {
78 | "id": "USD",
79 | "format": "$"
80 | },
81 | "sizes": [
82 | "M",
83 | "L"
84 | ],
85 | "name": "Taro Milk Tea",
86 | "price": 6.00,
87 | "description": "Taro bubble tea is recognized by its color, which runs from purple-tinged brown to nearly lilac, and its coconut-like flavor. Taro (a root vegetable similar to a sweet potato) is pureed and added to boba milk tea, where it acts as a thickener and flavoring.",
88 | "productCode": "CI9924-100",
89 | "ratings": {
90 | "total": 4,
91 | "avg": 5,
92 | "reviews": []
93 | }
94 | },
95 | {
96 | "_id": "5f6d74c519ce90070b4837cf",
97 | "status": 1,
98 | "teaType": 2,
99 | "category": "boba",
100 | "images": [{
101 | "src": "thai_boba.png"
102 | }],
103 | "created": 1601008816970,
104 | "currency": {
105 | "id": "USD",
106 | "format": "$"
107 | },
108 | "sizes": [
109 | "M",
110 | "L"
111 | ],
112 | "name": "Thai Milk Tea",
113 | "price": 5.00,
114 | "description": "Thai Tea is made from strongly-brewed black tea, spiced with star anise, crushed tamarind, and cardamom. It is then sweetened sugar and sweetened condensed milk.",
115 | "productCode": "AT8241-005",
116 | "ratings": {
117 | "total": 34,
118 | "avg": 4.5,
119 | "reviews": []
120 | }
121 | },
122 | {
123 | "_id": "5f6d761c19ce90070b4837d0",
124 | "status": 1,
125 | "teaType": 4,
126 | "category": "chill",
127 | "images": [{
128 | "src": "mango_chill.png"
129 | }],
130 | "created": 1601009129502,
131 | "currency": {
132 | "id": "USD",
133 | "format": "$"
134 | },
135 | "sizes": [
136 | "S",
137 | "M",
138 | "L"
139 | ],
140 | "name": "Mango Chill",
141 | "price": 5.00,
142 | "description": "A juicy, tart-sweet blend of mango, ginger & floral notes on ice.",
143 | "productCode": "CT4063-400",
144 | "ratings": {
145 | "total": 34,
146 | "avg": 4.5,
147 | "reviews": []
148 | }
149 | },
150 | {
151 | "_id": "5f6e0a4340fdb952de7f9314",
152 | "status": 2,
153 | "teaType": 3,
154 | "category": "latte",
155 | "images": [{
156 | "src": "matcha_latte.png"
157 | }],
158 | "created": 1601009129502,
159 | "currency": {
160 | "id": "USD",
161 | "format": "$"
162 | },
163 | "sizes": [
164 | "S",
165 | "M"
166 | ],
167 | "name": "Matcha Latte",
168 | "price": 6.00,
169 | "description": "A delicious base of energizing matcha green tea, spiced to perfection with hints of cinnamon, nutmeg and cardamom. Sweet but not too sweet with the goodness of matcha.",
170 | "productCode": "BQ9646-001",
171 | "ratings": {
172 | "total": 102,
173 | "avg": 4.5,
174 | "reviews": []
175 | }
176 | },
177 | {
178 | "_id": "5f6e0b6440fdb952de7f9315",
179 | "status": 2,
180 | "teaType": 4,
181 | "category": "chill",
182 | "images": [
183 | {
184 | "src": "matcha_chill.png"
185 | }
186 | ],
187 | "created": 1601047285438,
188 | "currency": {
189 | "id": "USD",
190 | "format": "$"
191 | },
192 | "sizes": [
193 | "S",
194 | "M",
195 | "L"
196 | ],
197 | "name": "Matcha Chill",
198 | "price": 5.50,
199 | "description": "A delicious base of energizing matcha green tea, spiced to perfection with hints of cinnamon, nutmeg and cardamom. Sweet but not too sweet with the goodness of matcha served over ice.",
200 | "productCode": "CJ6740-002",
201 | "ratings": {
202 | "total": 34,
203 | "avg": 4.5,
204 | "reviews": []
205 | }
206 | },
207 | {
208 | "_id": "5f6e0c3040fdb952de7f9316",
209 | "status": 1,
210 | "teaType": 4,
211 | "category": "chill",
212 | "images": [
213 | {
214 | "src": "pulumipus_chill.png"
215 | }
216 | ],
217 | "created": 1601047571500,
218 | "currency": {
219 | "id": "USD",
220 | "format": "$"
221 | },
222 | "sizes": [
223 | "S",
224 | "M",
225 | "L"
226 | ],
227 | "name": "Pulumipus Chill",
228 | "price": 6.00,
229 | "description": "Our special mix of mango, pineapple, kiwi, and more. A deliciously cold drink from your favorite platypus.",
230 | "productCode": "CK7513-003",
231 | "ratings": {
232 | "total": 182,
233 | "avg": 5,
234 | "reviews": []
235 | }
236 | },
237 | {
238 | "_id": "5f6e0d3840fdb952de7f9317",
239 | "status": 1,
240 | "teaType": 4,
241 | "category": "chill",
242 | "images": [
243 | {
244 | "src": "strawberry_chill.png"
245 | }
246 | ],
247 | "created": 1601047852170,
248 | "currency": {
249 | "id": "USD",
250 | "format": "$"
251 | },
252 | "sizes": [
253 | "S",
254 | "M",
255 | "L"
256 | ],
257 | "name": "Strawberry Chill",
258 | "price": 4.5,
259 | "description": "Refreshing and crisp, this tea blends juicy strawberry, tart hibiscus, floral rosehips, and brisk peppermint all combined together for the perfect summer drink.",
260 | "productCode": "CZ5021-100",
261 | "ratings": {
262 | "total": 6,
263 | "avg": 4,
264 | "reviews": []
265 | }
266 | },
267 | {
268 | "_id": "5f6e0e8940fdb952de7f9318",
269 | "status": 1,
270 | "teaType": 4,
271 | "category": "chill",
272 | "images": [
273 | {
274 | "src": "taro_chill.png"
275 | }
276 | ],
277 | "created": 1601048173895,
278 | "currency": {
279 | "id": "USD",
280 | "format": "$"
281 | },
282 | "sizes": [
283 | "S",
284 | "M",
285 | "L"
286 | ],
287 | "name": "Taro Chill",
288 | "price": 6.00,
289 | "description": "Taro bubble tea is recognized by its color, which runs from purple-tinged brown to nearly lilac, and its coconut-like flavor. Taro is pureed and added to boba milk tea, and served over ice.",
290 | "productCode": "AT3160-020",
291 | "ratings": {
292 | "total": 11,
293 | "avg": 5,
294 | "reviews": []
295 | }
296 | }
297 | ]);
--------------------------------------------------------------------------------
/data/docker-healthcheck.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -eo pipefail
3 |
4 | host="$(hostname --ip-address || echo '127.0.0.1')"
5 |
6 | if mongo --quiet "$host/test" --eval 'quit(db.runCommand("ping").ok ? 0 : 2)'; then
7 | exit 0
8 | fi
9 |
10 | exit 1
--------------------------------------------------------------------------------
/data/init.sh:
--------------------------------------------------------------------------------
1 | mongoimport --db cart --collection products --type json --file /app/data/products.json --jsonArray --uri "mongodb://mongo:27017"
--------------------------------------------------------------------------------
/data/products.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "_id": {
4 | "$oid": "5f6d025008a1b6f0e5636bc3"
5 | },
6 | "status": 1,
7 | "teaType": 2,
8 | "category": "boba",
9 | "images": [
10 | {
11 | "src": "classic_boba.png"
12 | }
13 | ],
14 | "created": 1600979464563,
15 | "currency": {
16 | "id": "USD",
17 | "format": "$"
18 | },
19 | "sizes": [
20 | "M",
21 | "L"
22 | ],
23 | "name": "Classic Milk Tea",
24 | "price": 5.00,
25 | "description": "Black tea is shaken with frothy milk, crushed ice, and a few generous handfuls of marble-sized, caramelized tapioca pearls.",
26 | "productCode": "852542-105",
27 | "ratings": {
28 | "total": 63,
29 | "avg": 5,
30 | "reviews": []
31 | }
32 | },
33 | {
34 | "_id": {
35 | "$oid": "5f6d0ad908a1b6f0e5636bc4"
36 | },
37 | "status": 1,
38 | "teaType": 2,
39 | "category": "boba",
40 | "images": [
41 | {
42 | "src": "ginger_boba.png"
43 | }
44 | ],
45 | "created": 1600981421087,
46 | "currency": {
47 | "id": "USD",
48 | "format": "$"
49 | },
50 | "sizes": [
51 | "M",
52 | "L"
53 | ],
54 | "name": "Ginger Milk Tea",
55 | "price": 5.00,
56 | "description": "A creamy ice cold drink with a strong taste of ginger, added by a cool and refreshing tea flavor.",
57 | "productCode": "CT2816-100",
58 | "ratings": {
59 | "total": 0,
60 | "avg": 0,
61 | "reviews": []
62 | }
63 | },
64 | {
65 | "_id": {
66 | "$oid": "5f6d734f19ce90070b4837ce"
67 | },
68 | "status": 2,
69 | "teaType": 2,
70 | "category": "boba",
71 | "images": [
72 | {
73 | "src": "taro_boba.png"
74 | }
75 | ],
76 | "created": 1601008415022,
77 | "currency": {
78 | "id": "USD",
79 | "format": "$"
80 | },
81 | "sizes": [
82 | "M",
83 | "L"
84 | ],
85 | "name": "Taro Milk Tea",
86 | "price": 6.00,
87 | "description": "Taro bubble tea is recognized by its color, which runs from purple-tinged brown to nearly lilac, and its coconut-like flavor. Taro (a root vegetable similar to a sweet potato) is pureed and added to boba milk tea, where it acts as a thickener and flavoring.",
88 | "productCode": "CI9924-100",
89 | "ratings": {
90 | "total": 4,
91 | "avg": 5,
92 | "reviews": []
93 | }
94 | },
95 | {
96 | "_id": {
97 | "$oid": "5f6d74c519ce90070b4837cf"
98 | },
99 | "status": 1,
100 | "teaType": 2,
101 | "category": "boba",
102 | "images": [
103 | {
104 | "src": "thai_boba.png"
105 | }
106 | ],
107 | "created": 1601008816970,
108 | "currency": {
109 | "id": "USD",
110 | "format": "$"
111 | },
112 | "sizes": [
113 | "M",
114 | "L"
115 | ],
116 | "name": "Thai Milk Tea",
117 | "price": 5.00,
118 | "description": "Thai Tea is made from strongly-brewed black tea, spiced with star anise, crushed tamarind, and cardamom. It is then sweetened sugar and sweetened condensed milk.",
119 | "productCode": "AT8241-005",
120 | "ratings": {
121 | "total": 34,
122 | "avg": 4.5,
123 | "reviews": []
124 | }
125 | },
126 | {
127 | "_id": {
128 | "$oid": "5f6d761c19ce90070b4837d0"
129 | },
130 | "status": 1,
131 | "teaType": 4,
132 | "category": "chill",
133 | "images": [
134 | {
135 | "src": "mango_chill.png"
136 | }
137 | ],
138 | "created": 1601009129502,
139 | "currency": {
140 | "id": "USD",
141 | "format": "$"
142 | },
143 | "sizes": [
144 | "S",
145 | "M",
146 | "L"
147 | ],
148 | "name": "Mango Chill",
149 | "price": 5.00,
150 | "description": "A juicy, tart-sweet blend of mango, ginger & floral notes on ice.",
151 | "productCode": "CT4063-400",
152 | "ratings": {
153 | "total": 34,
154 | "avg": 4.5,
155 | "reviews": []
156 | }
157 | },
158 | {
159 | "_id": {
160 | "$oid": "5f6e0a4340fdb952de7f9314"
161 | },
162 | "status": 2,
163 | "teaType": 3,
164 | "category": "latte",
165 | "images": [
166 | {
167 | "src": "matcha_latte.png"
168 | }
169 | ],
170 | "created": 1601009129502,
171 | "currency": {
172 | "id": "USD",
173 | "format": "$"
174 | },
175 | "sizes": [
176 | "S",
177 | "M"
178 | ],
179 | "name": "Matcha Latte",
180 | "price": 6.00,
181 | "description": "A delicious base of energizing matcha green tea, spiced to perfection with hints of cinnamon, nutmeg and cardamom. Sweet but not too sweet with the goodness of matcha.",
182 | "productCode": "BQ9646-001",
183 | "ratings": {
184 | "total": 102,
185 | "avg": 4.5,
186 | "reviews": []
187 | }
188 | },
189 | {
190 | "_id": {
191 | "$oid": "5f6e0b6440fdb952de7f9315"
192 | },
193 | "status": 2,
194 | "teaType": 4,
195 | "category": "chill",
196 | "images": [
197 | {
198 | "src": "matcha_chill.png"
199 | }
200 | ],
201 | "created": 1601047285438,
202 | "currency": {
203 | "id": "USD",
204 | "format": "$"
205 | },
206 | "sizes": [
207 | "S",
208 | "M",
209 | "L"
210 | ],
211 | "name": "Matcha Chill",
212 | "price": 5.50,
213 | "description": "A delicious base of energizing matcha green tea, spiced to perfection with hints of cinnamon, nutmeg and cardamom. Sweet but not too sweet with the goodness of matcha served over ice.",
214 | "productCode": "CJ6740-002",
215 | "ratings": {
216 | "total": 34,
217 | "avg": 4.5,
218 | "reviews": []
219 | }
220 | },
221 | {
222 | "_id": {
223 | "$oid": "5f6e0c3040fdb952de7f9316"
224 | },
225 | "status": 1,
226 | "teaType": 4,
227 | "category": "chill",
228 | "images": [
229 | {
230 | "src": "pulumipus_chill.png"
231 | }
232 | ],
233 | "created": 1601047571500,
234 | "currency": {
235 | "id": "USD",
236 | "format": "$"
237 | },
238 | "sizes": [
239 | "S",
240 | "M",
241 | "L"
242 | ],
243 | "name": "Pulumipus Chill",
244 | "price": 6.00,
245 | "description": "Our special mix of mango, pineapple, kiwi, and more. A deliciously cold drink from your favorite platypus.",
246 | "productCode": "CK7513-003",
247 | "ratings": {
248 | "total": 182,
249 | "avg": 5,
250 | "reviews": []
251 | }
252 | },
253 | {
254 | "_id": {
255 | "$oid": "5f6e0d3840fdb952de7f9317"
256 | },
257 | "status": 1,
258 | "teaType": 4,
259 | "category": "chill",
260 | "images": [
261 | {
262 | "src": "strawberry_chill.png"
263 | }
264 | ],
265 | "created": 1601047852170,
266 | "currency": {
267 | "id": "USD",
268 | "format": "$"
269 | },
270 | "sizes": [
271 | "S",
272 | "M",
273 | "L"
274 | ],
275 | "name": "Strawberry Chill",
276 | "price": 4.5,
277 | "description": "Refreshing and crisp, this tea blends juicy strawberry, tart hibiscus, floral rosehips, and brisk peppermint all combined together for the perfect summer drink.",
278 | "productCode": "CZ5021-100",
279 | "ratings": {
280 | "total": 6,
281 | "avg": 4,
282 | "reviews": []
283 | }
284 | },
285 | {
286 | "_id": {
287 | "$oid": "5f6e0e8940fdb952de7f9318"
288 | },
289 | "status": 1,
290 | "teaType": 4,
291 | "category": "chill",
292 | "images": [
293 | {
294 | "src": "taro_chill.png"
295 | }
296 | ],
297 | "created": 1601048173895,
298 | "currency": {
299 | "id": "USD",
300 | "format": "$"
301 | },
302 | "sizes": [
303 | "S",
304 | "M",
305 | "L"
306 | ],
307 | "name": "Taro Chill",
308 | "price": 6.00,
309 | "description": "Taro bubble tea is recognized by its color, which runs from purple-tinged brown to nearly lilac, and its coconut-like flavor. Taro is pureed and added to boba milk tea, and served over ice.",
310 | "productCode": "AT3160-020",
311 | "ratings": {
312 | "total": 11,
313 | "avg": 5,
314 | "reviews": []
315 | }
316 | }
317 | ]
318 |
--------------------------------------------------------------------------------
/frontend/.dockerignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
--------------------------------------------------------------------------------
/frontend/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:14
2 |
3 | # Create app directory
4 | WORKDIR /usr/src/app
5 |
6 | COPY ./client/package*.json ./
7 |
8 | RUN npm install
9 | COPY ./client .
10 | RUN npm build
11 | EXPOSE 3001
12 |
13 | CMD [ "npm", "start" ]
14 |
--------------------------------------------------------------------------------
/frontend/client/README.md:
--------------------------------------------------------------------------------
1 | # Shopping Cart Client
2 |
3 | > It contains the react front end for the application bootstrapped with Create React APP
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.
12 | Open [http://localhost:3001](http://localhost:3001) to view it in the browser.
13 |
14 | The page will reload if you make edits.
15 | You will also see any lint errors in the console.
16 |
17 | ### `npm run build`
18 |
19 | Builds the app for production to the `build` folder.
20 | It correctly bundles React in production mode and optimizes the build for the best performance.
21 |
--------------------------------------------------------------------------------
/frontend/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.5.0",
8 | "@testing-library/user-event": "^7.2.1",
9 | "http-proxy-middleware": "^2.0.1",
10 | "noty": "^3.2.0-beta",
11 | "react": "^17.0.2",
12 | "react-dom": "^17.0.2",
13 | "react-multi-carousel": "^2.6.3",
14 | "react-router-dom": "^5.2.0",
15 | "react-scripts": "^4.0.0",
16 | "shortid": "^2.2.16"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test",
22 | "eject": "react-scripts eject"
23 | },
24 | "eslintConfig": {
25 | "extends": "react-app"
26 | },
27 | "browserslist": {
28 | "production": [
29 | "defaults",
30 | "not IE 11",
31 | "not dead",
32 | "maintained node versions"
33 | ],
34 | "development": [
35 | "last 1 chrome version",
36 | "last 1 firefox version",
37 | "last 1 safari version"
38 | ]
39 | },
40 | "description": "> It contains the react frontend for the application bootstrapped with Create React APP",
41 | "main": "/usr/src/app/public/src/index.js",
42 | "author": "",
43 | "license": "ISC"
44 | }
45 |
--------------------------------------------------------------------------------
/frontend/client/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/public/favicon.ico
--------------------------------------------------------------------------------
/frontend/client/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/public/favicon.png
--------------------------------------------------------------------------------
/frontend/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Pulumipus Boba Tea
14 |
15 |
16 |
17 | You need to enable JavaScript to run this app.
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/frontend/client/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/public/logo192.png
--------------------------------------------------------------------------------
/frontend/client/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/public/logo512.png
--------------------------------------------------------------------------------
/frontend/client/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/frontend/client/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/frontend/client/src/App.jsx:
--------------------------------------------------------------------------------
1 | import React, { lazy, Suspense } from 'react';
2 | import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
3 | import { CartProvider } from './context/cartContext';
4 | import Header from './components/header/Header';
5 | import { Loader } from './components/loader/Loader';
6 |
7 | const Cart = lazy(() => import('./views/cart/Cart'));
8 | const Home = lazy(() => import('./views/homepage/Home'));
9 | const ViewProduct = lazy(() => import('./views/product/ViewProduct'));
10 |
11 | function App() {
12 | return (
13 |
14 |
15 | <>
16 |
17 | }>
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | >
26 |
27 |
28 | );
29 | }
30 |
31 | export default App;
32 |
--------------------------------------------------------------------------------
/frontend/client/src/components/cartProduct/CartProduct.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import PropTypes from 'prop-types';
3 | import { useContext } from 'react';
4 | import { CartContext } from '../../context/cartContext';
5 | import style from '../../views/cart/cart.module.css';
6 |
7 | function importAllImages(r) {
8 | let images = {};
9 | r.keys().map((item, index) => { images[item.replace('../../', '')] = r(item); });
10 | return images;
11 | }
12 |
13 | const images = importAllImages(require.context('../../img', false, /\.png$/));
14 |
15 | const CartProduct = ({ cartItem }) => {
16 | const { removeProduct, qtyUpdate } = useContext(CartContext);
17 | const [qty, setQty] = useState(0);
18 |
19 | useEffect(() => {
20 | if (cartItem) {
21 | setQty(cartItem.qty);
22 | }
23 | }, [cartItem]);
24 |
25 | function handleRemoveProduct() {
26 | removeProduct(cartItem.id);
27 | }
28 |
29 | function increment() {
30 | setQty(qty + 1);
31 | qtyUpdate({ ...cartItem, qty: qty + 1 });
32 | }
33 |
34 | function decrement() {
35 | if (qty === 1) return false;
36 | setQty(qty - 1);
37 | qtyUpdate({ ...cartItem, qty: qty - 1 });
38 | }
39 |
40 | const getCustomerType = (code) => {
41 | let cust = '';
42 | switch (code) {
43 | case 1:
44 | cust = "Tasty";
45 | break;
46 | case 2:
47 | cust = "Yummy";
48 | break;
49 | case 3:
50 | cust = "Delightful";
51 | break;
52 | case 5:
53 | cust = "Scrumptious";
54 | break;
55 | default:
56 | cust = "Delicious";
57 | break;
58 | }
59 | return cust;
60 | };
61 |
62 | return (
63 |
64 |
65 |
66 |
67 | close
68 |
69 |
70 |
71 |
75 |
76 |
77 |
{cartItem.product.name}
78 |
79 | {getCustomerType(cartItem.product.teaType)}{' '}
80 | {cartItem.product.category}
81 |
82 |
83 |
84 | {/*
Quantity
*/}
85 |
86 |
87 | remove
88 |
89 |
{qty}
90 |
91 | add
92 |
93 |
94 |
95 | {cartItem.product.currency.format} {cartItem.allCost.toFixed(2)}
96 |
97 |
98 |
99 | );
100 | };
101 |
102 | CartProduct.propTypes = {
103 | id: PropTypes.string,
104 | allCost: PropTypes.number,
105 | date: PropTypes.number,
106 | qty: PropTypes.number,
107 | product: PropTypes.shape({
108 | image: PropTypes.string,
109 | created: PropTypes.number,
110 | currency: PropTypes.object,
111 | sizes: PropTypes.array,
112 | name: PropTypes.string,
113 | price: PropTypes.number,
114 | description: PropTypes.string,
115 | _id: PropTypes.string,
116 | }),
117 | };
118 |
119 | export default CartProduct;
120 |
--------------------------------------------------------------------------------
/frontend/client/src/components/filters/Checkbox.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import './checkbox.css';
4 |
5 | const Checkbox = ({ label, name, id, ...props }) => {
6 | return (
7 |
8 |
9 | {label}
10 |
11 | );
12 | };
13 |
14 | Checkbox.propTypes = {
15 | label: PropTypes.string.isRequired,
16 | name: PropTypes.string.isRequired,
17 | id: PropTypes.string.isRequired,
18 | };
19 |
20 | export default Checkbox;
21 |
--------------------------------------------------------------------------------
/frontend/client/src/components/filters/Sizes.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import Checkbox from './Checkbox';
3 | import style from '../products/products.module.css';
4 |
5 | export const Sizes = ({ products, filterProducts }) => {
6 | const [sizes, setSizes] = useState([]);
7 | const [selectedSizes, setSelectedSizes] = useState([]);
8 |
9 | useEffect(() => {
10 | const arr = [];
11 | products.forEach((p) => {
12 | arr.push(...p.sizes);
13 | });
14 | const sizeSet = new Set(arr);
15 | const sizesArr = [...sizeSet];
16 | setSizes(sizesArr);
17 | }, [products]);
18 |
19 | useEffect(() => {
20 | filterProducts(selectedSizes);
21 | }, [selectedSizes, filterProducts]);
22 |
23 | function handleOnCheck(e) {
24 | const isChecked = e.target.checked;
25 | const size = e.target.name;
26 | if (isChecked) {
27 | setSelectedSizes((sizes) => [...sizes, size]);
28 | } else {
29 | const selectedFiltered = selectedSizes.filter((ss) => size !== ss);
30 | setSelectedSizes(selectedFiltered);
31 | }
32 | }
33 |
34 | return (
35 |
36 | {sizes.length &&
37 | sizes.map((s) => (
38 |
39 |
40 |
41 | ))}
42 |
43 | );
44 | };
45 |
--------------------------------------------------------------------------------
/frontend/client/src/components/filters/checkbox.css:
--------------------------------------------------------------------------------
1 | .cb {
2 | margin: 10px 0;
3 | }
4 |
5 | /* Base for label styling */
6 | [type="checkbox"]:not(:checked),
7 | [type="checkbox"]:checked {
8 | position: absolute;
9 | left: -9999px;
10 | }
11 |
12 | [type="checkbox"]:not(:checked)+label,
13 | [type="checkbox"]:checked+label {
14 | position: relative;
15 | padding-left: 1.95em;
16 | cursor: pointer;
17 | }
18 |
19 | /* checkbox aspect */
20 | [type="checkbox"]:not(:checked)+label:before,
21 | [type="checkbox"]:checked+label:before {
22 | content: '';
23 | position: absolute;
24 | left: 0;
25 | top: 0;
26 | width: 1.25em;
27 | height: 1.25em;
28 | border: 2px solid #ccc;
29 | background: #fff;
30 | border-radius: 4px;
31 | box-shadow: inset 0 1px 3px rgba(0, 0, 0, .1);
32 | }
33 |
34 | /* checked mark aspect */
35 | [type="checkbox"]:not(:checked)+label:after,
36 | [type="checkbox"]:checked+label:after {
37 | content: '\2713\0020';
38 | position: absolute;
39 | top: .15em;
40 | left: .22em;
41 | font-size: 1.3em;
42 | line-height: 0.8;
43 | color: #ff7800;
44 | transition: all .2s;
45 | }
46 |
47 | /* checked mark aspect changes */
48 | [type="checkbox"]:not(:checked)+label:after {
49 | opacity: 0;
50 | transform: scale(0);
51 | }
52 |
53 | [type="checkbox"]:checked+label:after {
54 | opacity: 1;
55 | transform: scale(1);
56 | }
57 |
58 | /* disabled checkbox */
59 | [type="checkbox"]:disabled:not(:checked)+label:before,
60 | [type="checkbox"]:disabled:checked+label:before {
61 | box-shadow: none;
62 | border-color: #bbb;
63 | background-color: #ddd;
64 | }
65 |
66 | [type="checkbox"]:disabled:checked+label:after {
67 | color: #999;
68 | }
69 |
70 | [type="checkbox"]:disabled+label {
71 | color: #aaa;
72 | }
73 |
74 | /* accessibility */
75 | [type="checkbox"]:checked:focus+label:before,
76 | [type="checkbox"]:not(:checked):focus+label:before {
77 | border: 2px solid #555;
78 | }
79 |
80 | /* hover style just for information */
81 | label:hover:before {
82 | border: 2px solid #888 !important;
83 | }
--------------------------------------------------------------------------------
/frontend/client/src/components/footer/Footer.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const Footer = () => {
4 | return (
5 |
6 | Pulumipus
7 | ©
8 | {new Date().getFullYear()}.
9 |
10 | );
11 | };
12 |
13 | export default Footer;
14 |
--------------------------------------------------------------------------------
/frontend/client/src/components/header/Header.jsx:
--------------------------------------------------------------------------------
1 | import React, {useContext} from 'react';
2 | import {NavLink} from 'react-router-dom';
3 | import {CartContext} from '../../context/cartContext';
4 | import style from './header.module.css';
5 | import logo from '../../img/science.png'
6 |
7 | const Header = () => {
8 | const {cartSize} = useContext(CartContext);
9 |
10 | return (
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 | Pulumipus Tea Shop
22 |
23 |
24 |
25 |
26 |
27 | {cartSize || shopping_cart }
28 |
29 |
30 |
31 |
32 | );
33 | };
34 |
35 | export default Header;
36 |
--------------------------------------------------------------------------------
/frontend/client/src/components/header/StoreHeader.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import style from './header.module.css';
3 |
4 | const TeaMenus = () => {
5 | const teaTypes = [
6 | {
7 | id: 1,
8 | title: 'Boba Tea',
9 | active: false,
10 | },
11 | ];
12 |
13 | return (
14 |
15 |
16 | {teaTypes.map((type) => (
17 |
18 |
23 | {type.title}
24 |
25 |
26 | ))}
27 |
28 |
29 |
30 | );
31 | };
32 |
33 | const TabsController = ({ customerTypeChange: teaTypeChange }) => {
34 | const [active, setActive] = useState(1);
35 |
36 | const changeTeaType = (e) => {
37 | setActive(e);
38 | teaTypeChange(e);
39 | };
40 |
41 | return (
42 |
43 |
44 |
45 | changeTeaType(1)}
48 | >
49 | All
50 |
51 | changeTeaType(2)}
54 | >
55 | Boba
56 |
57 | changeTeaType(3)}
60 | >
61 | Latte
62 |
63 | changeTeaType(4)}
66 | >
67 | Chills
68 |
69 |
70 |
71 |
72 | );
73 | };
74 |
75 | const StoreHeader = ({ customer, customerChange }) => {
76 | return (
77 | <>
78 |
79 |
83 | >
84 | );
85 | };
86 |
87 | export default StoreHeader;
88 |
--------------------------------------------------------------------------------
/frontend/client/src/components/header/header.module.css:
--------------------------------------------------------------------------------
1 | .container {
2 | padding-left: 50px;
3 | padding-right: 50px;
4 | }
5 |
6 | .container_centered {
7 | composes: container;
8 | text-align: center;
9 | }
10 |
11 | .header {
12 | background: var(--header-background);
13 | padding: 1rem 0;
14 | position: sticky;
15 | top: 0;
16 | z-index: 2;
17 | }
18 |
19 | .brand {
20 | align-items: center;
21 | display: flex;
22 | }
23 |
24 | .logo_box {
25 | align-items: center;
26 | display: flex;
27 | }
28 |
29 | .text_logo {
30 | color: #555;
31 | font-family: var(--font-family-2);
32 | font-size: 25px;
33 | font-weight: 500;
34 | letter-spacing: .15ch;
35 | text-decoration: none;
36 | }
37 |
38 | .logo {
39 | height: 140px;
40 | max-height: 64px;
41 | vertical-align: middle;
42 | }
43 |
44 | .header_nav {
45 | display: flex;
46 | justify-content: space-between;
47 | }
48 |
49 | .nav_link {
50 | text-decoration: none;
51 | }
52 |
53 | .cart {
54 | align-items: center;
55 | background: #eee;
56 | border-radius: 50%;
57 | color: #777;
58 | cursor: pointer;
59 | display: flex;
60 | font-size: 14px;
61 | font-weight: 600;
62 | height: 50px;
63 | justify-content: center;
64 | text-decoration: none;
65 | transition: background .2s ease-in;
66 | user-select: none;
67 | width: 50px;
68 | }
69 |
70 | .cart:hover {
71 | background: #dcdada
72 | }
73 |
74 | .store_menu_wrapper {
75 | background-color: #f7f7f7;
76 | display: grid;
77 | grid-template-columns: calc(100% - 200px) 200px;
78 | height: 105px;
79 | margin: 10px 0;
80 | overflow: hidden;
81 | position: relative;
82 | }
83 |
84 | .fader {
85 | background: linear-gradient(90deg, rgba(247, 247, 247, 0), rgba(247, 247, 247, 0.65), rgba(247, 247, 247, 0.9), rgba(247, 247, 247, 1));
86 | bottom: 0;
87 | content: '';
88 | right: 0;
89 | pointer-events: none;
90 | position: absolute;
91 | top: 0;
92 | width: 200px;
93 | }
94 |
95 | .store_menu {
96 | display: flex;
97 | gap: 6vw;
98 | opacity: 0.8;
99 | overflow-x: auto;
100 | overflow-y: hidden;
101 | scrollbar-width: none;
102 | white-space: nowrap;
103 | }
104 |
105 | .store_menu::-webkit-scrollbar {
106 | width: 0 !important
107 | }
108 |
109 | .store_menu {
110 | grid-column: 1/3;
111 | overflow: -moz-scrollbars-none;
112 | -ms-overflow-style: none;
113 | }
114 |
115 | .store_menu_item {
116 | align-items: center;
117 | display: inline-flex;
118 | height: 96px;
119 | }
120 |
121 | .store_menu_item:first-of-type {
122 | padding-left: 50px;
123 | }
124 |
125 | .store_menu_item:last-of-type {
126 | padding-right: 180px;
127 | }
128 |
129 | .store_menu_title {
130 | font-size: 2.5rem;
131 | line-height: 1;
132 | margin: 0;
133 | }
134 |
135 | .tabs_controller {
136 | background: var(--background);
137 | border: 1px solid;
138 | border-image: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.1), transparent) 1;
139 | padding: 1rem 0;
140 | position: sticky;
141 | top: 25px;
142 | z-index: 1;
143 | }
144 |
145 | .tab_menus {
146 | display: inline-flex;
147 | gap: 40px;
148 | list-style-type: none;
149 | margin: 0;
150 | padding: 0;
151 | }
152 |
153 | .tab_menus li {
154 | color: #444;
155 | cursor: pointer;
156 | font-size: 14px;
157 | font-weight: 400;
158 | letter-spacing: .1ch;
159 | opacity: 0.45;
160 | transition: all .2s ease-in;
161 | }
162 |
163 | .tab_menus li:hover {
164 | opacity: 0.6;
165 | }
166 |
167 | .tab_menus .active_tab {
168 | font-weight: 600;
169 | opacity: .8;
170 | }
171 |
172 | @media screen and (max-width:600px) {
173 |
174 | .container {
175 | padding-left: 20px;
176 | padding-right: 20px;
177 | }
178 |
179 | .header {
180 | padding: .5rem 0;
181 | }
182 |
183 | .store_menu_wrapper {
184 | height: 64px;
185 | }
186 |
187 | .store_menu_item:first-of-type {
188 | padding-left: 20px;
189 | }
190 |
191 | .store_menu_item:last-of-type {
192 | padding-right: 80px;
193 | }
194 |
195 | .fader {
196 | background: linear-gradient(90deg, rgba(247, 247, 247, 0), rgba(247, 247, 247, 0.65), rgba(247, 247, 247, 0.95), rgba(247, 247, 247, 1));
197 | width: 100px;
198 | }
199 |
200 | .store_menu_item {
201 | height: 64px;
202 | }
203 |
204 | .store_menu_title {
205 | font-size: 2.5rem;
206 | }
207 |
208 | .tabs_controller {
209 | padding: .5rem 0;
210 | }
211 | }
--------------------------------------------------------------------------------
/frontend/client/src/components/loader/Loader.css:
--------------------------------------------------------------------------------
1 | .loading-container {
2 | position: absolute;
3 | top: 50%;
4 | left: 50%;
5 | transform: translate(-50%, -25%);
6 | }
7 |
8 | .lds-facebook {
9 | display: inline-block;
10 | position: relative;
11 | width: 80px;
12 | height: 80px;
13 | }
14 |
15 | .lds-facebook div {
16 | display: inline-block;
17 | position: absolute;
18 | left: 8px;
19 | width: 16px;
20 | background: #333;
21 | animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
22 | }
23 |
24 | .lds-facebook div:nth-child(1) {
25 | left: 8px;
26 | animation-delay: -0.24s;
27 | }
28 |
29 | .lds-facebook div:nth-child(2) {
30 | left: 32px;
31 | animation-delay: -0.12s;
32 | }
33 |
34 | .lds-facebook div:nth-child(3) {
35 | left: 56px;
36 | animation-delay: 0;
37 | }
38 |
39 | @keyframes lds-facebook {
40 | 0% {
41 | top: 8px;
42 | height: 64px;
43 | }
44 |
45 | 50%,
46 | 100% {
47 | top: 24px;
48 | height: 32px;
49 | }
50 | }
--------------------------------------------------------------------------------
/frontend/client/src/components/loader/Loader.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import './Loader.css';
3 |
4 | export const Loader = () => {
5 | return (
6 |
13 | );
14 | };
15 |
--------------------------------------------------------------------------------
/frontend/client/src/components/products/Product.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { useHistory } from 'react-router-dom';
3 | import PropTypes from 'prop-types';
4 | import style from '../products/products.module.css';
5 |
6 | function importAllImages(r) {
7 | let images = {};
8 | r.keys().map((item, index) => { images[item.replace('../../', '')] = r(item); });
9 | return images;
10 | }
11 |
12 | const images = importAllImages(require.context('../../img', false, /\.png$/));
13 |
14 | console.log(images['./classic_boba.png'].default)
15 |
16 | export const Product = ({ product }) => {
17 | const history = useHistory();
18 |
19 | function showProductDetails(id) {
20 | history.push(
21 | `/product/${product.name.split(' ').join('-')}-${product._id}`
22 | );
23 | }
24 |
25 | function getItemKlass(custId) {
26 | let klass = 'prod all_item';
27 | switch (custId) {
28 | case 1:
29 | klass += '';
30 | break;
31 | case 2:
32 | klass += ' boba_item';
33 | break;
34 | case 3:
35 | klass += ' latte_item';
36 | break;
37 | case 4:
38 | klass += ' chills_item';
39 | break;
40 | default:
41 | klass = '';
42 | break;
43 | }
44 | return klass;
45 | }
46 |
47 | return (
48 | showProductDetails(product)}
52 | >
53 |
54 |
55 |
56 |
57 | {product.status === 0 && (
58 |
59 | Sold Out
60 |
61 | )}
62 | {product.status === 1 && (
63 | NEW
64 | )}
65 | {product.status === 3 && (
66 |
67 | Coming Soon
68 |
69 | )}
70 |
71 |
72 |
73 |
{product.name}
74 |
75 | {' '}
76 | {product.currency.format} {product.price.toFixed(2)}
77 |
78 |
79 |
80 |
81 | );
82 | };
83 |
84 | Product.propTypes = {
85 | product: PropTypes.shape({
86 | image: PropTypes.string,
87 | created: PropTypes.number,
88 | currency: PropTypes.object,
89 | sizes: PropTypes.array,
90 | name: PropTypes.string,
91 | price: PropTypes.number,
92 | description: PropTypes.string,
93 | _id: PropTypes.string,
94 | }).isRequired,
95 | };
96 |
--------------------------------------------------------------------------------
/frontend/client/src/components/products/ProductsGrid.jsx:
--------------------------------------------------------------------------------
1 | import React, {useState, useEffect, useCallback} from 'react';
2 | import {request} from '../../utils/fetch';
3 | import {Product} from './Product';
4 | import {Loader} from '../loader/Loader';
5 | import {Sizes} from '../filters/Sizes';
6 | import style from './products.module.css';
7 |
8 | const ListController = ({
9 | sortOrderChange,
10 | products,
11 | filterChange,
12 | viewChange,
13 | }) => {
14 | const [compactView, setCompactView] = useState(true);
15 | const [sizerShown, setSizerShown] = useState(false);
16 | const [sortVal, setSortVal] = useState('0');
17 |
18 | const selectOptions = [
19 | {text: 'Order By', value: 0},
20 | {text: 'High to Low', value: 1},
21 | {text: 'Low to High', value: 2},
22 | ];
23 |
24 | function sort(order) {
25 | setSortVal(order);
26 | sortOrderChange(order);
27 | }
28 |
29 | function clearFilters() {
30 | filterChange([]);
31 | setSizerShown(false);
32 | }
33 |
34 | function changeView(compact) {
35 | setCompactView(compact);
36 | viewChange(compact ? 'compact' : 'cozy');
37 | }
38 |
39 | return (
40 |
41 |
42 | changeView(false)}
47 | >
48 | view_module
49 |
50 | changeView(true)}
54 | >
55 | view_comfy
56 |
57 |
58 |
59 | Sort:
60 | sort(e.target.value)}>
61 | {selectOptions.map((opt, i) => (
62 |
63 | {opt.text}
64 |
65 | ))}
66 |
67 | unfold_more
68 |
69 |
setSizerShown(!sizerShown)}
72 | >
73 | filter_alt
74 | Sizes
75 |
76 | {sizerShown && (
77 |
78 |
79 |
Select Sizes
80 | clearFilters()}>
81 | Clear
82 |
83 |
84 |
85 |
86 | )}
87 |
88 | );
89 | };
90 |
91 | const ProductsGrid = ({customer}) => {
92 | const [products, setProducts] = useState(null);
93 | const [gridKlass, setGridKlass] = useState('all_items');
94 | const [compactView, setCompactView] = useState(true);
95 | const [sortBy, setSortBy] = useState('created');
96 | const [isLoading, setIsLoading] = useState(true);
97 |
98 | useEffect(() => {
99 | const url = `products?sort=${sortBy}`;
100 | request(url)
101 | .then((res) => {
102 | setProducts(res.data.products);
103 | setIsLoading(false);
104 | })
105 | .catch((err) => {
106 | setProducts([]);
107 | setIsLoading(false);
108 | });
109 | }, [sortBy]);
110 |
111 | useEffect(() => {
112 | setCustomKlass(customer);
113 | }, [customer]);
114 |
115 | function sortProducts(order) {
116 | switch (order) {
117 | case '1':
118 | setSortBy('-price');
119 | break;
120 | case '2':
121 | setSortBy('price');
122 | break;
123 | case '0':
124 | setSortBy('created');
125 | break;
126 | default:
127 | break;
128 | }
129 | }
130 |
131 | function changeGridView(view) {
132 | setCompactView(view === 'compact' ? true : false);
133 | }
134 |
135 | function setCustomKlass(custId) {
136 | let klass = 'all';
137 | switch (custId) {
138 | case 1:
139 | klass = 'all_items';
140 | break;
141 | case 2:
142 | klass = 'boba_items';
143 | break;
144 | case 3:
145 | klass = 'latte_items';
146 | break;
147 | case 4:
148 | klass = 'chills_items';
149 | break;
150 | default:
151 | klass = 'all_items';
152 | break;
153 | }
154 | setGridKlass(klass);
155 | }
156 |
157 | const handleProductsFilter = useCallback(
158 | (selectedSizes) => {
159 | const url = selectedSizes.length
160 | ? `products?sort=${sortBy}&sizes[in]=${selectedSizes.join(',')}`
161 | : `products?sort=${sortBy}`;
162 |
163 | getProducts(url, setProducts);
164 | },
165 | [sortBy]
166 | );
167 |
168 | return isLoading ? (
169 |
170 | ) : products && products.length > 0 ? (
171 |
172 |
173 |
178 | {products.map((product, i) => (
179 |
180 | ))}
181 |
182 |
183 |
189 |
190 | ) : (
191 | No products
192 | );
193 | };
194 |
195 | function getProducts(url, setProducts) {
196 | request(url)
197 | .then((res) => {
198 | setProducts(res.data.products);
199 | })
200 | .catch((err) => {
201 | setProducts([]);
202 | });
203 | }
204 |
205 | export default ProductsGrid;
206 |
--------------------------------------------------------------------------------
/frontend/client/src/components/products/products.module.css:
--------------------------------------------------------------------------------
1 | .products_container {
2 | overflow-x: hidden;
3 | }
4 |
5 | .container {
6 | padding-left: 50px;
7 | padding-right: 50px;
8 | }
9 |
10 | @media screen and (max-width:600px) {
11 | .container {
12 | padding-left: 20px;
13 | padding-right: 20px;
14 | }
15 | }
16 |
17 | .grid_view {
18 | display: grid;
19 | gap: 1rem 4rem;
20 | grid-template-columns: repeat(4, 1fr);
21 | margin: 24px 0 84px;
22 | opacity: 0.9;
23 | }
24 |
25 | .cozy {
26 | grid-template-columns: repeat(3, 1fr);
27 | }
28 |
29 | @media screen and (max-width:1199px) {
30 | .grid_view {
31 | grid-template-columns: repeat(3, 1fr);
32 | }
33 | }
34 |
35 | @media screen and (max-width:767px) {
36 | .grid_view {
37 | grid-template-columns: repeat(2, 1fr);
38 | }
39 | }
40 |
41 | @media screen and (max-width:480px) {
42 | .grid_view {
43 | grid-template-columns: 1fr;
44 | }
45 | }
46 |
47 | .product_card {
48 | border: gray 1px solid;
49 | cursor: pointer;
50 | padding: 1rem 1rem;
51 | }
52 |
53 | .card_image {
54 | height: 180px;
55 | padding: 1rem 0 0;
56 | text-align: center;
57 | }
58 |
59 | .cozy .card_image {
60 | height: 250px;
61 | }
62 |
63 | @media screen and (max-width:480px) {
64 | .card_image {
65 | height: 220px;
66 | }
67 | }
68 |
69 | .card_image img {
70 | width: 50%;
71 | height: 100%;
72 | object-fit: scale-down;
73 | }
74 |
75 | .card_status {
76 | align-items: flex-end;
77 | display: flex;
78 | height: 4rem;
79 | }
80 |
81 | .card_badge {
82 | color: #fff;
83 | font-size: 12px;
84 | font-weight: 500;
85 | margin-bottom: 4px;
86 | padding: 4px 10px;
87 | }
88 |
89 | .new_badge {
90 | background-color: green;
91 | }
92 |
93 | .soldout_badge {
94 | background-color: rgb(172, 169, 165);
95 | }
96 |
97 | .upcoming_badge {
98 | background-color: rgb(226, 116, 27);
99 | }
100 |
101 | @media screen and (max-width:480px) {
102 | .card_status {
103 | height: 5rem;
104 | }
105 | }
106 |
107 | .card_content {
108 | display: grid;
109 | grid-template-columns: 1fr 100px;
110 | padding: 1rem 0;
111 | }
112 |
113 | /* .card_info {} */
114 |
115 | .card_info h3 {
116 | color: var(--black-color);
117 | font-family: var(--font-family-2);
118 | font-size: 16px;
119 | font-weight: 400;
120 | margin: 0;
121 | padding: 0;
122 | }
123 |
124 | .card_info p {
125 | color: #888;
126 | font-size: 14px;
127 | font-weight: 500;
128 | margin: 0;
129 | padding: 0;
130 | }
131 |
132 | /* .card_meta {} */
133 |
134 | .card_colors {
135 | display: flex;
136 | justify-content: flex-end;
137 | }
138 |
139 | .card_colors span {
140 | border-radius: 50%;
141 | height: 15px;
142 | width: 15px;
143 | transition: transform .2s ease-in;
144 | }
145 |
146 | .card_colors span+span {
147 | margin-left: -3px;
148 | }
149 |
150 | .card_colors span:not(:last-of-type):hover {
151 | margin-right: 3px;
152 | z-index: 1;
153 | }
154 |
155 | .controller {
156 | align-items: stretch;
157 | background: #fff;
158 | border: solid #eee;
159 | border-width: 1px 0;
160 | bottom: 0;
161 | display: grid;
162 | grid-template-columns: 128px 1fr 240px;
163 | height: 64px;
164 | max-width: 640px;
165 | position: fixed;
166 | right: 0;
167 | user-select: none;
168 | width: 100%;
169 | z-index: 1;
170 | }
171 |
172 | @media screen and (max-width:600px) {
173 | .controller {
174 | grid-template-columns: 128px 1fr 140px;
175 | }
176 | }
177 |
178 | .view_btns {
179 | display: flex;
180 | }
181 |
182 | .view_btns button {
183 | background: #fff;
184 | /*border: none;*/
185 | border-right: 1px solid #eee;
186 | cursor: pointer;
187 | flex: 1;
188 | padding: 7px 0 0;
189 | transition: background .2s ease-in;
190 | }
191 |
192 | .active_btn {
193 | background-color: #eee !important;
194 | opacity: 0.85;
195 | pointer-events: none;
196 | }
197 |
198 | .view_btns button span {
199 | font-size: 20px;
200 | opacity: 0.6;
201 | }
202 |
203 | .view_btns button:hover {
204 | background: #f8f8f8;
205 | }
206 |
207 | .view_btns button:focus {
208 | outline: none;
209 | }
210 |
211 | .sort_btn {
212 | align-items: center;
213 | color: #888;
214 | display: flex;
215 | font-size: 14px;
216 | font-weight: 400;
217 | justify-content: center;
218 | padding: 0 10px;
219 | }
220 |
221 | .sort_btn span {
222 | padding-top: 2px;
223 | }
224 |
225 | @media screen and (max-width:600px) {
226 | .sort_btn span {
227 | display: none;
228 | }
229 | }
230 |
231 | .sort_btn select {
232 | appearance: none;
233 | -webkit-appearance: none;
234 | border: none;
235 | color: #555;
236 | cursor: pointer;
237 | font-size: 15px;
238 | height: 100%;
239 | margin: 0 10px;
240 | width: 80px;
241 | }
242 |
243 | .sort_btn select:focus {
244 | outline: none;
245 | }
246 |
247 | .filter_btn {
248 | align-items: center;
249 | background-color: #222;
250 | color: #aaa;
251 | cursor: pointer;
252 | display: flex;
253 | font-size: 15px;
254 | font-weight: 400;
255 | justify-content: center;
256 | transition: background .2s ease-in;
257 | }
258 |
259 | .filter_btn:hover {
260 | background-color: #333;
261 | }
262 |
263 | .filter_btn span+span {
264 | margin-left: 10px;
265 | }
266 |
267 | .size_box {
268 | background: white;
269 | border: solid #eee;
270 | border-width: 1px 0;
271 | bottom: 65px;
272 | display: block;
273 | left: -1px;
274 | position: absolute;
275 | right: 0;
276 | color: #888;
277 | }
278 |
279 | .box_header {
280 | align-items: center;
281 | border-bottom: 1px solid #eee;
282 | display: flex;
283 | justify-content: space-between;
284 | padding: 16px 20px;
285 | }
286 |
287 | .box_header h4 {
288 | /* border-bottom: 1px solid #eee; */
289 | margin: 0;
290 | }
291 |
292 | .box_header button {
293 | background-color: #fff;
294 | border: 1px solid #ccc;
295 | color: #666;
296 | cursor: pointer;
297 | padding: 8px 12px;
298 | transition: background .2s ease-in;
299 | }
300 |
301 | .box_header button:hover {
302 | background-color: #eee;
303 | }
304 |
305 | .sizes {
306 | display: flex;
307 | flex-wrap: wrap;
308 | margin: 0 -5px;
309 | padding: 10px 20px 20px;
310 | }
311 |
312 | .size {
313 | font-family: var(--font-family-2);
314 | font-size: 14px;
315 | font-weight: 400;
316 | margin: 5px;
317 | width: 110px;
318 | }
--------------------------------------------------------------------------------
/frontend/client/src/context/cartContext.js:
--------------------------------------------------------------------------------
1 | import React, { createContext, useReducer } from 'react';
2 | import cartReducer, { SET_PRODUCT, REMOVE_PRODUCT, QTY_UPDATE } from './cartReducer';
3 |
4 | const initialState = {
5 | cart: [],
6 | cartSize: 0,
7 | totalCost: 0,
8 | };
9 |
10 | export const CartContext = createContext(initialState);
11 |
12 | export const CartProvider = ({ children }) => {
13 | const [state, dispatch] = useReducer(cartReducer, initialState);
14 |
15 | // Actions
16 | function setProduct(product) {
17 | dispatch({ type: SET_PRODUCT, payload: product });
18 | }
19 |
20 | function removeProduct(id) {
21 | dispatch({ type: REMOVE_PRODUCT, payload: id });
22 | }
23 |
24 | function qtyUpdate(product) {
25 | dispatch({type: QTY_UPDATE, payload: product})
26 | }
27 |
28 | return (
29 |
39 | {children}
40 |
41 | );
42 | };
43 |
--------------------------------------------------------------------------------
/frontend/client/src/context/cartReducer.js:
--------------------------------------------------------------------------------
1 | import shortid from 'shortid';
2 |
3 | export const SET_PRODUCT = 'SET_PRODUCT';
4 | export const REMOVE_PRODUCT = 'REMOVE_PRODUCT';
5 | export const QTY_UPDATE = 'QTY_UPDATE';
6 |
7 | export default (state, action) => {
8 | switch (action.type) {
9 | case SET_PRODUCT:
10 | return setProduct(state, action.payload);
11 | case REMOVE_PRODUCT:
12 | return removeProduct(state, action.payload);
13 | case QTY_UPDATE:
14 | return qtyProduct(state, action.payload);
15 | default:
16 | return state;
17 | }
18 | };
19 |
20 | function setProduct(state, cartItem) {
21 | const item = state.cart.find((ci) => ci.product._id === cartItem.product._id);
22 | const index = state.cart.findIndex(
23 | (ci) => ci.product._id === cartItem.product._id
24 | );
25 | if (item) {
26 | const newItem = {
27 | ...item,
28 | qty: item.qty + 1,
29 | };
30 | newItem['allCost'] = item.product.price * newItem.qty;
31 | const cart = state.cart.filter((c, i) => i !== index);
32 | const newCart = [...cart, newItem].sort((a, b) => a.date - b.date);
33 | const totalCost = getTotal(newCart);
34 | return {
35 | ...state,
36 | totalCost,
37 | cart: newCart,
38 | cartSize: state.cartSize + 1,
39 | };
40 | }
41 | cartItem['allCost'] = cartItem.product.price;
42 | cartItem['id'] = shortid();
43 | cartItem['date'] = Date.now();
44 | const newCart = [...state.cart, cartItem];
45 | const totalCost = getTotal(newCart);
46 | return {
47 | ...state,
48 | totalCost,
49 | cart: newCart,
50 | cartSize: state.cartSize + 1,
51 | };
52 | }
53 |
54 | /**
55 | * Returns the total of the bag
56 | * @param {Array} cart all the cart items in a array
57 | * @returns number
58 | */
59 | function getTotal(cart) {
60 | return cart.map((c) => Number(c.allCost)).reduce((a, b) => a + b, 0);
61 | }
62 |
63 | function removeProduct(state, id) {
64 | const cart = state.cart.filter((item) => item.id !== id);
65 | const totalCost = getTotal(cart);
66 | const cartSize = cart.map((c) => c.qty).reduce((a, b) => a + b, 0);
67 | return { ...state, cart, totalCost, cartSize };
68 | }
69 |
70 | function qtyProduct(state, cartItem) {
71 | const item = state.cart.find((ci) => ci.product._id === cartItem.product._id);
72 | const upItem = {
73 | ...item,
74 | qty: cartItem.qty,
75 | allCost: item.product.price * cartItem.qty,
76 | };
77 | const cart = state.cart.filter((item) => item.id !== cartItem.id);
78 | const newCart = [...cart, upItem].sort((a, b) => a.date - b.date);
79 | const totalCost = getTotal(newCart);
80 | const cartSize = newCart.map((c) => c.qty).reduce((a, b) => a + b, 0);
81 | return { ...state, cart: newCart, totalCost, cartSize };
82 | }
83 |
--------------------------------------------------------------------------------
/frontend/client/src/img/classic_boba.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/classic_boba.png
--------------------------------------------------------------------------------
/frontend/client/src/img/ginger_boba.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/ginger_boba.png
--------------------------------------------------------------------------------
/frontend/client/src/img/mango_chill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/mango_chill.png
--------------------------------------------------------------------------------
/frontend/client/src/img/matcha_chill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/matcha_chill.png
--------------------------------------------------------------------------------
/frontend/client/src/img/matcha_latte.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/matcha_latte.png
--------------------------------------------------------------------------------
/frontend/client/src/img/pulumipus_chill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/pulumipus_chill.png
--------------------------------------------------------------------------------
/frontend/client/src/img/science.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/science.png
--------------------------------------------------------------------------------
/frontend/client/src/img/strawberry_chill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/strawberry_chill.png
--------------------------------------------------------------------------------
/frontend/client/src/img/taro_boba.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/taro_boba.png
--------------------------------------------------------------------------------
/frontend/client/src/img/taro_chill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/taro_chill.png
--------------------------------------------------------------------------------
/frontend/client/src/img/thai_boba.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulumi/tutorial-pulumi-fundamentals/49b2d20bada315b547d754efb5af0f69240835c2/frontend/client/src/img/thai_boba.png
--------------------------------------------------------------------------------
/frontend/client/src/index.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500&family=Prompt:wght@200;400;500;600&display=swap');
2 |
3 | :root {
4 | --background: #f7f7f7;
5 | --black-color: #222;
6 | --background-rgb: 247, 247, 247;
7 | --font-family-2: 'Oswald', sans-serif;
8 | --font-family: 'Prompt', sans-serif;
9 | --header-background: var(--background);
10 | }
11 |
12 | body {
13 | padding: 0;
14 | margin: 0;
15 | font-family: var(--font-family);
16 | -webkit-font-smoothing: antialiased;
17 | -moz-osx-font-smoothing: grayscale;
18 | overflow-x: hidden;
19 | font-weight: 200;
20 | background-color: var(--background);
21 | }
22 |
23 | body.noscroll {
24 | overflow: hidden;
25 | }
26 |
27 | body.trans {
28 | --header-background: transparent;
29 | }
30 |
31 | @media screen and (min-width:993px) {
32 | body.noscroll-web {
33 | overflow: hidden;
34 | }
35 | }
36 |
37 | .no-products {
38 | display: flex;
39 | align-items: center;
40 | justify-content: center;
41 | height: 70vh;
42 | letter-spacing: 1px;
43 | color: #888;
44 | font-weight: 500;
45 | }
46 |
47 | .footer {
48 | padding: 20px 50px;
49 | font-size: 14px;
50 | color: #888;
51 | }
52 |
53 | .footer a {
54 | color: #666;
55 | }
56 |
57 | .footer em {
58 | font-style: normal;
59 | font-weight: 400;
60 | font-size: 14px;
61 | }
62 |
63 | .react-multi-carousel-list {
64 | height: 100%;
65 | /* width: calc(100vw - 20px); */
66 | }
67 |
68 | ul.react-multi-carousel-track {
69 | height: 100%;
70 | margin: 0;
71 | padding: 0;
72 | list-style-type: none;
73 | }
74 |
75 | ul.react-multi-carousel-track li {
76 | height: 100%;
77 | }
78 |
79 | /* Grid items filtering via css classes */
80 | .all_items .prod:not(.all_item) {
81 | display: none !important;
82 | }
83 |
84 | .all_items .prod.all_item {
85 | display: block !important;
86 | }
87 |
88 | .boba_items .prod:not(.boba_item) {
89 | display: none !important;
90 | }
91 |
92 | .boba_items .prod.boba_item {
93 | display: block !important;
94 | }
95 |
96 | .latte_items .prod:not(.latte_item) {
97 | display: none !important;
98 | }
99 |
100 | .latte_items .prod.latte_item {
101 | display: block !important;
102 | }
103 |
104 | .chills_items .prod:not(.chills_item) {
105 | display: none !important;
106 | }
107 |
108 | .chills_items .prod.chills_item {
109 | display: block !important;
110 | }
--------------------------------------------------------------------------------
/frontend/client/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import * as serviceWorker from './serviceWorker';
5 | import App from './App';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want your app to work offline and load faster, you can change
15 | // unregister() to register() below. Note this comes with some pitfalls.
16 | // Learn more about service workers: https://bit.ly/CRA-PWA
17 | serviceWorker.unregister();
18 |
--------------------------------------------------------------------------------
/frontend/client/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/frontend/client/src/setupProxy.js:
--------------------------------------------------------------------------------
1 | const { createProxyMiddleware } = require('http-proxy-middleware');
2 |
3 | const host = process.env.HTTP_PROXY;
4 | const protocol = process.env.PROXY_PROTOCOL;
5 |
6 | module.exports = function(app) {
7 | app.use(
8 | '/api',
9 | createProxyMiddleware({
10 | target: `${protocol}${host}`,
11 | changeOrigin: true,
12 | })
13 | );
14 | };
--------------------------------------------------------------------------------
/frontend/client/src/utils/fetch.js:
--------------------------------------------------------------------------------
1 | export function request(endpoint, { body, ...customConfig } = {}) {
2 | const headers = { 'content-type': 'application/json' };
3 |
4 | const config = {
5 | method: body ? 'POST' : 'GET',
6 | ...customConfig,
7 | headers: {
8 | ...headers,
9 | ...customConfig.headers,
10 | }
11 | };
12 |
13 | if (body) {
14 | config.body = JSON.stringify(body);
15 | }
16 |
17 | return window
18 | .fetch(`/api/${endpoint}`, config)
19 | .then(async (response) => {
20 | const data = await response.json();
21 | if (response.ok) {
22 | return data;
23 | } else {
24 | return Promise.reject(data);
25 | }
26 | });
27 | }
28 |
--------------------------------------------------------------------------------
/frontend/client/src/views/cart/Cart.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useContext, useLayoutEffect } from 'react';
2 | import CartProduct from '../../components/cartProduct/CartProduct';
3 | import { CartContext } from '../../context/cartContext';
4 | import style from './cart.module.css';
5 |
6 | const Cart = () => {
7 | const { cart, totalCost } = useContext(CartContext);
8 | const [coShown, setCOShown] = useState(false);
9 |
10 | useLayoutEffect(() => {
11 | window.scrollTo(0, 0);
12 | document.body.classList.add('noscroll-web');
13 | document.body.classList.add('trans');
14 | }, []);
15 |
16 | function handleCheckOut() {
17 | alert('Checkout - Subtotal : $ ' + totalCost);
18 | }
19 |
20 | return (
21 |
22 |
23 | {cart.length > 0 ? (
24 |
25 | {cart.map((cartItem) => (
26 |
27 | ))}
28 |
29 | ) : (
30 |
Cart Empty
31 | )}
32 |
35 |
Order Summary
36 |
37 |
38 |
39 |
Bag Total
40 |
{totalCost.toFixed(2)}
41 |
42 |
43 |
Shipping
44 |
Free
45 |
46 |
47 |
Discount
48 |
0.00
49 |
50 |
51 |
Total
52 |
{totalCost.toFixed(2)}
53 |
54 |
55 |
56 |
57 | Place Order
58 |
59 |
60 |
61 |
62 |
63 |
setCOShown(!coShown)}
66 | className={`${style.toggle_btn} ${coShown ? style.toggle_close : ''}`}
67 | >
68 | keyboard_arrow_left
69 |
70 |
71 | );
72 | };
73 |
74 | export default Cart;
75 |
--------------------------------------------------------------------------------
/frontend/client/src/views/cart/cart.module.css:
--------------------------------------------------------------------------------
1 | .page {
2 | position: fixed;
3 | top: 0;
4 | bottom: 0;
5 | left: 0;
6 | right: 0;
7 | background: var(--background);
8 | z-index: 1;
9 | }
10 |
11 | .wrapper {
12 | display: grid;
13 | grid-template-columns: 1fr 500px;
14 | }
15 |
16 | .empty {
17 | display: flex;
18 | align-items: center;
19 | justify-content: center;
20 | height: 100vh;
21 | letter-spacing: 1px;
22 | color: #888;
23 | font-weight: 500;
24 | }
25 |
26 | .items {
27 | height: calc(100vh - 164px);
28 | overflow: auto;
29 | padding: 82px 50px;
30 | }
31 |
32 | .checkout {
33 | display: flex;
34 | flex-direction: column;
35 | background-color: #fff;
36 | height: 100vh;
37 | padding: 82px 50px;
38 | }
39 |
40 | .item:not(:last-child) {
41 | border-bottom: 1px solid #e7e7e7;
42 | }
43 |
44 | .item_wrapper {
45 | display: grid;
46 | grid-template-columns: 50px 200px auto 100px 120px;
47 | gap: 20px;
48 | align-items: center;
49 | }
50 |
51 | .item_image {
52 | width: 200px;
53 | height: 200px;
54 | }
55 |
56 | .item_image img {
57 | width: 100%;
58 | height: 100%;
59 | object-fit: contain;
60 | }
61 |
62 | .item_details h3 {
63 | margin: 0 0 10px;
64 | padding: 0;
65 | font-family: var(--font-family-2);
66 | font-weight: 400;
67 | }
68 |
69 | .item_meta {
70 | font-size: 14px;
71 | font-weight: 400;
72 | color: #777;
73 | }
74 |
75 | .item_controller {
76 | background-color: #fff;
77 | display: flex;
78 | justify-content: space-between;
79 | align-items: center;
80 | font-size: 14px;
81 | font-weight: 500;
82 | color: #777;
83 | border-radius: 30px;
84 | overflow: hidden;
85 | padding: 2px;
86 | }
87 |
88 | @media screen and (max-width: 992px) {
89 |
90 | .wrapper {
91 | grid-template-columns: 1fr;
92 | }
93 |
94 | .checkout {
95 | position: fixed;
96 | right: 0;
97 | width: 400px;
98 | transform: translateX(100%);
99 | }
100 |
101 | .checkout_shown {
102 | transform: translateX(0%);
103 | }
104 | }
105 |
106 | @media screen and (max-width: 600px) {
107 |
108 |
109 | .checkout {
110 | position: fixed;
111 | right: 0;
112 | width: calc(100% - 100px);
113 | left: 0;
114 | }
115 | }
116 |
117 | .item_controller button {
118 | background-color: transparent;
119 | border: none;
120 | height: 30px;
121 | width: 30px;
122 | padding: 0;
123 | border-radius: 30px;
124 | cursor: pointer;
125 | /* transition: background .2s ease-in; */
126 | }
127 |
128 | .item_controller button:disabled {
129 | opacity: 0.3;
130 | }
131 |
132 | /* .item_controller button:hover {
133 | background-color: var(--black-color);
134 | }
135 |
136 | .item_controller button:hover i {
137 | color: #fff;
138 | } */
139 |
140 | .item_controller button:focus {
141 | outline: none;
142 | }
143 |
144 | .item_controller button i {
145 | font-size: 16px;
146 | }
147 |
148 | .item_remove {
149 | justify-self: flex-start;
150 | }
151 |
152 | .item_remove button {
153 | height: 45px;
154 | width: 45px;
155 | border-radius: 50%;
156 | border: none;
157 | transition: background .2s ease-in;
158 | cursor: pointer;
159 | background-color: #ededed;
160 | padding-top: 3px;
161 | }
162 |
163 | .item_remove button:hover {
164 | /* background-color: #dcdada; */
165 | background-color: var(--black-color);
166 | }
167 |
168 | .item_remove button:hover span {
169 | color: #fff;
170 | }
171 |
172 | .item_remove button:focus {
173 | outline: none;
174 | }
175 |
176 | .item_remove button span {
177 | font-size: 22px;
178 | }
179 |
180 | .item_price {
181 | justify-self: flex-end;
182 | font-weight: 500;
183 | font-size: 16px;
184 | }
185 |
186 | .total_box {
187 | border-top: 1px solid #ddd;
188 | }
189 |
190 | .total_box_content {
191 | padding: 1rem 0;
192 | border-bottom: 1px solid #eee;
193 | }
194 |
195 | .total_item {
196 | display: flex;
197 | justify-content: space-between;
198 | padding: 4px 0;
199 | font-weight: 400;
200 | color: #555;
201 | }
202 |
203 | .coupon {
204 | color: salmon
205 | }
206 |
207 | .total_item:last-of-type {
208 | border-top: 1px solid #eee;
209 | padding-top: 1rem;
210 | margin-top: 10px;
211 | font-weight: 600;
212 | }
213 |
214 | .checkout_footer {
215 | padding: 10px 0;
216 | margin-top: 10px;
217 | }
218 |
219 | .checkout_footer button {
220 | background-color: var(--black-color);
221 | padding: 16px 20px;
222 | border: none;
223 | color: #fff;
224 | font-weight: 400;
225 | font-size: 17px;
226 | width: 100%;
227 | border-radius: 2px;
228 | text-transform: uppercase;
229 | transition: background .2s ease-in;
230 | cursor: pointer;
231 | }
232 |
233 | .checkout_footer button:hover {
234 | background-color: #000;
235 | }
236 |
237 | .toggle_btn {
238 | position: fixed;
239 | right: 50px;
240 | bottom: 1rem;
241 | display: flex;
242 | height: 50px;
243 | width: 50px;
244 | border-radius: 50%;
245 | background: #eee;
246 | align-items: center;
247 | cursor: pointer;
248 | justify-content: center;
249 | transition: background .2s ease-in;
250 | border: none;
251 | }
252 |
253 | .toggle_btn:hover {
254 | background: #dcdada
255 | }
256 |
257 | .toggle_btn:focus {
258 | outline: none;
259 | }
260 |
261 | .toggle_close {
262 | transform: rotate(180deg);
263 | }
264 |
265 | @media screen and (min-width:993px) {
266 | .toggle_btn {
267 | display: none;
268 | }
269 | }
270 |
271 | @media screen and (max-width:600px) {
272 | .toggle_btn {
273 | right: 20px;
274 | }
275 | }
--------------------------------------------------------------------------------
/frontend/client/src/views/homepage/Home.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import ProductsGrid from '../../components/products/ProductsGrid';
3 | import StoreHeader from '../../components/header/StoreHeader';
4 | import Footer from '../../components/footer/Footer';
5 |
6 | const Home = () => {
7 | useEffect(() => {
8 | document.body.classList.remove('noscroll-web');
9 | document.body.classList.remove('trans');
10 | }, []);
11 |
12 | const [customer, setCustomer] = useState(1);
13 |
14 | return (
15 | <>
16 | setCustomer(e)} />
17 |
18 |
19 | >
20 | );
21 | };
22 |
23 | export default Home;
24 |
--------------------------------------------------------------------------------
/frontend/client/src/views/product/ViewProduct.jsx:
--------------------------------------------------------------------------------
1 | import React, {useEffect, useState, useContext} from 'react';
2 | import {Link, useParams} from 'react-router-dom';
3 | import Carousel from 'react-multi-carousel';
4 | import 'react-multi-carousel/lib/styles.css';
5 | import {CartContext} from '../../context/cartContext';
6 | import {Loader} from '../../components/loader/Loader';
7 | import {request} from '../../utils/fetch';
8 | import Noty from 'noty';
9 | import style from './product.module.css';
10 | import './../../../node_modules/noty/lib/noty.css';
11 | import './../../../node_modules/noty/lib/themes/relax.css';
12 |
13 |
14 | function importAllImages(r) {
15 | let images = {};
16 | r.keys().map((item, index) => {
17 | images[item.replace('../../', '')] = r(item);
18 | });
19 | return images;
20 | }
21 |
22 | const images = importAllImages(require.context('../../img', false, /\.png$/));
23 |
24 | const breakPoints = {
25 | superLargeDesktop: {
26 | // the naming can be any, depends on you.
27 | breakpoint: {max: 4000, min: 1921},
28 | items: 3,
29 | },
30 | desktop: {
31 | breakpoint: {max: 1920, min: 1201},
32 | items: 2,
33 | },
34 | tablet: {
35 | breakpoint: {max: 1200, min: 0},
36 | items: 1,
37 | },
38 | };
39 |
40 | const breakPointsFS = {
41 | preview: {
42 | // the naming can be any, depends on you.
43 | breakpoint: {max: 4000, min: 0},
44 | items: 1,
45 | },
46 | };
47 |
48 | const ButtonGroup = ({next, previous, goToSlide, ...rest}) => {
49 | return (
50 |
51 | previous()}>
52 | chevron_left
53 |
54 | next()}>
55 | chevron_right
56 |
57 |
58 | );
59 | };
60 |
61 | const CarouselFullScreen = ({product}) => {
62 | return (
63 | }
72 | renderButtonGroupOutside={true}
73 | >
74 | {product.images.map((img, i) => (
75 |
76 |
77 |
78 |
79 |
80 | ))}
81 |
82 | );
83 | };
84 |
85 | const CarouselFitScreen = ({product}) => {
86 | return (
87 | }
96 | renderButtonGroupOutside={true}
97 | >
98 | {product.images.map((img, i) => (
99 |
100 |
101 |
102 |
103 |
104 | ))}
105 |
106 | );
107 | };
108 |
109 | const ViewProduct = () => {
110 | let {id} = useParams();
111 |
112 | const {setProduct} = useContext(CartContext);
113 | const [product, setProductDetails] = useState(null);
114 | const [isLoading, setIsLoading] = useState(true);
115 |
116 | useEffect(() => {
117 | document.body.classList.add('noscroll-web');
118 | document.body.classList.remove('trans');
119 | }, []);
120 |
121 | useEffect(() => {
122 | const productId = id.split('-').pop();
123 | const url = `products/${productId}`;
124 | request(url)
125 | .then((res) => {
126 | setProductDetails(res.data.product);
127 | setIsLoading(false);
128 | })
129 | .catch((err) => {
130 | setProductDetails(null);
131 | setIsLoading(false);
132 | });
133 | }, [id]);
134 |
135 | const [fullView, setFullView] = useState(false);
136 |
137 | function addToCart() {
138 | const cartProduct = {
139 | qty: 1,
140 | product,
141 | };
142 | setProduct(cartProduct);
143 | new Noty({
144 | layout: 'bottomCenter',
145 | progressBar: false,
146 | text: ` Added to cart
`,
147 | theme: 'relax',
148 | timeout: 1000
149 | }).show();
150 | }
151 |
152 | const getCustomerType = (code) => {
153 | let cust = '';
154 | switch (code) {
155 | case 2:
156 | cust = 'Boba';
157 | break;
158 | case 3:
159 | cust = 'Latte';
160 | break;
161 | case 4:
162 | cust = 'Chills';
163 | break;
164 | default:
165 | cust = 'All';
166 | break;
167 | }
168 | return cust;
169 | };
170 |
171 | return isLoading ? (
172 |
173 | ) : (
174 |
175 |
178 |
179 | {fullView ? (
180 |
181 | ) : (
182 |
183 | )}
184 |
189 |
190 | {!fullView ? (
191 | setFullView(true)}>
192 | add
193 |
194 | ) : (
195 | setFullView(false)}
199 | >
200 | close
201 |
202 | )}
203 |
204 |
205 |
206 | {!fullView && (
207 |
208 |
209 |
210 |
211 |
212 | Home
213 |
214 | Products
215 | {product.category}
216 | {getCustomerType(product.teaType)}
217 |
218 |
219 | Id: {product.productCode}
220 |
221 |
222 |
223 |
{product.name}
224 |
{product.description}
225 |
226 |
227 |
228 |
229 | {product.ratings.total} Reviews
230 |
231 |
232 | star
233 | star
234 | star
235 | star_half
236 | star_outline
237 |
238 |
239 |
240 |
241 | {product.currency.format} {product.price.toFixed(2)}
242 |
243 |
244 |
245 | Available sizes:
246 | {product.sizes.join(', ')}
247 |
248 |
249 |
250 | {' '}
251 | {product.currency.format} {product.price.toFixed(2)}
252 |
253 | Add to Cart
254 |
255 | shopping_cart
256 |
257 |
258 |
259 |
260 |
261 | )}
262 |
263 |
264 | );
265 | };
266 |
267 | export default ViewProduct;
268 |
--------------------------------------------------------------------------------
/frontend/client/src/views/product/product.module.css:
--------------------------------------------------------------------------------
1 | .view_wrapper {
2 | height: calc(100vh - 82px);
3 | position: relative;
4 | }
5 |
6 | .view_background {
7 | bottom: 0;
8 | left: 0;
9 | position: absolute;
10 | right: 0;
11 | top: 0;
12 | z-index: 1;
13 | }
14 |
15 | .view_wrapper.full_view {
16 | background: var(--background);
17 | bottom: 0;
18 | height: 100vh;
19 | left: 0;
20 | position: fixed;
21 | right: 0;
22 | top: 0;
23 | z-index: 2;
24 | }
25 |
26 | .view_foreground {
27 | display: flex;
28 | height: 50vh;
29 | left: 50%;
30 | min-height: 400px;
31 | position: absolute;
32 | right: 0;
33 | z-index: 2;
34 | }
35 |
36 | .view_controller {
37 | bottom: 0;
38 | display: flex;
39 | justify-content: flex-end;
40 | left: 0;
41 | padding: 2rem 50px;
42 | position: absolute;
43 | right: 50%;
44 | z-index: 1;
45 | /*z-index: 5;*/
46 | }
47 |
48 | .right_aligned {
49 | right: 0;
50 | }
51 |
52 | .arrow_btns {
53 | bottom: 2rem;
54 | height: 50px;
55 | left: 50px;
56 | position: absolute;
57 | width: 140px;
58 | z-index: 10;
59 | }
60 |
61 | .arrow_btns button {
62 | background: #fff;
63 | border: 1px solid #eee;
64 | cursor: pointer;
65 | height: 100%;
66 | line-height: 1;
67 | overflow: hidden;
68 | padding: 10px 0 8px;
69 | position: relative;
70 | text-align: center;
71 | user-select: none;
72 | width: 70px;
73 | }
74 |
75 | .arrow_btns button::before {
76 | background-color: var(--black-color);
77 | bottom: 0;
78 | content: '';
79 | left: 0;
80 | position: absolute;
81 | top: 0;
82 | transform: translateX(-100%);
83 | transition: all .2s ease-in;
84 | width: 100%;
85 | z-index: 0;
86 | }
87 |
88 | .arrow_btns button:first-child::before {
89 | transform: translateX(100%);
90 | }
91 |
92 | .arrow_btns button:last-child::before {
93 | transform: translateX(-100%);
94 | }
95 |
96 | .arrow_btns button+button {
97 | border-left: 1px solid #eee;
98 | }
99 |
100 | .arrow_btns button:hover::before {
101 | transform: translateX(0);
102 | }
103 |
104 | .arrow_btns button:focus {
105 | outline: none;
106 | }
107 |
108 | .arrow_btns button:disabled {
109 | opacity: 0.6;
110 | pointer-events: none;
111 | }
112 |
113 | .arrow_btns button:hover span {
114 | color: #ddd;
115 | }
116 |
117 | .arrow_btns button span {
118 | color: #555;
119 | font-size: 32px;
120 | left: 50%;
121 | opacity: 0.7;
122 | position: absolute;
123 | transform: translate(-50%, -50%);
124 | top: 50%;
125 | z-index: 1;
126 | }
127 |
128 | .arrow_btns button:hover span {
129 | opacity: 1;
130 | }
131 |
132 | .fs_btn button {
133 | background: #eee;
134 | border: none;
135 | border-radius: 50%;
136 | cursor: pointer;
137 | height: 50px;
138 | width: 50px;
139 | }
140 |
141 | .fs_btn button:hover {
142 | background-color: #dcdada;
143 | }
144 |
145 | .fs_btn button:focus {
146 | outline: none;
147 | }
148 |
149 | .dark_btn {
150 | background-color: var(--black-color) !important;
151 | }
152 |
153 | .fs_btn button span {
154 | color: #555;
155 | font-size: 24px;
156 | opacity: 0.7;
157 | }
158 |
159 | .dark_btn span {
160 | color: #ddd !important;
161 | }
162 |
163 | .product_details {
164 | background: #fff;
165 | display: flex;
166 | flex: 1;
167 | flex-direction: column;
168 | justify-content: space-between;
169 | padding: 1rem 50px 2rem;
170 | }
171 |
172 | .details_meta {
173 | align-items: center;
174 | display: flex;
175 | justify-content: space-between;
176 | }
177 |
178 | .breadcrumb {
179 | bottom: 0;
180 | display: flex;
181 | list-style-type: none;
182 | padding: 0;
183 | }
184 |
185 | .breadcrumb li {
186 | color: #888;
187 | font-size: 14px;
188 | font-weight: 400;
189 | text-transform: capitalize;
190 | }
191 |
192 | .breadcrumb li a {
193 | color: #666;
194 | text-decoration: none;
195 | }
196 |
197 | .breadcrumb li:hover a {
198 | color: #444;
199 | }
200 |
201 | .breadcrumb li:not(:last-child)::after {
202 | content: '/';
203 | margin: 0 10px;
204 | opacity: 0.35;
205 | user-select: none;
206 | }
207 |
208 | .details_id {
209 | color: #888;
210 | }
211 |
212 | /* .details_info {} */
213 |
214 | .details_info h2 {
215 | color: var(--black-color);
216 | font-family: var(--font-family-2);
217 | font-size: 40px;
218 | font-weight: 500;
219 | margin: 0;
220 | padding: .5rem 0;
221 | }
222 |
223 | .details_info p {
224 | color: #555;
225 | font-size: 15px;
226 | font-weight: 300;
227 | margin: .5rem 0;
228 | line-height: 1.3;
229 | }
230 |
231 | .details_more {
232 | align-items: center;
233 | display: flex;
234 | justify-content: space-between;
235 | margin: 20px 0;
236 | }
237 |
238 | .colors {
239 | display: flex;
240 | flex-wrap: wrap;
241 | height: 40px;
242 | }
243 |
244 | .colors span {
245 | width: 60px;
246 | }
247 |
248 | .ratings_reviews {
249 | align-items: center;
250 | column-gap: 10px;
251 | display: flex;
252 | margin: 10px 0;
253 | }
254 |
255 | .r_count {
256 | color: #888;
257 | font-size: 14px;
258 | font-weight: 400;
259 | }
260 |
261 | .stars {
262 | color: #999;
263 | margin-top: 5px;
264 | }
265 |
266 | .stars span {
267 | font-size: 20px;
268 | }
269 |
270 | .details_actions {
271 | align-items: center;
272 | column-gap: 10px;
273 | display: flex;
274 | margin: 10px 0 0;
275 | }
276 |
277 | .size_details {
278 | align-items: center;
279 | border: 2px solid #eee;
280 | color: #777;
281 | display: flex;
282 | flex: 1;
283 | font-size: 14px;
284 | font-weight: 400;
285 | height: 36px;
286 | justify-content: space-between;
287 | line-height: 20px;
288 | padding: 10px 20px;
289 | }
290 |
291 | .size_details span:nth-child(2) {
292 | max-width: 150px;
293 | overflow: auto;
294 | overflow: -moz-scrollbars-none;
295 | -ms-overflow-style: none;
296 | white-space: nowrap;
297 | }
298 |
299 | .size_details span:nth-child(2)::-webkit-scrollbar {
300 | height: 0 !important;
301 | width: 0 !important;
302 | }
303 |
304 | .action_buy {
305 | align-items: center;
306 | background-color: var(--black-color);
307 | color: #fff;
308 | cursor: pointer;
309 | display: inline-flex;
310 | flex: 1;
311 | font-size: 14px;
312 | font-weight: 400;
313 | height: 40px;
314 | justify-content: space-between;
315 | line-height: 20px;
316 | padding: 10px 20px;
317 | transition: all .2s ease-in;
318 | }
319 |
320 | .action_buy:hover {
321 | background-color: #000;
322 | }
323 |
324 | .price {
325 | color: #bbb;
326 | }
327 |
328 | .price_big {
329 | color: var(--black-color);
330 | font-size: 24px;
331 | font-weight: 600;
332 | margin-bottom: 10px;
333 | }
334 |
335 | @media screen and (min-width:601px) {
336 |
337 | .buy_icon,
338 | .price_big {
339 | display: none;
340 | }
341 |
342 | }
343 |
344 | .preview {
345 | height: 100%;
346 | overflow: hidden;
347 | position: relative;
348 | width: 1100px;
349 | }
350 |
351 | .preview_large {
352 | height: 100%;
353 | overflow: hidden;
354 | position: relative;
355 | width: 100%;
356 | }
357 |
358 | .cover {
359 | left: 50%;
360 | margin: -50px auto 0 -100px;
361 | position: absolute;
362 | text-align: center;
363 | top: 50%;
364 | transform: translate(-50%, -50%);
365 | width: 1000px;
366 | }
367 |
368 | .cover img {
369 | height: 50%;
370 | object-fit: cover;
371 | object-position: left center;
372 | width: 50%;
373 | }
374 |
375 | .cover_large img {
376 | height: 1000px;
377 | margin-top: -200px;
378 | object-fit: contain;
379 | object-position: center;
380 | width: 100%;
381 | }
382 |
383 | @media screen and (max-width:992px) {
384 |
385 | .view_wrapper {
386 | height: auto;
387 | }
388 |
389 | .view_background {
390 | height: 360px;
391 | position: relative;
392 | }
393 |
394 | .view_foreground {
395 | display: block;
396 | left: 0;
397 | position: relative;
398 | }
399 |
400 | .cover {
401 | left: 0;
402 | margin-top: -150px;
403 | position: relative;
404 | top: 0;
405 | transform: none;
406 | width: 100%;
407 | }
408 |
409 | .cover img {
410 | height: 600px;
411 | object-fit: contain;
412 | object-position: center;
413 | width: 600px;
414 | }
415 |
416 | .view_controller {
417 | display: none;
418 | }
419 |
420 | .fs_btn {
421 | display: none;
422 | }
423 |
424 | .arrow_btns {
425 | display: flex;
426 | height: 50px;
427 | justify-content: space-between;
428 | left: 0;
429 | position: absolute;
430 | right: 0;
431 | width: 100%;
432 | top: 50%;
433 | transform: translateY(-50%);
434 | z-index: 10;
435 | }
436 |
437 | }
438 |
439 | @media screen and (min-width:601px) and (max-width:767px) {
440 | .cover {
441 | margin-left: -150px;
442 | }
443 | }
444 |
445 | @media screen and (max-width:600px) {
446 |
447 | .product_details {
448 | padding: 1rem 20px 2rem;
449 | }
450 |
451 | .details_meta {
452 | align-items: flex-start;
453 | flex-direction: column-reverse;
454 | padding-top: 1rem;
455 | }
456 |
457 | .details_more {
458 | align-items: flex-start;
459 | flex-direction: column;
460 | }
461 |
462 | .details_actions {
463 | display: grid;
464 | grid-template-columns: 1fr 60px;
465 | margin-left: -4px;
466 | margin-right: -4px;
467 | }
468 |
469 | .details_actions>div {
470 | border-radius: 30px;
471 | }
472 |
473 | .cover {
474 | margin-left: -250px;
475 | }
476 |
477 | .price,
478 | .buy_text {
479 | display: none;
480 | }
481 | }
--------------------------------------------------------------------------------