From 96823afb869a79ed337a5ab31f1486e6301d5aea Mon Sep 17 00:00:00 2001 From: Josh Calder Date: Fri, 18 Mar 2022 18:28:25 +1100 Subject: [PATCH] Some upgrades (#45) --- .github/workflows/master_pantrydeploy.yml | 75 + apps/Dockerfile | 34 +- apps/user-portal/components/DocumentBlock.tsx | 18 +- .../components/ManageStripeButton.tsx | 3 +- apps/user-portal/components/SigninButton.tsx | 55 +- apps/user-portal/components/SignupButton.tsx | 34 + .../components/SubscribeButton.tsx | 16 +- apps/user-portal/components/forms/User.tsx | 7 +- .../components/forms/householdMembers.tsx | 107 +- apps/user-portal/components/forms/index.tsx | 2 +- .../components/theme/ErrorMessage.js | 5 +- apps/user-portal/components/theme/Footer.js | 28 +- apps/user-portal/components/theme/Header.js | 35 +- apps/user-portal/components/theme/Page.js | 9 +- apps/user-portal/lib/form/apolloClient.ts | 22 +- apps/user-portal/lib/form/index.ts | 6 +- apps/user-portal/lib/form/useForm.ts | 20 +- apps/user-portal/lib/form/useUser.ts | 2 +- apps/user-portal/lib/form/withData.ts | 6 +- apps/user-portal/next.config.js | 2 +- apps/user-portal/package.json | 8 +- .../[club]/[subscription]/[returnStatus].tsx | 20 +- .../pages/[club]/[subscription]/index.tsx | 32 +- .../pages/[club]/[subscription]/subscribe.tsx | 61 +- apps/user-portal/pages/[club]/index.tsx | 30 +- .../pages/[club]/my-membership.tsx | 4 +- apps/user-portal/pages/_app.tsx | 4 +- apps/user-portal/pages/index.tsx | 12 +- apps/user-portal/pages/profile.tsx | 8 +- apps/user-portal/server.js | 17 + backend/Dockerfile | 36 +- backend/keystone.ts | 23 +- backend/lib/stripe.ts | 5 +- .../20220316072755_init/migration.sql | 194 + .../migration.sql | 2 + backend/migrations/migration_lock.toml | 3 + backend/package.json | 24 +- backend/schema.graphql | 7 + backend/schema.prisma | 1 + backend/schemas/User.ts | 30 +- backend/schemas/Variation.ts | 13 + docker-compose.yml | 16 +- package.json | 15 +- pnpm-lock.yaml | 3367 +++-- yarn.lock | 11202 ++++++++++++++++ 45 files changed, 13823 insertions(+), 1797 deletions(-) create mode 100644 .github/workflows/master_pantrydeploy.yml create mode 100644 apps/user-portal/components/SignupButton.tsx create mode 100644 apps/user-portal/server.js create mode 100644 backend/migrations/20220316072755_init/migration.sql create mode 100644 backend/migrations/20220317033016_add_about_to_variation/migration.sql create mode 100644 backend/migrations/migration_lock.toml create mode 100644 yarn.lock diff --git a/.github/workflows/master_pantrydeploy.yml b/.github/workflows/master_pantrydeploy.yml new file mode 100644 index 0000000..920e5c4 --- /dev/null +++ b/.github/workflows/master_pantrydeploy.yml @@ -0,0 +1,75 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy Node.js app to Azure Web App - pantryadmin + +on: + push: + branches: + - master + workflow_dispatch: + +env: + BACKEND_BASE_URL: http://localhost:3000 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js version + uses: actions/setup-node@v1 + with: + node-version: "16.x" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to registry + uses: docker/login-action@v1 + with: + registry: https://collectivereg.azurecr.io/ + username: ${{ secrets.AzureAppService_ContainerUsername_28d39508e5734f558fc68a409d6d0fac }} + password: ${{ secrets.AzureAppService_ContainerPassword_807a7babf8fc4bbab3814a0bd2d77375 }} + + - name: Build and push container image to registry + uses: docker/build-push-action@v2 + with: + push: true + tags: collectivereg.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_28d39508e5734f558fc68a409d6d0fac }}/pantry-backend:${{ github.sha }} + file: ./backend/Dockerfile + + - name: Build and push container image to registry + uses: docker/build-push-action@v2 + with: + push: true + tags: collectivereg.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e63bb1905c6a4a45b5a231dfb2e20209 }}/pantry-frontend:${{ github.sha }} + file: ./apps/Dockerfile + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: "Production" + url: ${{ steps.frontend-to-webapp.outputs.webapp-url }} + + steps: + - name: Deploy Backend to Azure Web App + id: backend-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: "pantryadmin-docker" + slot-name: "production" + publish-profile: ${{ secrets.AzureAppService_PublishProfile_d7e475cd12ae435193e3f0efff1d8394 }} + images: "collectivereg.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_28d39508e5734f558fc68a409d6d0fac }}/pantry-backend:${{ github.sha }}" + + - name: Deploy Frontend to Azure Web App + id: frontend-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: "pantryfrontend" + slot-name: "production" + publish-profile: ${{ secrets.AzureAppService_PublishProfile_4d2ccba4715b4bfe9af97028f357c793 }} + images: "collectivereg.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e63bb1905c6a4a45b5a231dfb2e20209 }}/pantry-frontend:${{ github.sha }}" diff --git a/apps/Dockerfile b/apps/Dockerfile index 21e2754..5ee4998 100644 --- a/apps/Dockerfile +++ b/apps/Dockerfile @@ -1,13 +1,27 @@ +FROM node:16-alpine AS builder +RUN apk update +# Set working directory +WORKDIR /app +RUN yarn global add turbo +COPY . . +RUN turbo prune --scope=@opensaas-clubhouse/frontend --docker -FROM node:16.13-alpine AS deps -ARG APP=next-app -RUN npm i -g pnpm -WORKDIR /usr/app -COPY ".npmrc" . -COPY ["./apps/${APP}/package.json", "pnpm-lock.*", "./"] -RUN pnpm install +# Add lockfile and package.json's of isolated subworkspace +FROM node:16-alpine AS installer +RUN apk update +WORKDIR /app +COPY --from=builder /app/out/json/ . +COPY --from=builder /app/out/yarn.lock ./yarn.lock +RUN yarn install + +FROM node:16-alpine AS sourcer +RUN apk update +WORKDIR /app +COPY --from=installer /app/ . +COPY --from=builder /app/out/full/ . +COPY .gitignore .gitignore ENV NODE_ENV=production -COPY ./apps/${APP}/. . -RUN pnpm build +ENV BACKEND_BASE_URL=http://localhost:3000 +RUN yarn turbo run build --scope=@opensaas-clubhouse/frontend --include-dependencies --no-deps EXPOSE 3000 -CMD ["pnpm", "start"] +CMD ["yarn", "start"] diff --git a/apps/user-portal/components/DocumentBlock.tsx b/apps/user-portal/components/DocumentBlock.tsx index 504c958..e85efac 100644 --- a/apps/user-portal/components/DocumentBlock.tsx +++ b/apps/user-portal/components/DocumentBlock.tsx @@ -1,10 +1,10 @@ import { DocumentRenderer, DocumentRendererProps, -} from "@keystone-6/document-renderer"; -import ReactPlayer from "react-player"; +} from '@keystone-6/document-renderer'; +import ReactPlayer from 'react-player'; -const renderers: DocumentRendererProps["renderers"] = { +const renderers: DocumentRendererProps['renderers'] = { // use your editor's autocomplete to see what other renderers you can override inline: { bold: ({ children }) => {children}, @@ -16,18 +16,18 @@ const renderers: DocumentRendererProps["renderers"] = { }, }; -const componentBlockRenderers: DocumentRendererProps["componentBlocks"] = { +const componentBlockRenderers: DocumentRendererProps['componentBlocks'] = { quote: (props) => (
-
+
{props.content}
-
+
— {props.attribution}
@@ -39,8 +39,8 @@ const componentBlockRenderers: DocumentRendererProps["componentBlocks"] = {
diff --git a/apps/user-portal/components/ManageStripeButton.tsx b/apps/user-portal/components/ManageStripeButton.tsx index 893a7c9..90f58fc 100644 --- a/apps/user-portal/components/ManageStripeButton.tsx +++ b/apps/user-portal/components/ManageStripeButton.tsx @@ -1,5 +1,4 @@ import { Button } from 'react-bootstrap'; -import React from 'react'; import getConfig from 'next/config'; import { useMutation } from '@apollo/client'; import { useSession } from 'next-auth/react'; @@ -20,7 +19,7 @@ export function ManageStripeButton() { `; const [getPortalSession] = useMutation(MANAGE_STRIPE_MUTATION, { - //refetchQueries: [{ query: CURRENT_USER_QUERY }], + // refetchQueries: [{ query: CURRENT_USER_QUERY }], }); if (!userData.id) { return ; diff --git a/apps/user-portal/components/SigninButton.tsx b/apps/user-portal/components/SigninButton.tsx index 3f42e1e..73093ee 100644 --- a/apps/user-portal/components/SigninButton.tsx +++ b/apps/user-portal/components/SigninButton.tsx @@ -1,34 +1,31 @@ -import { signIn, signOut, useSession } from "next-auth/react"; -import { Navbar, Nav, Button } from "react-bootstrap"; -import Link from "next/link"; +import { signIn, signOut, useSession } from 'next-auth/react'; +import { Navbar, Nav, Button } from 'react-bootstrap'; +import Link from 'next/link'; -export function SigninButton() { +export function SigninButton({ ...props }) { + const { returnUrl } = props; const { data, status } = useSession(); + if (!data) + return ( + + ); return ( - <> - {!data ? ( - - ) : ( - <> - - - )} - + ); } diff --git a/apps/user-portal/components/SignupButton.tsx b/apps/user-portal/components/SignupButton.tsx new file mode 100644 index 0000000..3525683 --- /dev/null +++ b/apps/user-portal/components/SignupButton.tsx @@ -0,0 +1,34 @@ +import { signIn, signOut, useSession } from 'next-auth/react'; +import { Navbar, Nav, Button } from 'react-bootstrap'; +import Link from 'next/link'; + +export function SignupButton() { + const { data, status } = useSession(); + if (!data) + return ( + + ); + return ( + + ); +} diff --git a/apps/user-portal/components/SubscribeButton.tsx b/apps/user-portal/components/SubscribeButton.tsx index acb0abc..7068315 100644 --- a/apps/user-portal/components/SubscribeButton.tsx +++ b/apps/user-portal/components/SubscribeButton.tsx @@ -1,15 +1,14 @@ import { Button } from 'react-bootstrap'; -import React from 'react'; import getConfig from 'next/config'; import { useMutation } from '@apollo/client'; import { useSession } from 'next-auth/react'; import { useRouter } from 'next/dist/client/router'; import gql from 'graphql-tag'; +import { SigninButton } from './SigninButton'; import { User } from '../types'; export function SubscribeButton({ ...props }) { const { data: userData, status } = useSession(); - const userSession = userData.data as User; const router = useRouter(); const { variation, subscription, club } = props; @@ -27,9 +26,18 @@ export function SubscribeButton({ ...props }) { } `; + const userSession = userData?.data as User; const [getStripeSession] = useMutation(SUBSCRIPTION_MUTATION, { - //refetchQueries: [{ query: CURRENT_USER_QUERY }], + // refetchQueries: [{ query: CURRENT_USER_QUERY }], }); + if (!userData) { + return ( + + ); + } + const existingVariation = userSession.memberships.find( (m) => m.variation.id === variation.id ); @@ -38,7 +46,9 @@ export function SubscribeButton({ ...props }) { <>

You already have this one and is it {existingVariation.status}

- + ) : ( )} - + )}
    - {relatedLinks.map((relatedLink: RelatedLink, i: number) => { - return ( -
  • -
    -
    {relatedLink.name}
    -
    - {onChange && ( -
    - + - -
    - )} -
  • - ); - })} + color="red" + onClick={() => onDeleteRelatedLink(i)} + /> + +
+ )} + + ))} ); -}; +} diff --git a/apps/user-portal/components/forms/index.tsx b/apps/user-portal/components/forms/index.tsx index 077378c..403fc94 100644 --- a/apps/user-portal/components/forms/index.tsx +++ b/apps/user-portal/components/forms/index.tsx @@ -1 +1 @@ -export { User } from "./User"; +export { User } from './User'; diff --git a/apps/user-portal/components/theme/ErrorMessage.js b/apps/user-portal/components/theme/ErrorMessage.js index a5ddcaa..3499776 100644 --- a/apps/user-portal/components/theme/ErrorMessage.js +++ b/apps/user-portal/components/theme/ErrorMessage.js @@ -18,7 +18,7 @@ const ErrorStyles = styled.div` } `; -export const DisplayError = ({ error }) => { +export function DisplayError({ error }) { if (!error || !error.message) return null; if ( error.networkError && @@ -42,7 +42,7 @@ export const DisplayError = ({ error }) => {

); -}; +} DisplayError.defaultProps = { error: {}, @@ -51,4 +51,3 @@ DisplayError.defaultProps = { DisplayError.propTypes = { error: PropTypes.object, }; - diff --git a/apps/user-portal/components/theme/Footer.js b/apps/user-portal/components/theme/Footer.js index aa26177..41d31a1 100644 --- a/apps/user-portal/components/theme/Footer.js +++ b/apps/user-portal/components/theme/Footer.js @@ -5,21 +5,21 @@ import React from 'react'; import getConfig from 'next/config'; export function Footer() { - const { publicRuntimeConfig } = getConfig(); - return ( - - + return ( + + {' '} - Please email {publicRuntimeConfig?.supportEmail || "set@SUPPORT_EMAIL.env"} if you have any difficulties - with this site + Please email{' '} + {publicRuntimeConfig?.supportEmail || 'set@SUPPORT_EMAIL.env'} if you + have any difficulties with this site + + + + {' '} + Thank you for supporting the Old Church on the Hill - - - {' '} - Thank you for supporting the Old Church on the Hill - - - - ); + + + ); } diff --git a/apps/user-portal/components/theme/Header.js b/apps/user-portal/components/theme/Header.js index f58d48e..1df0f93 100644 --- a/apps/user-portal/components/theme/Header.js +++ b/apps/user-portal/components/theme/Header.js @@ -1,10 +1,9 @@ -import { Navbar, Nav, Button } from "react-bootstrap"; -import Image from "next/image"; -import Link from "next/link"; -import React from "react"; -import { signIn, signOut, useSession } from "next-auth/react"; -import { Container } from "react-bootstrap"; -import { SigninButton } from "../SigninButton"; +import { Navbar, Nav, Button, Container } from 'react-bootstrap'; +import Image from 'next/image'; +import Link from 'next/link'; +import React from 'react'; +import { useSession } from 'next-auth/react'; +import { SigninButton } from '../SigninButton'; export function Header() { const { data, status } = useSession(); @@ -14,7 +13,7 @@ export function Header() {
- {children} + + {children} +