From fb39f86ce90167be8027a908d4e6b4b2c393f68c Mon Sep 17 00:00:00 2001 From: vincanger <70215737+vincanger@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:58:59 +0200 Subject: [PATCH] [MAGE] add modals (#1463) --- wasp-ai/main.wasp | 23 ++++- .../migration.sql | 2 + wasp-ai/src/client/Main.css | 3 + wasp-ai/src/client/components/Header.jsx | 18 +++- wasp-ai/src/client/components/Title.jsx | 2 +- wasp-ai/src/client/pages/MainPage.jsx | 79 ++++++++++++++- wasp-ai/src/client/pages/ResultPage.jsx | 98 ++++++++++++++++++- wasp-ai/src/server/auth.ts | 18 +++- wasp-ai/src/server/operations.ts | 7 ++ 9 files changed, 234 insertions(+), 16 deletions(-) create mode 100644 wasp-ai/migrations/20231002090520_add_github_login/migration.sql diff --git a/wasp-ai/main.wasp b/wasp-ai/main.wasp index 2750dc73c..22f9e6f6d 100644 --- a/wasp-ai/main.wasp +++ b/wasp-ai/main.wasp @@ -2,9 +2,9 @@ app waspAi { wasp: { version: "^0.11.0" }, - title: "GPT Web App Generator ✨", + title: "MAGE - GPT Web App Generator ✨", head: [ - "", + "", "", "", "", @@ -30,6 +30,7 @@ app waspAi { ("@visx/responsive", "3.0.0"), ("@visx/gradient", "3.0.0"), ("@visx/axis", "3.2.0"), + ("js-confetti", "0.11.0") ], client: { rootComponent: import { RootComponent } from "@client/RootComponent.jsx", @@ -41,13 +42,17 @@ app waspAi { userEntity: User, externalAuthEntity: SocialLogin, methods: { + gitHub: { + configFn: import { getGitHubAuthConfig } from "@server/auth.js", + getUserFieldsFn: import { getGitHubUserFields } from "@server/auth.js", + }, google: { configFn: import { getGoogleAuthConfig } from "@server/auth.js", - getUserFieldsFn: import { getUserFields } from "@server/auth.js", - } + getUserFieldsFn: import { getGoogleUserFields } from "@server/auth.js", + }, }, onAuthFailedRedirectTo: "/login", - onAuthSucceededRedirectTo: "/stats" + onAuthSucceededRedirectTo: "/" } } @@ -115,6 +120,13 @@ query getStats { ] } +query getNumProjects { + fn: import { getNumProjects } from "@server/operations.js", + entities: [ + Project + ] +} + entity User {=psl id Int @id @default(autoincrement()) @@ -131,6 +143,7 @@ entity SocialLogin {=psl userId Int user User @relation(fields: [userId], references: [id]) + createdAt DateTime @default(now()) psl=} entity Project {=psl diff --git a/wasp-ai/migrations/20231002090520_add_github_login/migration.sql b/wasp-ai/migrations/20231002090520_add_github_login/migration.sql new file mode 100644 index 000000000..6ec1d821b --- /dev/null +++ b/wasp-ai/migrations/20231002090520_add_github_login/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "SocialLogin" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/wasp-ai/src/client/Main.css b/wasp-ai/src/client/Main.css index f2e435a76..a80e438bc 100644 --- a/wasp-ai/src/client/Main.css +++ b/wasp-ai/src/client/Main.css @@ -18,6 +18,9 @@ body { .button.light-blue { @apply bg-sky-200 text-sky-600 hover:bg-sky-100 } +.button.amber{ + @apply bg-amber-400 text-slate-900 hover:bg-amber-300 +} .button.sm { @apply text-sm py-2 px-4; } diff --git a/wasp-ai/src/client/components/Header.jsx b/wasp-ai/src/client/components/Header.jsx index 9f584b0e5..55e73ff53 100644 --- a/wasp-ai/src/client/components/Header.jsx +++ b/wasp-ai/src/client/components/Header.jsx @@ -1,15 +1,25 @@ -import { StatusPill } from "./StatusPill"; -import { Title } from "./Title"; +import { StatusPill } from './StatusPill'; +import { Title } from './Title'; +import { signInUrl as gitHubSignInUrl } from '@wasp/auth/helpers/GitHub'; +import { AiFillGithub } from 'react-icons/ai'; export function Header({ currentStatus, isStatusVisible }) { return ( -
Generate your full-stack web app in Wasp, React, Node.js and Prisma
diff --git a/wasp-ai/src/client/pages/MainPage.jsx b/wasp-ai/src/client/pages/MainPage.jsx index 7dae4d69b..de67c6314 100644 --- a/wasp-ai/src/client/pages/MainPage.jsx +++ b/wasp-ai/src/client/pages/MainPage.jsx @@ -1,4 +1,4 @@ -import { useState, useMemo } from "react"; +import { useState, useMemo, useEffect } from "react"; import startGeneratingNewApp from "@wasp/actions/startGeneratingNewApp"; import { useHistory } from "react-router-dom"; import { MyDropdown } from "../components/Dropdown"; @@ -7,12 +7,14 @@ import { Header } from "../components/Header"; import { availableColors } from "../components/Color"; import { Faq } from "../components/Faq"; import { exampleIdeas } from "../examples"; -import { PiMagicWandDuotone } from "react-icons/pi"; +import { PiMagicWandDuotone, PiGithubLogoDuotone, PiStarDuotone } from "react-icons/pi"; import { readReferrerFromLocalStorage } from "../storage"; +import { MyDialog } from "../components/Dialog"; const MainPage = () => { const [appName, setAppName] = useState(""); const [appDesc, setAppDesc] = useState(""); + const [isGhModalOpen, setIsGhModalOpen] = useState(false); const [currentStatus, setCurrentStatus] = useState({ status: "idle", message: "Waiting for instructions", @@ -68,12 +70,51 @@ const MainPage = () => { const [appAuthMethod, setAppAuthMethod] = useState(availableAuthMethods[0]); + useEffect(() => { + try { + const appDetails = JSON.parse(localStorage.getItem("appDetails")); + const appNum = JSON.parse(localStorage.getItem("appNum")); + if (!appNum) { + localStorage.setItem("appNum", 0); + } + if (appNum === 2) { + setIsGhModalOpen(true); + } + if (appDetails) { + setAppName(appDetails.appName); + setAppDesc(appDetails.appDesc); + setAppPrimaryColor(availableColors.find((color) => color.name === appDetails.appPrimaryColor)); + setAppAuthMethod(availableAuthMethods.find((method) => method.value === appDetails.appAuthMethod)); + setCreativityLevel(availableCreativityLevels.find((level) => level.value === appDetails.appCreativityLevel)); + localStorage.removeItem("appDetails"); + } + } catch (error) { + console.error(error); + } + }, []); + async function startGenerating(event) { event.preventDefault(); + + try { + const appNum = JSON.parse(localStorage.getItem("appNum")) + localStorage.setItem("appNum", appNum + 1) + localStorage.setItem("appDetails", JSON.stringify({ + appName, + appDesc, + appPrimaryColor: appPrimaryColor.name, + appAuthMethod: appAuthMethod.value, + appCreativityLevel: creativityLevel.value, + })); + } catch (error) { + console.error(error) + } + setCurrentStatus({ status: "idle", message: "Starting...", }); + try { const referrer = readReferrerFromLocalStorage(); const appId = await startGeneratingNewApp({ @@ -110,6 +151,8 @@ const MainPage = () => {