diff --git a/apps/web/app/admin/page.tsx b/apps/web/app/admin/page.tsx index d306298..38c5ddc 100644 --- a/apps/web/app/admin/page.tsx +++ b/apps/web/app/admin/page.tsx @@ -13,6 +13,9 @@ export default function AdminDashboard() { const { data, isLoading } = trpc.user.getCurrent.useQuery(); + const { data: pendingModifications } = + trpc.modification.getPending.useQuery(); + const { data: pinCounts } = trpc.pin.getStatusCounts.useQuery(); const { data: userCount } = trpc.user.getCount.useQuery(); const { data: commentCount } = trpc.comment.getCount.useQuery(); @@ -28,11 +31,27 @@ export default function AdminDashboard() { const rejectPin = trpc.pin.reject.useMutation({ onSuccess: (output) => { utils.pin.getAllAdmin.invalidate(); + utils.modification.getPending.invalidate(); }, }); const approvePin = trpc.pin.approve.useMutation({ onSuccess: (output) => { + utils.pin.getAll.invalidate(); + utils.pin.getAllAdmin.invalidate(); + utils.modification.getPending.invalidate(); + }, + }); + const applyMod = trpc.pin.applyUpdate.useMutation({ + onSuccess: (output) => { + utils.modification.getPending.invalidate(); + utils.pin.getAll.invalidate(); utils.pin.getAllAdmin.invalidate(); + utils.pin.getStatusCounts.invalidate(); + }, + }); + const rejectMod = trpc.pin.rejectUpdate.useMutation({ + onSuccess: (output) => { + utils.modification.getPending.invalidate(); }, }); @@ -114,40 +133,6 @@ export default function AdminDashboard() { // newUsers30Days: 45, }; - const recentUsers = [ - { - id: "u1", - name: "User 1", - email: "user1@up.edu.ph", - joinedAt: "2 hours ago", - }, - { - id: "u2", - name: "User 2", - email: "user2@up.edu.ph", - joinedAt: "5 hours ago", - }, - { - id: "u3", - name: "User 3", - email: "user3@up.edu.ph", - joinedAt: "1 day ago", - }, - { - id: "u4", - name: "User 4", - email: "user4@up.edu.ph", - joinedAt: "2 days ago", - }, - ]; - - const topUsers = [ - { id: "u1", name: "User 1", pinCount: 142, rank: 1 }, - { id: "u2", name: "User 2", pinCount: 89, rank: 2 }, - { id: "u3", name: "User 3", pinCount: 75, rank: 3 }, - { id: "u4", name: "User 4", pinCount: 60, rank: 4 }, - ]; - return (
{/* --- MOBILE OVERLAY --- */} @@ -749,6 +734,127 @@ export default function AdminDashboard() {
+ +
+
+

RECENT MODIFICATION REQUESTS

+
+ +
+
+ {pendingModifications?.map((mod) => { + const color = "var(--text-primary)"; + return ( +
+
+
+ + {mod.pin.title.charAt(0).toUpperCase()} + +
+ +
+ + {mod.pin.title} + + + Modification by {mod.user.name} + +
+
+ +
+ + + + + + + + + +
+
+ ); + })} +
+
+
diff --git a/apps/web/app/dashboard/page.tsx b/apps/web/app/dashboard/page.tsx index 50afe41..e2ae445 100644 --- a/apps/web/app/dashboard/page.tsx +++ b/apps/web/app/dashboard/page.tsx @@ -6,6 +6,7 @@ import { signOut } from "@/lib/auth-client"; import { trpc } from "@/lib/trpc"; import { PIN_CATEGORIES, getPinColor } from "@/data/pin-categories"; import { useTheme } from "@/lib/ThemeContext"; +import Link from "next/link"; export default function Dashboard() { const router = useRouter(); @@ -496,11 +497,24 @@ export default function Dashboard() { - + ); })} @@ -564,11 +578,24 @@ export default function Dashboard() { - + ); })} diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index 2b970b7..03bb4ac 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -33,6 +33,8 @@ export default function Home() { const session = useSession(); const params = useSearchParams(); + const [hasPreselected, setHasPreselected] = useState(false); + const { data: pins } = trpc.pin.getAll.useQuery(undefined, { refetchOnWindowFocus: false, }); @@ -125,11 +127,12 @@ export default function Home() { }, [isAddingPin]); useEffect(() => { - if (params.has("pin")) { + if (params.has("pin") && !hasPreselected) { const preselectedPin = params.get("pin") as string; selectPin(preselectedPin); + setHasPreselected(true); } - }, [params, selectPin]); + }, [params, selectPin, hasPreselected]); return ( @@ -189,7 +192,10 @@ export default function Home() { !!(matchesCategory && matchesSearch) && (currentUser?.userRole === "admin" ? pinData.status !== "DELETED" - : pinData.status === "ACTIVE"); + : currentUser?.userRole === "user" && + pinData.ownerId === currentUser?.id + ? pinData.status !== "DELETED" + : pinData.status === "ACTIVE"); return ( void; onCancel: () => void; @@ -74,17 +70,14 @@ export function EditPinModal({ onSave, onCancel, pin }: IEditPinModalProps) { handleCancel(); return; } - - const dirtyFields = Object.keys(formMethods.formState.dirtyFields); - console.log(dirtyFields); + const diffs = Object.keys(formMethods.formState.dirtyFields); + if (diffs.length === 0) return; updatePin.mutate({ id: pin.id, - title: dirtyFields.includes("title") ? data.title : undefined, - description: dirtyFields.includes("description") - ? data.description - : undefined, - tags: dirtyFields.includes("tags") ? data.tags || [] : [], + title: diffs.includes("title") ? data.title : undefined, + description: diffs.includes("description") ? data.description : undefined, + tags: diffs.includes("tags") ? data.tags || [] : [], }); }; @@ -96,6 +89,14 @@ export function EditPinModal({ onSave, onCancel, pin }: IEditPinModalProps) { const tags = formMethods.watch("tags"); + useEffect(() => { + formMethods.reset({ + tags: pin.pinTags?.map((pt) => pt.tagId), + title: pin.title, + description: pin.description || "", + }); + }, [formMethods, pin.description, pin.pinTags, pin.title]); + return (
diff --git a/apps/web/components/ExpandedPinView.tsx b/apps/web/components/ExpandedPinView.tsx index efd43e1..317d090 100644 --- a/apps/web/components/ExpandedPinView.tsx +++ b/apps/web/components/ExpandedPinView.tsx @@ -358,7 +358,7 @@ export function ExpandedPinView({ pinId, onClose }: ExpandedPinViewProps) {
- {sessionData?.user?.id === pin?.ownerId && ( + {!!sessionData && (