Skip to content

Commit

Permalink
Reuse pages from captn (#11)
Browse files Browse the repository at this point in the history
* Add toc and privacy page

* Update auth component

* Update customer portal link

* Update CI action file
  • Loading branch information
harishmohanraj authored Apr 12, 2024
1 parent 30d5590 commit 7144624
Show file tree
Hide file tree
Showing 21 changed files with 1,583 additions and 105 deletions.
135 changes: 66 additions & 69 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,67 +81,64 @@ jobs:
run: docker push ghcr.io/$GITHUB_REPOSITORY --all-tags


# deploy_backend:
# runs-on: ubuntu-22.04
# defaults:
# run:
# shell: bash
# if: github.ref_name == 'main' || github.ref_name == 'dev'
# env:
# GITHUB_USERNAME: ${{ github.actor }}
# GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
# PORT: ${{ vars.PORT }}
# REACT_APP_CUSTOMER_PORTAL_LINK: ${{ vars.REACT_APP_CUSTOMER_PORTAL_LINK }}
# GOOGLE_CLIENT_ID: ${{ github.ref_name == 'main' && secrets.PROD_GOOGLE_CLIENT_ID || secrets.STAGING_GOOGLE_CLIENT_ID }}
# GOOGLE_CLIENT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_GOOGLE_CLIENT_SECRET || secrets.STAGING_GOOGLE_CLIENT_SECRET }}
# ADMIN_EMAILS: ${{ vars.ADMIN_EMAILS }}

# WASP_SERVER_URL: ${{ github.ref_name == 'main' && vars.PROD_WASP_SERVER_URL || vars.STAGING_WASP_SERVER_URL }}
# ADS_SERVER_URL: ${{ github.ref_name == 'main' && vars.PROD_ADS_SERVER_URL || vars.STAGING_ADS_SERVER_URL }}
# BACKEND_DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_BACKEND_DOMAIN || vars.STAGING_BACKEND_DOMAIN }}
# WASP_WEB_CLIENT_URL: ${{ github.ref_name == 'main' && vars.PROD_WASP_WEB_CLIENT_URL || vars.STAGING_WASP_WEB_CLIENT_URL }}
# DATABASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_DATABASE_URL || secrets.STAGING_DATABASE_URL }}
# REACT_APP_API_URL: ${{ github.ref_name == 'main' && vars.PROD_REACT_APP_API_URL || vars.STAGING_REACT_APP_API_URL }}
# JWT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_JWT_SECRET || secrets.STAGING_JWT_SECRET }}
# PRO_SUBSCRIPTION_PRICE_ID: ${{ github.ref_name == 'main' && secrets.PROD_PRO_SUBSCRIPTION_PRICE_ID || secrets.STAGING_PRO_SUBSCRIPTION_PRICE_ID }}
# STRIPE_KEY: ${{ github.ref_name == 'main' && secrets.PROD_STRIPE_KEY || secrets.STAGING_STRIPE_KEY }}
# STRIPE_WEBHOOK_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_STRIPE_WEBHOOK_SECRET || secrets.STAGING_STRIPE_WEBHOOK_SECRET }}
# SSH_KEY: ${{ github.ref_name == 'main' && secrets.PROD_SSH_KEY || secrets.STAGING_SSH_KEY }}
# steps:
# - uses: actions/checkout@v3
# # This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
# - run: chown -R $(id -u):$(id -g) $PWD

# - run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "TAG=latest" >> $GITHUB_ENV ; else echo "TAG=dev" >> $GITHUB_ENV ; fi;

# - run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
# - run: 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
# - run: eval $(ssh-agent -s)
# - run: mkdir -p ~/.ssh
# - run: chmod 700 ~/.ssh
# - run: ssh-keyscan "$BACKEND_DOMAIN" >> ~/.ssh/known_hosts
# - run: chmod 644 ~/.ssh/known_hosts
# - run: echo "$SSH_KEY" | base64 --decode > key.pem
# - run: chmod 600 key.pem

# - run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$BACKEND_DOMAIN" "docker images"
# - run: bash scripts/deploy_backend.sh

# - run: rm key.pem
deploy_backend:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
if: github.ref_name == 'main' || github.ref_name == 'dev'
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
PORT: ${{ vars.PORT }}
REACT_APP_CUSTOMER_PORTAL_LINK: ${{ vars.REACT_APP_CUSTOMER_PORTAL_LINK }}
GOOGLE_CLIENT_ID: ${{ github.ref_name == 'main' && secrets.PROD_GOOGLE_CLIENT_ID || secrets.STAGING_GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_GOOGLE_CLIENT_SECRET || secrets.STAGING_GOOGLE_CLIENT_SECRET }}
ADMIN_EMAILS: ${{ vars.ADMIN_EMAILS }}

WASP_SERVER_URL: ${{ github.ref_name == 'main' && vars.PROD_WASP_SERVER_URL || vars.STAGING_WASP_SERVER_URL }}
ADS_SERVER_URL: ${{ github.ref_name == 'main' && vars.PROD_ADS_SERVER_URL || vars.STAGING_ADS_SERVER_URL }}
BACKEND_DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_BACKEND_DOMAIN || vars.STAGING_BACKEND_DOMAIN }}
WASP_WEB_CLIENT_URL: ${{ github.ref_name == 'main' && vars.PROD_WASP_WEB_CLIENT_URL || vars.STAGING_WASP_WEB_CLIENT_URL }}
DATABASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_DATABASE_URL || secrets.STAGING_DATABASE_URL }}
REACT_APP_API_URL: ${{ github.ref_name == 'main' && vars.PROD_REACT_APP_API_URL || vars.STAGING_REACT_APP_API_URL }}
JWT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_JWT_SECRET || secrets.STAGING_JWT_SECRET }}
PRO_SUBSCRIPTION_PRICE_ID: ${{ github.ref_name == 'main' && secrets.PROD_PRO_SUBSCRIPTION_PRICE_ID || secrets.STAGING_PRO_SUBSCRIPTION_PRICE_ID }}
STRIPE_KEY: ${{ github.ref_name == 'main' && secrets.PROD_STRIPE_KEY || secrets.STAGING_STRIPE_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_STRIPE_WEBHOOK_SECRET || secrets.STAGING_STRIPE_WEBHOOK_SECRET }}
SSH_KEY: ${{ github.ref_name == 'main' && secrets.PROD_SSH_KEY || secrets.STAGING_SSH_KEY }}
steps:
- uses: actions/checkout@v3
# This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
- run: chown -R $(id -u):$(id -g) $PWD

- run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "TAG=latest" >> $GITHUB_ENV ; else echo "TAG=dev" >> $GITHUB_ENV ; fi;

- run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
- run: 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- run: eval $(ssh-agent -s)
- run: mkdir -p ~/.ssh
- run: chmod 700 ~/.ssh
- run: ssh-keyscan "$BACKEND_DOMAIN" >> ~/.ssh/known_hosts
- run: chmod 644 ~/.ssh/known_hosts
- run: echo "$SSH_KEY" | base64 --decode > key.pem
- run: chmod 600 key.pem

- run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$BACKEND_DOMAIN" "docker images"
- run: bash scripts/deploy_backend.sh

- run: rm key.pem

deploy_frontend:
runs-on: ubuntu-22.04
permissions:
contents: write
if: github.ref_name == 'main' || github.ref_name == 'dev'
env:
# STAGING_BACKEND_DOMAIN: ${{ vars.STAGING_BACKEND_DOMAIN }}
# STAGING_SSH_KEY: ${{ secrets.STAGING_SSH_KEY }}
# REACT_APP_CUSTOMER_PORTAL_LINK: ${{ vars.REACT_APP_CUSTOMER_PORTAL_LINK }}
# REACT_APP_API_URL: ${{ github.ref_name == 'main' && vars.PROD_REACT_APP_API_URL || vars.STAGING_REACT_APP_API_URL }}

REACT_APP_CUSTOMER_PORTAL_LINK: ""
REACT_APP_API_URL: ""
STAGING_BACKEND_DOMAIN: ${{ vars.STAGING_BACKEND_DOMAIN }}
STAGING_SSH_KEY: ${{ secrets.STAGING_SSH_KEY }}
REACT_APP_CUSTOMER_PORTAL_LINK: ${{ vars.REACT_APP_CUSTOMER_PORTAL_LINK }}
REACT_APP_API_URL: ${{ github.ref_name == 'main' && vars.PROD_REACT_APP_API_URL || vars.STAGING_REACT_APP_API_URL }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -171,18 +168,18 @@ jobs:
with:
folder: app/.wasp/build/web-app/build

# - name: Deploy UI to staging
# if: github.ref_name == 'dev'
# run: |
# apt-get update -y && apt-get install openssh-client git -y
# eval $(ssh-agent -s)
# mkdir -p ~/.ssh
# chmod 700 ~/.ssh
# ssh-keyscan "$STAGING_BACKEND_DOMAIN" >> ~/.ssh/known_hosts
# chmod 644 ~/.ssh/known_hosts
# echo "$STAGING_SSH_KEY" | base64 --decode > key.pem
# chmod 600 key.pem
# ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$STAGING_BACKEND_DOMAIN" "ls -lah /var/www/html/UI"
# scp -i key.pem -r app/.wasp/build/web-app/build azureuser@"$STAGING_BACKEND_DOMAIN":/var/www/html/UI
# ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$STAGING_BACKEND_DOMAIN" "ls -lah /var/www/html/UI"
# rm key.pem
- name: Deploy UI to staging
if: github.ref_name == 'dev'
run: |
apt-get update -y && apt-get install openssh-client git -y
eval $(ssh-agent -s)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan "$STAGING_BACKEND_DOMAIN" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
echo "$STAGING_SSH_KEY" | base64 --decode > key.pem
chmod 600 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$STAGING_BACKEND_DOMAIN" "ls -lah /var/www/html/UI"
scp -i key.pem -r app/.wasp/build/web-app/build azureuser@"$STAGING_BACKEND_DOMAIN":/var/www/html/UI
ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$STAGING_BACKEND_DOMAIN" "ls -lah /var/www/html/UI"
rm key.pem
14 changes: 13 additions & 1 deletion app/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app OpenSaaS {
},
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/",
onAuthSucceededRedirectTo: "/chat",
},
db: {
system: PostgreSQL,
Expand Down Expand Up @@ -67,6 +67,9 @@ entity User {=psl
createdAt DateTime @default(now())
lastActiveTimestamp DateTime @default(now())
isAdmin Boolean @default(false)
hasAcceptedTos Boolean @default(false)
hasSubscribedToMarketingEmails Boolean @default(false)
isSignUpComplete Boolean @default(false)
stripeId String?
checkoutSessionId String?
hasPaid Boolean @default(false)
Expand Down Expand Up @@ -148,6 +151,15 @@ page CheckoutPage {
component: import Checkout from "@src/client/app/CheckoutPage"
}

route TocPageRoute { path: "/toc", to: TocPage }
page TocPage {
component: import TocPage from "@src/client/app/TocPage",
}
route PrivacyRoute { path: "/privacy", to: PrivacyPage }
page PrivacyPage {
component: import PrivacyPage from "@src/client/app/PrivacyPage",
}

route AdminRoute { path: "/admin", to: DashboardPage }
page DashboardPage {
authRequired: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "hasAcceptedTos" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "hasSubscribedToMarketingEmails" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "isSignUpComplete" BOOLEAN NOT NULL DEFAULT false;
92 changes: 84 additions & 8 deletions app/src/client/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useEffect, ReactNode } from 'react';
import { useMemo, useEffect, ReactNode, useState } from 'react';
import { useLocation } from 'react-router-dom';

import './Main.css';
Expand All @@ -10,6 +10,7 @@ import AppNavBar from './components/AppNavBar';
import Footer from './components/Footer';
import ServerNotRechableComponent from './components/ServerNotRechableComponent';
import LoadingComponent from './components/LoadingComponent';
import TosAndMarketingEmailsModal from './components/TosAndMarketingEmailsModal';

const addServerErrorClass = () => {
if (!document.body.classList.contains('server-error')) {
Expand All @@ -29,6 +30,7 @@ const removeServerErrorClass = () => {
*/
export default function App({ children }: { children: ReactNode }) {
const location = useLocation();
const [showTosAndMarketingEmailsModal, setShowTosAndMarketingEmailsModal] = useState(false);
const { data: user, isError, isLoading } = useAuth();

const shouldDisplayAppNavBar = useMemo(() => {
Expand All @@ -39,12 +41,48 @@ export default function App({ children }: { children: ReactNode }) {
return location.pathname.startsWith('/admin');
}, [location]);

const isCheckoutPage = useMemo(() => {
return location.pathname.startsWith('/checkout');
}, [location]);

const isAccountPage = useMemo(() => {
return location.pathname.startsWith('/account');
}, [location]);

const isChatPage = useMemo(() => {
return location.pathname.startsWith('/chat');
}, [location]);

useEffect(() => {
if (user) {
const lastSeenAt = new Date(user.lastActiveTimestamp);
const today = new Date();
if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) {
updateCurrentUser({ lastActiveTimestamp: today });
console.log('user', user);
if (!user.isSignUpComplete) {
if (user.hasAcceptedTos) {
updateCurrentUser({
isSignUpComplete: true,
});
setShowTosAndMarketingEmailsModal(false);
} else {
const hasAcceptedTos = localStorage.getItem('hasAcceptedTos') === 'true';
const hasSubscribedToMarketingEmails = localStorage.getItem('hasSubscribedToMarketingEmails') === 'true';
if (!hasAcceptedTos) {
setShowTosAndMarketingEmailsModal(true);
} else {
updateCurrentUser({
isSignUpComplete: true,
hasAcceptedTos: hasAcceptedTos,
hasSubscribedToMarketingEmails: hasSubscribedToMarketingEmails,
});
setShowTosAndMarketingEmailsModal(false);
}
}
} else {
setShowTosAndMarketingEmailsModal(false);
const lastSeenAt = new Date(user.lastActiveTimestamp);
const today = new Date();
if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) {
updateCurrentUser({ lastActiveTimestamp: today });
}
}
}
}, [user]);
Expand All @@ -63,13 +101,51 @@ export default function App({ children }: { children: ReactNode }) {
<>
<div className='bg-gradient-to-b from-airt-hero-gradient-start via-airt-hero-gradient-middle to-airt-secondary min-h-screen dark:text-white dark:bg-boxdark-2'>
{isError && (addServerErrorClass(), (<ServerNotRechableComponent />))}
{isAdminDashboard ? (
<>{children}</>
{isAdminDashboard || isChatPage ? (
<>
{showTosAndMarketingEmailsModal ? (
<>
<TosAndMarketingEmailsModal />
</>
) : (
<>
{isAdminDashboard ? (
children
) : (
<div className='relative flex flex-col min-h-screen justify-between'>
{shouldDisplayAppNavBar && <AppNavBar />}
{children}
<div>
<Footer />
<div className='flex items-center h-20 bg-airt-footer-copyrights'>
<p className='text-center w-full text-sm text-airt-font-base opacity-50'>
© 2024 airt. All rights reserved.
</p>
</div>
</div>
</div>
)}
</>
)}
</>
) : (
<div className='relative flex flex-col min-h-screen justify-between'>
{shouldDisplayAppNavBar && <AppNavBar />}
<div className='mx-auto max-w-7xl sm:px-6 lg:px-8 w-full'>
{isError ? children : isLoading ? <LoadingComponent /> : (removeServerErrorClass(), children)}
{isError ? (
children
) : isLoading ? (
<LoadingComponent />
) : (
(removeServerErrorClass(),
showTosAndMarketingEmailsModal && (isCheckoutPage || isAccountPage) ? (
<>
<TosAndMarketingEmailsModal />
</>
) : (
children
))
)}
</div>
<div>
<Footer />
Expand Down
Loading

0 comments on commit 7144624

Please sign in to comment.