Skip to content

Commit

Permalink
Quest Updates (#217)
Browse files Browse the repository at this point in the history
* feat: quest routes, wip mail sender

* feat: add organizer name

* feat: present health data

* fix: list quest organizer on edit

* feat: fetch quest subscribers

* bump build

* feat: add quest page

* feat: allow people fund via the profile page

* feat: display quest list if already subscribed

* feat: update to the quest details page
  • Loading branch information
oreHGA committed May 17, 2024
1 parent 74880a9 commit eef7d1f
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 119 deletions.
13 changes: 13 additions & 0 deletions frontend/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ export interface DatasetExport {
fileNames: string[];
dataSets: Array<any>;
}

export interface IQuest {
title: string;
description: string;
config: string;
guid: string;
userGuid: string;
createdAt: string;
updatedAt: string;
joinCode: string;
organizerName?: string;
participants?: string[]; // userNpubs
}
29 changes: 29 additions & 0 deletions frontend/src/components/stripe-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useEffect } from "react";

const StripeButton: React.FC = () => {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://js.stripe.com/v3/buy-button.js";
script.async = true;
document.body.appendChild(script);

return () => {
document.body.removeChild(script);
};
}, []);

return (
<div
dangerouslySetInnerHTML={{
__html: `
<stripe-buy-button
buy-button-id="buy_btn_1PGow3AKPHx99o8IGvwDtS4E"
publishable-key="pk_live_51NA1xHAKPHx99o8I87C1SBDbmMDaxuiuL3l4hGjNtkcDQv1xFhV900UB8oX6J2iHM8IYVnN6OPDQ4QzqLWCeZeOi00m2L6N4MM"
></stripe-buy-button>
`,
}}
></div>
);
};

export default StripeButton;
13 changes: 11 additions & 2 deletions frontend/src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { getServerSession } from "next-auth";
import { useSession, signOut } from "next-auth/react";

import { authOptions } from "./api/auth/[...nextauth]";
import { DashboardLayout } from "~/components/layouts";
import { DashboardLayout, Meta } from "~/components/layouts";
import { Button, Dialog, DialogContent, DialogDescription, DialogTitle } from "~/components/ui";
import { deletePrivateKey } from "~/utils/auth";
import Link from "next/link";
import StripeButton from "~/components/stripe-button";

const AccountPage: NextPage = () => {
const { data: session } = useSession();
Expand All @@ -19,6 +21,12 @@ const AccountPage: NextPage = () => {

return (
<DashboardLayout>
<Meta
meta={{
title: "Profile | NeuroFusion Explorer",
description: "Your account profile. You have been assigned an anonymous account.",
}}
/>
<h1 className="text-4xl">Profile</h1>
<p className="mb-10 mt-2 text-lg dark:text-slate-400">You have been assigned an anonymous account</p>

Expand All @@ -38,7 +46,8 @@ const AccountPage: NextPage = () => {
</div>

<div>
<p className="mt-5">You're on the Fusion Free Plan.</p>
<p className="mt-5">Fusion is open source. Fund our development!</p>
<StripeButton />
</div>
</DashboardLayout>
);
Expand Down
118 changes: 118 additions & 0 deletions frontend/src/pages/quest/[guid].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// this is what will contain the dashboard

import { GetServerSideProps, NextPage } from "next";
import { getServerSession } from "next-auth";
import { DashboardLayout, Meta } from "~/components/layouts";
import { authOptions } from "../api/auth/[...nextauth]";
import { Button } from "~/components/ui";
import React from "react";
import { api } from "~/config";
import { useSession } from "next-auth/react";
import { IQuest } from "~/@types";
import { usePathname } from "next/navigation";

const QuestDetailPage: NextPage = () => {
const [quest, setQuest] = React.useState<IQuest | null>(null);
const pathname = usePathname();

// get the last part of the pathname
const questId = pathname.split("/").pop();

const session = useSession();
// fetch the quest info
React.useEffect(() => {
// maker request to backend to get quest info
(async () => {
const res = await api.get("/quest/detail", {
params: {
questId,
},
headers: {
Authorization: `Bearer ${session.data?.user?.authToken}`,
},
});

if (res.status === 200) {
const data = res.data;
setQuest(data.quest);

const questSubscribers = await getQuestSubscribers(questId!);
if (questSubscribers) {
setQuestSubscribers(questSubscribers);
}
}
})();
}, []);

// TODO: move to quest.service.ts
const [questSubscribers, setQuestSubscribers] = React.useState<any[]>([]);
const getQuestSubscribers = async (questId: string) => {
try {
const res = await api.get(
"/quest/subscribers",

{
params: {
questId,
},
headers: {
Authorization: `Bearer ${session.data?.user?.authToken}`,
},
}
);

if (res.status === 200) {
console.log("Quest Subscribers fetched successfully");
console.log(res.data);
return res.data.userQuests;
} else {
console.error("Failed to fetch quest subscribers");
}
} catch (error) {
console.error("Failed to fetch quest subscribers", error);
}
};

return (
<DashboardLayout>
<Meta
meta={{
title: `${quest?.title ?? "Quest"} | NeuroFusion Explorer`,
description: `${quest?.description ?? ""}`,
}}
/>
<h1 className="text-4xl">Quest</h1>

{/* display overall quest details */}
<div className="mt-5">
<h2 className="text-2xl">{quest?.title}</h2>
<p className="mt-2">{quest?.description}</p>

<p className="mt-2">Active Participants: {questSubscribers.length}</p>
</div>

<Button intent="primary" className="mt-4">
Download Data
</Button>
</DashboardLayout>
);
};

export default QuestDetailPage;

export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
const session = await getServerSession(req, res, authOptions);

if (!session) {
return {
redirect: {
destination: "/auth/login",
permanent: false,
},
};
}

return {
props: { session },
};
};
7 changes: 6 additions & 1 deletion frontend/src/pages/quests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DashboardLayout, Meta } from "~/components/layouts";
import { Button, Dialog, DialogContent, DialogDescription, DialogTitle, Input } from "~/components/ui";
import { api } from "~/config";
import { useSession } from "next-auth/react";
import Link from "next/link";

interface IQuest {
title: string;
Expand Down Expand Up @@ -175,6 +176,8 @@ const QuestsPage: NextPage = () => {
<Meta
meta={{
title: "NeuroFusion | Quests",
description:
"Create and manage quests for your participants to run. Wearables. Behavior Tracking. Health Data.",
}}
/>{" "}
<h1 className="text-4xl">Quests</h1>
Expand Down Expand Up @@ -273,7 +276,9 @@ const QuestsPage: NextPage = () => {
<tbody>
{savedQuests.map((quest) => (
<tr key={quest.guid}>
<td>{quest.title}</td>
<Link href={`/quest/${quest.guid}`}>
<td className="underline">{quest.title}</td>
</Link>
<td>{quest.description}</td>
<td className="flex justify-center">
<Button
Expand Down
4 changes: 2 additions & 2 deletions mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ missingDimensionStrategy "store", "play"
applicationId 'com.neurofusion.fusion'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 80
versionName "1.8.6"
versionCode 84
versionName "2.0.0"
missingDimensionStrategy 'store', 'play'
}

Expand Down
6 changes: 3 additions & 3 deletions mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: "Fusion",
slug: "fusion",
version: "1.8.6",
version: "2.0.0",
orientation: "portrait",
icon: "./assets/icon.png",
backgroundColor: "#0B0816",
Expand All @@ -20,7 +20,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
ios: {
supportsTablet: true,
bundleIdentifier: "com.neurofusion.fusion",
buildNumber: "80",
buildNumber: "84",
backgroundColor: "#0B0816",
config: {
usesNonExemptEncryption: false,
Expand All @@ -35,7 +35,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
backgroundColor: "#0B0816",
},
package: "com.neurofusion.fusion",
versionCode: 80,
versionCode: 84,
softwareKeyboardLayoutMode: "pan",
},
web: {
Expand Down
4 changes: 2 additions & 2 deletions mobile/ios/Fusion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
);
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG";
PRODUCT_BUNDLE_IDENTIFIER = com.neurofusion.fusion;
PRODUCT_NAME = Fusion;
PRODUCT_NAME = "Fusion";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -415,7 +415,7 @@
);
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE";
PRODUCT_BUNDLE_IDENTIFIER = com.neurofusion.fusion;
PRODUCT_NAME = Fusion;
PRODUCT_NAME = "Fusion";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
Expand Down
4 changes: 2 additions & 2 deletions mobile/ios/Fusion/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.8.6</string>
<string>2.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>80</string>
<string>84</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand Down
2 changes: 2 additions & 0 deletions mobile/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ export interface Quest {
endDate?: number;
prompts?: Prompt[];
additionalMeta?: object;
config?: string;
organizerName?: string;
}
14 changes: 4 additions & 10 deletions mobile/src/components/quests/join-quest-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Button } from "../button";
import { ChevronRight } from "../icons";
import { Input } from "../input";

import { Prompt } from "~/@types";
import { Prompt, Quest } from "~/@types";
import { IS_IOS } from "~/config";
import { AccountContext } from "~/contexts";

Expand Down Expand Up @@ -58,22 +58,16 @@ export const JoinQuestSheet: FC<AddPromptSheetProps> = ({ bottomSheetRef }) => {
if (res.data) {
// navigate to quest screen
const questRes = res.data.quest;
console.log(questRes.config);
const questPrompts = JSON.parse(questRes.config) as Prompt[];
console.log("prompts object", questPrompts);
questRes.prompts = JSON.parse(questRes.config) as Prompt[];

// build the quest object and navigate to the quest screen
Keyboard.dismiss();
bottomSheetRef.current?.close();

navigation.navigate("QuestNavigator", {
screen: "QuestDetailScreen",
params: {
quest: {
title: questRes.title,
description: questRes.description,
guid: questRes.guid,
prompts: questPrompts,
},
quest: questRes as Quest,
},
});
} else {
Expand Down
Loading

0 comments on commit eef7d1f

Please sign in to comment.