Skip to content

Commit

Permalink
opt in
Browse files Browse the repository at this point in the history
  • Loading branch information
avsomers25 committed Oct 24, 2024
1 parent 220b78b commit 6bca922
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { majors as majorConstants } from '@/app/lib/constants';

import { useSearchParams } from 'next/navigation';

import { OptInSelf } from '@/app/lib/data';

let whenTeamCreationBegins = new Date('March 23, 2024 12:00:00');
const numOfMinsUntilTeamCreation =
(whenTeamCreationBegins.getTime() - Date.now()) / 60000;
Expand Down Expand Up @@ -469,6 +471,39 @@ export default function Dashboard() {
</CardHeader>
</Card>
)}
{userData?.opt_in == null && (
<Card className="w-full max-w-2xl">
<CardHeader>
<CardTitle>Opt in or out to mlh emails!</CardTitle>
<CardDescription>
<Button
onClick={async () => {
const resp = await OptInSelf(true)
if (resp == "GOOD"){
setUserData({ ...userData, opt_in: true })
}
}}
type="button"
className="mt-10"
>
OPT IN
</Button>
<Button
onClick={async () => {
const resp = await OptInSelf(false)
if (resp == "GOOD"){
setUserData({ ...userData, opt_in: false })
}
}}
type="button"
className="mx-10"
>
OPT OUT
</Button>
</CardDescription>
</CardHeader>
</Card>
)}
{userData?.registration_status === 'checked_in' && false && (
<Card className="w-full max-w-2xl">
<CardHeader>
Expand Down
18 changes: 18 additions & 0 deletions app/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ export async function RegisterSelf() {
return 'Something went wrong';
}

export async function OptInSelf(stat:boolean) {
const session = await auth();
console.log('Register Self');
if (session?.user && session?.user?.email) {
const resp = await SetUser(
{ opt_in: stat},
session.user.email,
);

if (resp.error === '') {
return "GOOD";
}
return resp.error;
}

return 'Something went wrong';
}

export async function ConfirmComingOrNot(isComing: boolean): Promise<{
error: string | undefined;
response: Record<string, any>;
Expand Down

0 comments on commit 6bca922

Please sign in to comment.