Initial changes to helpers (scope creep)
This commit is contained in:
parent
48b353ce57
commit
4c4a6e9cda
4 changed files with 110 additions and 99 deletions
|
@ -8,6 +8,7 @@ import { useEffect, useState } from "react";
|
||||||
import { FaShieldAlt } from "react-icons/fa";
|
import { FaShieldAlt } from "react-icons/fa";
|
||||||
import { GiStarFormation } from "react-icons/gi";
|
import { GiStarFormation } from "react-icons/gi";
|
||||||
import { useUser } from "@clerk/nextjs";
|
import { useUser } from "@clerk/nextjs";
|
||||||
|
import { isAdmin, isVIP } from "~/utils/helpers";
|
||||||
|
|
||||||
const Home: NextPage = () => {
|
const Home: NextPage = () => {
|
||||||
return (
|
return (
|
||||||
|
@ -43,10 +44,10 @@ const HomePageBody = () => {
|
||||||
<>
|
<>
|
||||||
<h1 className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-4xl font-bold mx-auto">
|
<h1 className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-4xl font-bold mx-auto">
|
||||||
Hi, {user?.fullName}!{" "}
|
Hi, {user?.fullName}!{" "}
|
||||||
{(user?.publicMetadata.isAdmin as boolean | undefined) && (
|
{isVIP(user?.publicMetadata) && (
|
||||||
<FaShieldAlt className="inline-block text-primary" />
|
<FaShieldAlt className="inline-block text-primary" />
|
||||||
)}
|
)}
|
||||||
{(user?.publicMetadata.isVIP as boolean | undefined) && (
|
{isAdmin(user?.publicMetadata) && (
|
||||||
<GiStarFormation className="inline-block text-secondary" />
|
<GiStarFormation className="inline-block text-secondary" />
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
|
@ -22,7 +22,7 @@ import Link from "next/link";
|
||||||
import { FaShieldAlt } from "react-icons/fa";
|
import { FaShieldAlt } from "react-icons/fa";
|
||||||
import { RiVipCrownFill } from "react-icons/ri";
|
import { RiVipCrownFill } from "react-icons/ri";
|
||||||
import { env } from "~/env.mjs";
|
import { env } from "~/env.mjs";
|
||||||
import { downloadCSV } from "~/utils/helpers";
|
import { downloadCSV, isAdmin, isVIP } from "~/utils/helpers";
|
||||||
import type { PresenceItem } from "~/utils/types";
|
import type { PresenceItem } from "~/utils/types";
|
||||||
import { useUser } from "@clerk/nextjs";
|
import { useUser } from "@clerk/nextjs";
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ const RoomBody = ({}) => {
|
||||||
name: user?.fullName || "",
|
name: user?.fullName || "",
|
||||||
image: user?.imageUrl || "",
|
image: user?.imageUrl || "",
|
||||||
client_id: user?.id || "",
|
client_id: user?.id || "",
|
||||||
isAdmin: (user?.publicMetadata.isAdmin as boolean | undefined) || false,
|
isAdmin: isAdmin(user?.publicMetadata),
|
||||||
isVIP: (user?.publicMetadata.isVIP as boolean | undefined) || false,
|
isVIP: isVIP(user?.publicMetadata),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -347,7 +347,9 @@ const RoomBody = ({}) => {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isSignedIn && !!roomFromDb && roomFromDb.userId === user.id && (
|
{isSignedIn &&
|
||||||
|
!!roomFromDb &&
|
||||||
|
(roomFromDb.userId === user.id || isAdmin(user?.publicMetadata)) && (
|
||||||
<>
|
<>
|
||||||
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
||||||
<div className="card-body flex flex-col flex-wrap">
|
<div className="card-body flex flex-col flex-wrap">
|
||||||
|
@ -432,7 +434,8 @@ const RoomBody = ({}) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{votesFromDb &&
|
{votesFromDb &&
|
||||||
(roomFromDb.logs.length > 0 || votesFromDb.length > 0) && (
|
(roomFromDb.logs.length > 0 ||
|
||||||
|
votesFromDb.length > 0) && (
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
onClick={() => downloadLogs()}
|
onClick={() => downloadLogs()}
|
||||||
|
|
|
@ -139,7 +139,6 @@ export const roomRouter = createTRPCRouter({
|
||||||
.update(rooms)
|
.update(rooms)
|
||||||
.set({
|
.set({
|
||||||
storyName: input.name,
|
storyName: input.name,
|
||||||
userId: ctx.auth.userId,
|
|
||||||
visible: input.visible,
|
visible: input.visible,
|
||||||
scale: [...new Set(input.scale.split(","))]
|
scale: [...new Set(input.scale.split(","))]
|
||||||
.filter((item) => item !== "")
|
.filter((item) => item !== "")
|
||||||
|
|
|
@ -15,3 +15,11 @@ export function downloadCSV(
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isAdmin(meta: UserPublicMetadata | undefined) {
|
||||||
|
return (meta?.isAdmin as boolean | undefined) || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isVIP(meta: UserPublicMetadata | undefined) {
|
||||||
|
return (meta?.isVIP as boolean | undefined) || false;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue