Skip to content

Commit

Permalink
feat: Merch (#114)
Browse files Browse the repository at this point in the history
* feat: Implement orders and products endpoint

[SCSE-236]
[SCSE-237]

* task: Port home page (product listing) (#77)

* feat(merch): Add CORS

* fix: Add CORS types

* feat: Add pricing calculator

* feat(merch): Implement product page

* chore: Run prettier on all merch files

* cleanup: Merge Cart and CartItem

* fix: Use state.cart.items instead of state.items

* update CODEOWNERS

* update CODEOWNERS

* feat(cart): Add cart button component (#95)

* Port thank you page (#99)

* fix: Handle 404 in orders

* feat: Init checkout feature (#102)

* cleanup: Rework merch backend

* chore: Move swiper dependency to web

[SCSE-275]

* fix: Add key to grid item

* chore: Rename JSONResponse to Response

* feat: Add name and image to quotation

* fix: Merch top padding

* feat: add cart page (#96)

[SCSE-271]

* cleanup: Remove quotation HTTP request

* feat: Add merch payment

* fix: Enable product selection by default

* chore: Fix yarn.lock

* fix web build

* update ci to use build:ci scripts for inter-app builds

* fix lint

* fix ci

* add missing env var for web#build

* disable vercel auto preview deployment

* add manual vercel preview deployments

* update turbo.json

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* bump next.js to latest

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update ci.yml

* update cd-staging.yml

---------

Co-authored-by: Guo Yong <[email protected]>
Co-authored-by: nicolelst <[email protected]>
Co-authored-by: Dyllon <[email protected]>
Co-authored-by: YoNG-Zaii <[email protected]>
Co-authored-by: kingsmil <[email protected]>
Co-authored-by: ykcyberarts <[email protected]>
Co-authored-by: dyllon <[email protected]>
  • Loading branch information
8 people authored Jul 9, 2023
1 parent fb4b31c commit 5ee6b4d
Show file tree
Hide file tree
Showing 89 changed files with 5,000 additions and 189 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,39 @@ jobs:
ghcr.io/${{ github.repository_owner }}/website/merch:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/website/merch:latest
build-web:
name: Build Web next.js app
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"

- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile

- name: Build web
run: yarn turbo run build --filter=web

- name: Cache CD Staging workflow for dependent jobs
uses: actions/cache/save@v3
with:
path: .
key: CD-Staging-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}

deploy-to-staging:
name: Deploy To Staging
runs-on: ubuntu-22.04
needs:
- build-cms
- build-merch
- build-web
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -81,3 +108,33 @@ jobs:
docker compose pull &&
docker compose up -d
'
deploy-to-vercel:
name: Deploy To Staging
runs-on: ubuntu-22.04
needs:
- build-cms
- build-merch
- build-web
steps:
- name: Get build cache
uses: actions/cache/restore@v3
with:
path: .
key: CD-Staging-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
fail-on-cache-miss: true

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Copy Build Artifacts to .vercel dir
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
id: deploy-to-vercel
run: |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
vercel alias --token=${{ secrets.VERCEL_TOKEN }} set "$DEPLOYMENT_URL" dev.ntuscse.com
133 changes: 128 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ on:
pull_request:
types: [opened, synchronize]

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} # remote caching
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} # remote caching

jobs:
build:
name: Lint, Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} # remote caching
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} # remote caching
WORDPRESS_API_URL: ${{ secrets.WORDPRESS_API_URL }} # for web

steps:
- name: Grab cache
uses: actions/cache/restore@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
CI-${{ runner.os }}-${{ github.ref }}-
CI-${{ runner.os }}-refs/head/main-
- name: Check out code
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -47,7 +56,121 @@ jobs:
echo "${{steps.prettier-run.outputs.prettier_output}}"
echo "⭐️ You should run `yarn format` in the root of the project directory to fix these files"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_CI }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_CI }}
aws-region: ap-southeast-1

- name: Lint + Build + Unit Test
run: yarn turbo run lint build test cypress:start-headless --color
run: yarn turbo run lint build:ci --color
env:
#merch
AWS_REGION: 'ap-southeast-1'
PRODUCT_TABLE_NAME: 'be-dev-products'
ORDER_TABLE_NAME: 'be-dev-orders'
ORDER_HOLD_TABLE_NAME: 'be-dev-orders-hold'
# web
WORDPRESS_API_URL: 'https://clubs.ntu.edu.sg/csec/graphql'
NEXT_PUBLIC_MERCH_API_ORIGIN: 'http://127.0.0.1:3002'

- name: Cache CI workflow for dependent jobs
uses: actions/cache/save@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}

preview:
name: Vercel Preview - web
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
permissions:
deployments: write
pull-requests: write
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB }}

steps:
- name: Get build cache
uses: actions/cache/restore@v3
with:
path: .
key: CI-${{ runner.os }}-${{ github.ref }}-${{ github.run_id }}
fail-on-cache-miss: true

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Copy Build Artifacts to .vercel dir
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
id: deploy-to-vercel
run: |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
- name: Print Deployment URL
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
run: echo $DEPLOYMENT_URL

- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: '${{ github.token }}'
environment-url: '${{ steps.deploy-to-vercel.outputs.deployment-url }}'
environment: Preview - website

- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: '${{ steps.deploy-to-vercel.outputs.deployment-url }}'
state: 'success'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}

- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
state: 'failure'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}

- name: Comment PR with preview link if success
if: success()
uses: thollander/actions-comment-pull-request@v2
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
with:
message: |
Deployment preview link: ${{ env.DEPLOYMENT_URL }}
comment_tag: execution
mode: recreate


- name: Comment PR with preview link if fail
if: failure()
uses: thollander/actions-comment-pull-request@v2
env:
DEPLOYMENT_URL: ${{ steps.deploy-to-vercel.outputs.deployment-url }}
with:
message: |
Deployment preview link: ❌
comment_tag: execution
mode: recreate





9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ node_modules
coverage

# build
**/.next
**/build
**/out
**/dist

# next.js
.next/
out/
build

# misc
.DS_Store
*.pem
Expand All @@ -44,6 +40,9 @@ yarn-error.log*
# turbo
.turbo

# vercel
.vercel

# jetbrains
.idea

Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/apps/cms/** @jamiegoh
/apps/merch/** @chanbakjsd
/apps/web/** @xJQx
/apps/web/features/merch/** @chanbakjsd
/apps/web/pages/merch/** @chanbakjsd

/packages/eslint-custom-config/** @realdyllon
/packages/nodelogger/** @realdyllon
Expand All @@ -18,4 +20,5 @@
/packages/types/lib/cms.ts @jamiegoh
/packages/types/lib/merch.ts @chanbakjsd
/packages/ui/** @xJQx
/packages/ui/merch/** @chanbakjsd

4 changes: 2 additions & 2 deletions apps/cms/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MONGODB_URI=mongodb://localhost/cms
PAYLOAD_SECRET=
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
PAYLOAD_PUBLIC_SERVER_PORT=3000
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3003
PAYLOAD_PUBLIC_SERVER_PORT=3003
FRONTEND_STAGING_DOMAIN=https://dev.ntuscse.com
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
Expand Down
2 changes: 2 additions & 0 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"build:payload": "yarn generate:types && PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
"build:server": "tsc",
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
"build:ci": "yarn run build",
"clean": "rm -rf dist && rm -rf build",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js BABEL_DISABLE_CACHE=1 NODE_ENV=production node dist/server.js",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
Expand Down
6 changes: 6 additions & 0 deletions apps/merch/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
AWS_REGION=
PRODUCT_TABLE_NAME=
ORDER_TABLE_NAME=
ORDER_HOLD_TABLE_NAME=
CORS_ORIGIN=http://localhost:3001
STRIPE_SECRET_KEY=
25 changes: 19 additions & 6 deletions apps/merch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,42 @@
"license": "Apache-2.0",
"scripts": {
"build": "tsup src/index.ts --format cjs",
"build:ci": "yarn run build",
"start": "node dist/index.js",
"start:ci": "nohup yarn run start > /dev/null 2>&1 &",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "tsup src/index.ts --format cjs --watch --onSuccess \"node dist/index.js\"",
"lint": "TIMING=1 eslint \"**/*.ts*\"",
"lint:fix": "TIMING=1 eslint --fix \"**/*.ts*\""
},
"dependencies": {
"express": "^4.17.1",
"nodelogger": "*"
"@aws-sdk/client-dynamodb": "^3.289.0",
"@aws-sdk/util-dynamodb": "^3.289.0",
"@trpc/server": "^10.31.0",
"add": "^2.0.6",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"nodelogger": "*",
"stripe": "^12.5.0",
"trpc-panel": "^1.3.4",
"uuid": "^9.0.0",
"yarn": "^1.22.19",
"zod": "^3.21.4"
},
"devDependencies": {
"@swc/core": "^1.3.64",
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.9",
"@types/morgan": "^1.9.4",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/uuid": "^9.0.1",
"cookie-parser": "^1.4.6",
"morgan": "^1.10.0",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"tsconfig": "*",
"tsup": "^6.7.0",
"types": "*",
"typescript": "^4.8.4",
"winston": "^3.8.2"
"typescript": "^4.8.4"
}
}
Loading

1 comment on commit 5ee6b4d

@vercel
Copy link

@vercel vercel bot commented on 5ee6b4d Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

website-ui-storybook – ./packages/ui

website-ui-storybook-git-main-cse-it.vercel.app
website-ui-storybook-cse-it.vercel.app
storybook.ui.dev.ntuscse.com

Please sign in to comment.