-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The one with permissions - v1.0.3 #183
* Permissions against admin users for various tabs * Env changes and better usage on emails etc * Header loads less on client * Attendee list stats is real and times are working
- Loading branch information
Showing
27 changed files
with
651 additions
and
515 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
.env.local | ||
.env.production | ||
.idea | ||
|
||
desktop.ini | ||
.vercel | ||
|
||
sendgrid.env | ||
|
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,13 @@ | ||
import React from "react"; | ||
import AuthCheck from "@components/admin/authCheck"; | ||
|
||
export default async function AdminLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <AuthCheck> | ||
{children} | ||
</AuthCheck> | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client' | ||
import useSWR from "swr"; | ||
import { fetcher } from "@lib/fetchers"; | ||
import StatBlock, { StatLine } from "@components/admin/statBlock"; | ||
import { subWeeks } from 'date-fns' | ||
import { guaranteeTimestampFromDate } from '@lib/useful'; | ||
|
||
|
||
export default function AttendeeStats() { | ||
const {data, error, isLoading} = useSWR("/api/admin/attendees", fetcher, { keepPreviousData: false }); | ||
|
||
const stats = isLoading ? | ||
[ | ||
{ name: 'Total', value: 'Loading...', unit: '' }, | ||
{ name: 'Today', value: 'Loading...', unit: '' }, | ||
{ name: 'Meal prefs', value: 'Loading...', unit: '' }, | ||
{ name: 'Dinner Prefs', value: 'Loading...', unit: '' } | ||
] as StatLine[] | ||
: error ? [ | ||
{ name: 'Total', value: "Error", unit: '' }, | ||
{ name: 'Today', value: 'Error', unit: '' }, | ||
{ name: 'Meal prefs', value: 'Error', unit: '' }, | ||
{ name: 'Dinner Prefs', value: 'Error', unit: '' } | ||
] as StatLine[] | ||
: [ | ||
{ name: 'Total', value: data.attendees.length, unit: 'tickets' }, | ||
{ name: 'This week', value: data.attendees.filter((row)=>{ | ||
return guaranteeTimestampFromDate(row.purchased_date) > subWeeks(new Date(),1).getTime() | ||
}).length, unit: 'tickets' }, | ||
{ name: 'Meal prefs', value: data.attendees.filter((row)=>{return row.meal_preferences}).length, unit: 'set' }, | ||
{ name: 'Dinner Prefs', value: 'Unknown', unit: '' } | ||
] as StatLine[] | ||
|
||
return <StatBlock stats={stats}></StatBlock> | ||
// return <div>{JSON.stringify(stats,null,2)}</div> | ||
} |
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,19 @@ | ||
'use client' | ||
import { useUser } from "@clerk/clerk-react"; | ||
import { authUsage } from "@lib/authorise"; | ||
import { usePathname } from 'next/navigation' | ||
import { BiSolidHand } from "react-icons/bi"; | ||
|
||
const containerClasses = "flex w-full h-screen justify-center items-center" | ||
const alertClasses = " border border-1 border-gray-500 rounded-md p-6 flex gap-3 items-center justify-center " | ||
|
||
export default function AuthCheck({children}) { | ||
const { user, isLoaded } = useUser(); | ||
const path = usePathname() | ||
|
||
if(path == '/admin') return children | ||
if (!isLoaded) { return <div className={containerClasses}><div className={alertClasses}>Permission Checking...</div></div> } | ||
if (!user) { return <div className={containerClasses}><div className={alertClasses}>Not Logged.</div></div> } | ||
if(!authUsage(user, path)) { return <div className={containerClasses }><div className={alertClasses + ` text-chillired-800 border-chillired-800`}><BiSolidHand/>Not Authorised!</div></div> } | ||
return children | ||
} |
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.