-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
15 changed files
with
461 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.