diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..440c9e5 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +VITE_API_BASE_URL=https://betaapicsa.tradhox.com/api diff --git a/.forgejo/workflows/ci-cd-beta.yml b/.forgejo/workflows/ci-cd-beta.yml index 1c357ab..9650b56 100644 --- a/.forgejo/workflows/ci-cd-beta.yml +++ b/.forgejo/workflows/ci-cd-beta.yml @@ -8,9 +8,10 @@ on: jobs: build-and-test: runs-on: ubuntu-latest + container: node:22 steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: https://github.com/actions/checkout@v4 - name: Install dependencies run: npm ci @@ -20,9 +21,11 @@ jobs: - name: Build run: npm run build + env: + VITE_API_BASE_URL: https://betaapicsa.tradhox.com/api - name: Upload Build Artifact - uses: actions/upload-artifact@v3 + uses: https://github.com/actions/upload-artifact@v3 with: name: dist path: dist/ @@ -30,17 +33,36 @@ jobs: deploy-beta: needs: build-and-test runs-on: ubuntu-latest + container: node:22 steps: - name: Download Build Artifact - uses: actions/download-artifact@v3 + uses: https://github.com/actions/download-artifact@v3 with: name: dist path: dist - - name: Deploy to Beta via FTP - env: - FTP_USERNAME: ${{ secrets.CRM_BETA_FTP_USERNAME }} - FTP_PASSWORD: ${{ secrets.CRM_BETA_FTP_PASSWORD }} - FTP_HOST: ${{ secrets.CRM_FTP_HOST }} + - name: Install AWS CLI run: | - lftp -d -u "$FTP_USERNAME","$FTP_PASSWORD" -e "set ssl:verify-certificate no; set ftp:ssl-allow yes; set ftp:ssl-force true; set ftp:ssl-protect-data true; set ftp:passive-mode true; mirror -R dist/ ./; quit" $FTP_HOST + apt-get update && apt-get install -y awscli + + - name: Deploy to AWS S3 (betacsa) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ap-south-2 + S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_BETA || 'betacsa' }} + run: | + aws s3 sync dist/ s3://$S3_BUCKET --delete + + - name: Invalidate CloudFront Cache + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ap-south-2 + DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_BETA }} + run: | + if [ -n "$DISTRIBUTION_ID" ]; then + aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/*" + else + echo "No CLOUDFRONT_DISTRIBUTION_ID_BETA specified, skipping invalidation." + fi diff --git a/.forgejo/workflows/ci-cd-main.yml b/.forgejo/workflows/ci-cd-main.yml index 91159a1..50f1bc6 100644 --- a/.forgejo/workflows/ci-cd-main.yml +++ b/.forgejo/workflows/ci-cd-main.yml @@ -8,9 +8,10 @@ on: jobs: build-and-test: runs-on: ubuntu-latest + container: node:22 steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: https://github.com/actions/checkout@v4 - name: Install dependencies run: npm ci @@ -20,9 +21,11 @@ jobs: - name: Build run: npm run build + env: + VITE_API_BASE_URL: https://apicsa.tradhox.com/api - name: Upload Build Artifact - uses: actions/upload-artifact@v3 + uses: https://github.com/actions/upload-artifact@v3 with: name: dist path: dist/ @@ -30,19 +33,38 @@ jobs: deploy-prod: needs: build-and-test runs-on: ubuntu-latest + container: node:22 environment: name: production steps: - name: Download Build Artifact - uses: actions/download-artifact@v3 + uses: https://github.com/actions/download-artifact@v3 with: name: dist path: dist - - name: Deploy to Production via FTP - env: - FTP_USERNAME: ${{ secrets.FTP_USERNAME }} - FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} - FTP_HOST: ${{ secrets.FTP_HOST }} + - name: Install AWS CLI run: | - lftp -d -u "$FTP_USERNAME","$FTP_PASSWORD" -e "set ssl:verify-certificate no; set ftp:ssl-allow yes; set ftp:ssl-force true; set ftp:ssl-protect-data true; set ftp:passive-mode true; mirror -R dist/ ./; quit" $FTP_HOST + apt-get update && apt-get install -y awscli + + - name: Deploy to AWS S3 (csawebsite) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ap-south-2 + S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_PROD || 'csawebsite' }} + run: | + aws s3 sync dist/ s3://$S3_BUCKET --delete + + - name: Invalidate CloudFront Cache + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ap-south-2 + DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_PROD }} + run: | + if [ -n "$DISTRIBUTION_ID" ]; then + aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/*" + else + echo "No CLOUDFRONT_DISTRIBUTION_ID_PROD specified, skipping invalidation." + fi diff --git a/src/components/DocumentViewer.jsx b/src/components/DocumentViewer.jsx index e392dce..f894c3c 100644 --- a/src/components/DocumentViewer.jsx +++ b/src/components/DocumentViewer.jsx @@ -1,17 +1,14 @@ import React, { useState } from 'react'; import StatusBadge from './StatusBadge'; import { API_BASE_URL } from '../config'; -import { useAuth } from '../context/AuthContext'; -const DocumentViewer = ({ documents, sellerId }) => { - const { token } = useAuth(); +const DocumentViewer = ({ documents }) => { const [previewDoc, setPreviewDoc] = useState(null); const resolveUrl = (url) => { if (!url) return ''; - if (url.startsWith('/') || url.startsWith('//')) { - // Use window.location.origin to match the secure public domain (e.g. crm.tipro.in) - return `${window.location.origin}/crm/api/crm${url}`; + if (url.startsWith('/')) { + return `${API_BASE_URL}${url}`; } return url; }; diff --git a/src/config.js b/src/config.js index 9d28276..b54f9e8 100644 --- a/src/config.js +++ b/src/config.js @@ -1,2 +1,3 @@ // DigiHox CRM - Frontend Configuration -export const API_BASE_URL = "https://ec2-16-113-57-127.ap-south-2.compute.amazonaws.com/crm/api/crm"; +export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "https://betaapicsa.tradhox.com/api"; + diff --git a/src/context/AuthContext.jsx b/src/context/AuthContext.jsx index 5335de7..74c9bfc 100644 --- a/src/context/AuthContext.jsx +++ b/src/context/AuthContext.jsx @@ -36,7 +36,7 @@ export const AuthProvider = ({ children }) => { } else { logout(); } - } catch (err) { + } catch (_err) { // Fallback to local user session if server is offline setUser({ username: localStorage.getItem('crm_username') || 'vignesh', diff --git a/src/pages/products/CategoryList.jsx b/src/pages/products/CategoryList.jsx index 2216ebf..00ca957 100644 --- a/src/pages/products/CategoryList.jsx +++ b/src/pages/products/CategoryList.jsx @@ -1,7 +1,6 @@ import React, { useState, useEffect } from 'react'; import { API_BASE_URL } from '../../config'; import { useAuth } from '../../context/AuthContext'; -import StatusBadge from '../../components/StatusBadge'; const CategoryList = () => { const { token } = useAuth();