Added many todos

This commit is contained in:
Tim Howitz 2025-05-20 13:53:25 +01:00
parent 1b0b751b32
commit efc16aa92a
10 changed files with 429 additions and 387 deletions

View File

@ -50,7 +50,6 @@ model Earthquake {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
date DateTime
code String @unique
magnitude Float
@ -59,10 +58,8 @@ model Earthquake {
longitude Float
location String
depth String
creatorId Int?
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id])
artefacts Artefact[]
observatories Observatory[] @relation("EarthquakeObservatory")
}
@ -91,6 +88,7 @@ model Artefact {
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
warehouseArea String
description String
imagePath String
earthquakeId Int
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
creatorId Int?
@ -101,6 +99,8 @@ model Artefact {
isSold Boolean @default(false)
purchasedById Int?
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
// todo unlink purchase from user
// todo link purchase to order
isCollected Boolean @default(false)
}
@ -111,3 +111,11 @@ model Pallet {
warehouseArea String
palletNote String
}
model Order {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
orderNumber String
// todo link order to user
}

View File

@ -1,5 +1,6 @@
"use client";
import React, { useState, useRef } from "react";
import React, { useRef, useState } from 'react';
type Role = "ADMIN" | "GUEST" | "SCIENTIST";
const roleLabels: Record<Role, string> = {
ADMIN: "Admin",
@ -15,11 +16,27 @@ type User = {
createdAt: string;
};
// todo create api route to get users, with auth for only admin
// todo add management of only junior scientists if senior scientist
const initialUsers: User[] = [
{ email: "john@example.com", name: "John Doe", role: "ADMIN", password: "secret1", createdAt: "2024-06-21T09:15:01Z", id: 1 },
{ email: "jane@example.com", name: "Jane Smith", role: "GUEST", password: "secret2", createdAt: "2024-06-21T10:01:09Z", id: 2 },
{ email: "bob@example.com", name: "Bob Brown", role: "SCIENTIST", password: "secret3", createdAt: "2024-06-21T12:13:45Z" ,id:3},
{ email: "alice@example.com", name: "Alice Johnson",role: "GUEST", password: "secret4", createdAt: "2024-06-20T18:43:20Z" ,id:4},
{
email: "bob@example.com",
name: "Bob Brown",
role: "SCIENTIST",
password: "secret3",
createdAt: "2024-06-21T12:13:45Z",
id: 3,
},
{
email: "alice@example.com",
name: "Alice Johnson",
role: "GUEST",
password: "secret4",
createdAt: "2024-06-20T18:43:20Z",
id: 4,
},
{ email: "eve@example.com", name: "Eve Black", role: "ADMIN", password: "secret5", createdAt: "2024-06-20T19:37:10Z", id: 5 },
{ email: "dave@example.com", name: "Dave Clark", role: "GUEST", password: "pw", createdAt: "2024-06-19T08:39:10Z", id: 6 },
{ email: "fred@example.com", name: "Fred Fox", role: "GUEST", password: "pw", createdAt: "2024-06-19T09:11:52Z", id: 7 },
@ -30,12 +47,13 @@ const initialUsers: User[] = [
{ email: "leo@example.com", name: "Leo Garrison", role: "GUEST", password: "pw", createdAt: "2024-06-12T08:02:51Z", id: 12 },
{ email: "isaac@example.com", name: "Isaac Yang", role: "GUEST", password: "pw", createdAt: "2024-06-12T15:43:29Z", id: 13 },
];
const sortFields = [ // Sort box options
const sortFields = [
// Sort box options
{ label: "Name", value: "name" },
{ label: "Email", value: "email" },
] as const;
type SortField = typeof sortFields[number]["value"];
type SortField = (typeof sortFields)[number]["value"];
type SortDir = "asc" | "desc";
const dirLabels: Record<SortDir, string> = { asc: "ascending", desc: "descending" };
const fieldLabels: Record<SortField, string> = { name: "Name", email: "Email" };
@ -50,7 +68,7 @@ export default function AdminPage() {
React.useEffect(() => {
if (!selectedEmail) setEditUser(null);
else {
const user = users.find(u => u.email === selectedEmail);
const user = users.find((u) => u.email === selectedEmail);
setEditUser(user ? { ...user } : null);
}
}, [selectedEmail, users]);
@ -69,24 +87,16 @@ export default function AdminPage() {
React.useEffect(() => {
const handleClick = (e: MouseEvent) => {
if (
filterDropdownRef.current && !filterDropdownRef.current.contains(e.target as Node)
) setFilterDropdownOpen(false);
if (
sortDropdownRef.current && !sortDropdownRef.current.contains(e.target as Node)
) setSortDropdownOpen(false);
if (filterDropdownRef.current && !filterDropdownRef.current.contains(e.target as Node)) setFilterDropdownOpen(false);
if (sortDropdownRef.current && !sortDropdownRef.current.contains(e.target as Node)) setSortDropdownOpen(false);
};
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}, []);
// Filtering, searching, sorting logic
const filteredUsers = users.filter(
(user) => roleFilter === "all" || user.role === roleFilter
);
const searchedUsers = filteredUsers.filter(user =>
user[searchField].toLowerCase().includes(searchText.toLowerCase())
);
const filteredUsers = users.filter((user) => roleFilter === "all" || user.role === roleFilter);
const searchedUsers = filteredUsers.filter((user) => user[searchField].toLowerCase().includes(searchText.toLowerCase()));
const sortedUsers = [...searchedUsers].sort((a, b) => {
let cmp = a[sortField].localeCompare(b[sortField]);
return sortDir === "asc" ? cmp : -cmp;
@ -96,9 +106,7 @@ export default function AdminPage() {
const handleEditChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
if (!editUser) return;
const { name, value } = e.target;
setEditUser(prev =>
prev ? { ...prev, [name]: value } : null
);
setEditUser((prev) => (prev ? { ...prev, [name]: value } : null));
};
// Update button logic (compare original selectedUser and editUser)
@ -107,9 +115,7 @@ export default function AdminPage() {
if (!editUser || !selectedUser) return false;
// Compare primitive fields
return (
editUser.name !== selectedUser.name ||
editUser.role !== selectedUser.role ||
editUser.password !== selectedUser.password
editUser.name !== selectedUser.name || editUser.role !== selectedUser.role || editUser.password !== selectedUser.password
);
}, [editUser, selectedUser]);
@ -117,11 +123,9 @@ export default function AdminPage() {
const handleUpdate = (e: React.FormEvent) => {
e.preventDefault();
if (!editUser) return;
setUsers(prev =>
prev.map(u =>
u.email === editUser.email ? { ...editUser } : u
)
);
setUsers((prev) => prev.map((u) => (u.email === editUser.email ? { ...editUser } : u)));
// todo create receiving api route
// todo send to api route
// After successful update, update selectedUser local state
// (editUser will auto-sync due to useEffect on users)
};
@ -130,7 +134,7 @@ export default function AdminPage() {
const handleDelete = () => {
if (!selectedUser) return;
if (!window.confirm(`Are you sure you want to delete "${selectedUser.name}"? This cannot be undone.`)) return;
setUsers(prev => prev.filter(u => u.email !== selectedUser.email));
setUsers((prev) => prev.filter((u) => u.email !== selectedUser.email));
setSelectedEmail(null);
setEditUser(null);
};
@ -152,13 +156,13 @@ export default function AdminPage() {
className="flex-1 border rounded-lg px-2 py-1 text-sm"
placeholder={`Search by ${searchField}`}
value={searchText}
onChange={e => setSearchText(e.target.value)}
onChange={(e) => setSearchText(e.target.value)}
/>
<button
type="button"
className="border rounded-lg px-2 py-1 text-sm bg-white hover:bg-neutral-100 transition font-semibold"
style={{ width: "80px" }} // fixed width, adjust as needed
onClick={() => setSearchField(field => field === "name" ? "email" : "name")}
onClick={() => setSearchField((field) => (field === "name" ? "email" : "name"))}
title={`Switch to searching by ${searchField === "name" ? "Email" : "Name"}`}
>
{searchField === "name" ? "Email" : "Name"}
@ -170,28 +174,39 @@ export default function AdminPage() {
<div className="relative" ref={filterDropdownRef}>
<button
className={`px-3 py-1 rounded-lg border font-semibold flex items-center transition
${roleFilter !== "all"
${
roleFilter !== "all"
? "bg-blue-600 text-white border-blue-600 hover:bg-blue-700"
: "bg-white text-gray-700 border hover:bg-neutral-200"}
: "bg-white text-gray-700 border hover:bg-neutral-200"
}
`}
onClick={() => setFilterDropdownOpen(v => !v)}
onClick={() => setFilterDropdownOpen((v) => !v)}
type="button"
>
Filter <svg className="w-4 h-4 ml-1" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" /></svg>
Filter{" "}
<svg className="w-4 h-4 ml-1" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</button>
{filterDropdownOpen && (
<div className="absolute z-10 mt-1 left-0 bg-white border rounded-lg shadow-sm w-28 py-1">
<button
onClick={() => { setRoleFilter("all"); setFilterDropdownOpen(false); }}
onClick={() => {
setRoleFilter("all");
setFilterDropdownOpen(false);
}}
className={`w-full text-left px-3 py-1 hover:bg-blue-50 border-b border-gray-100 last:border-0
${roleFilter === "all" ? "font-bold text-blue-600" : ""}`}
>
All
</button>
{allRoles.map(role => (
{allRoles.map((role) => (
<button
key={role}
onClick={() => { setRoleFilter(role); setFilterDropdownOpen(false); }}
onClick={() => {
setRoleFilter(role);
setFilterDropdownOpen(false);
}}
className={`w-full text-left px-3 py-1 hover:bg-blue-50 border-b border-gray-100 last:border-0
${roleFilter === role ? "font-bold text-blue-600" : ""}`}
>
@ -205,14 +220,17 @@ export default function AdminPage() {
<div className="relative" ref={sortDropdownRef}>
<button
className="px-3 py-1 rounded-lg bg-white border text-gray-700 font-semibold flex items-center hover:bg-neutral-200"
onClick={() => setSortDropdownOpen(v => !v)}
onClick={() => setSortDropdownOpen((v) => !v)}
type="button"
>
Sort <svg className="w-4 h-4 ml-1" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" /></svg>
Sort{" "}
<svg className="w-4 h-4 ml-1" fill="none" stroke="currentColor" strokeWidth={2} viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</button>
{sortDropdownOpen && (
<div className="absolute z-10 mt-1 left-0 bg-white border rounded-lg shadow-sm w-28 ">
{sortFields.map(opt => (
{sortFields.map((opt) => (
<button
key={opt.value}
onClick={() => {
@ -231,7 +249,7 @@ export default function AdminPage() {
{/* Asc/Desc Toggle */}
<button
className="ml-2 px-2 py-1 rounded-lg bg-white border text-gray-700 font-semibold flex items-center hover:bg-neutral-200"
onClick={() => setSortDir(d => (d === "asc" ? "desc" : "asc"))}
onClick={() => setSortDir((d) => (d === "asc" ? "desc" : "asc"))}
title={sortDir === "asc" ? "Ascending" : "Descending"}
type="button"
>
@ -261,9 +279,7 @@ export default function AdminPage() {
</div>
</li>
))}
{sortedUsers.length === 0 && (
<li className="text-gray-400 text-center py-6">No users found.</li>
)}
{sortedUsers.length === 0 && <li className="text-gray-400 text-center py-6">No users found.</li>}
</ul>
</div>
</div>
@ -282,9 +298,7 @@ export default function AdminPage() {
<span className="text-sm text-gray-500">{editUser.id}</span>
</div>
<div className="relative">
<label className="block text-sm font-medium text-gray-700 mb-1">
Email (unique):
</label>
<label className="block text-sm font-medium text-gray-700 mb-1">Email (unique):</label>
<input
className="w-full border px-3 py-2 rounded-lg outline-none bg-gray-100 cursor-not-allowed"
type="email"
@ -303,9 +317,7 @@ export default function AdminPage() {
)}
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Name:
</label>
<label className="block text-sm font-medium text-gray-700 mb-1">Name:</label>
<input
className="w-full border px-3 py-2 rounded-lg outline-none focus:ring-2 focus:ring-blue-300"
type="text"
@ -315,9 +327,7 @@ export default function AdminPage() {
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Role:
</label>
<label className="block text-sm font-medium text-gray-700 mb-1">Role:</label>
<select
className="w-full border px-3 py-2 rounded-lg outline-none focus:ring-2 focus:ring-blue-300"
name="role"
@ -325,14 +335,14 @@ export default function AdminPage() {
onChange={handleEditChange}
>
{allRoles.map((role) => (
<option key={role} value={role}>{roleLabels[role]}</option>
<option key={role} value={role}>
{roleLabels[role]}
</option>
))}
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Password:
</label>
<label className="block text-sm font-medium text-gray-700 mb-1">Password:</label>
<input
className="w-full border px-3 py-2 rounded-lg outline-none focus:ring-2 focus:ring-blue-300"
type="text"
@ -352,7 +362,8 @@ export default function AdminPage() {
<button
type="submit"
className={`px-4 py-2 rounded-lg font-semibold transition
${isEditChanged
${
isEditChanged
? "bg-blue-600 hover:bg-blue-700 text-white shadow"
: "bg-gray-300 text-gray-500 cursor-not-allowed"
}`}
@ -364,9 +375,7 @@ export default function AdminPage() {
</form>
</div>
) : (
<div className="text-center text-gray-400 mt-16 text-lg">
Select a user...
</div>
<div className="text-center text-gray-400 mt-16 text-lg">Select a user...</div>
)}
</div>
</div>

View File

@ -1,11 +1,13 @@
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server';
import { PrismaClient } from "@prismaclient";
import { PrismaClient } from '@prismaclient';
const usingPrisma = false;
let prisma: PrismaClient;
if (usingPrisma) prisma = new PrismaClient();
// todo add specification of date range in request
export async function POST(req: Request) {
try {
const json = await req.json();

View File

@ -1,11 +1,14 @@
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server';
import { PrismaClient } from "@prismaclient";
import { PrismaClient } from '@prismaclient';
const usingPrisma = false;
let prisma: PrismaClient;
if (usingPrisma) prisma = new PrismaClient();
// todo remove if (usingPrisma) code
// todo add specification of date range in request
export async function GET(request: Request) {
try {
const events = [

View File

@ -11,6 +11,8 @@ const usingPrisma = false;
let prisma: PrismaClient;
if (usingPrisma) prisma = new PrismaClient();
// todo remove if (usingPrisma) code
export async function POST(req: Request) {
try {
const { email, password, name } = await req.json(); // Parse incoming JSON data
@ -18,6 +20,7 @@ export async function POST(req: Request) {
const userData = await readUserCsv();
// todo remove console logs
console.log(userData);
console.log("Name:", name); // ! remove
console.log("Email:", email); // ! remove

View File

@ -1,13 +1,16 @@
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server';
import { PrismaClient } from "@prismaclient";
import { env } from "@utils/env";
import { verifyJwt } from "@utils/verifyJwt";
import { PrismaClient } from '@prismaclient';
import { env } from '@utils/env';
import { verifyJwt } from '@utils/verifyJwt';
const usingPrisma = false;
let prisma: PrismaClient;
if (usingPrisma) prisma = new PrismaClient();
// todo remove if (usingPrisma) code
// todo add specification of date range in request
// Artefact type
interface Artefact {
id: number;

View File

@ -1,11 +1,12 @@
"use client";
import { useState, useEffect } from "react";
import { useStoreActions } from "@hooks/store";
import axios, { AxiosError } from "axios";
import { useRouter } from "next/navigation";
import { User } from "@appTypes/Prisma";
import { FaSignOutAlt } from "react-icons/fa";
import { FaUser } from "react-icons/fa6";
import axios, { AxiosError } from 'axios';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { FaSignOutAlt } from 'react-icons/fa';
import { FaUser } from 'react-icons/fa6';
import { User } from '@appTypes/Prisma';
import { useStoreActions } from '@hooks/store';
export default function Profile() {
const router = useRouter();
@ -50,6 +51,8 @@ export default function Profile() {
}
setIsSubmitting(true);
try {
// todo create receiving api route
// todo handle sending fields to api route
await new Promise((resolve) => setTimeout(resolve, 500));
setUserState({ ...user!, name, email, role });
alert("Profile updated successfully.");

View File

@ -1,10 +1,10 @@
"use client";
import Image from "next/image";
import { Dispatch, SetStateAction, useCallback, useState } from "react";
import Image from 'next/image';
import { Dispatch, SetStateAction, useCallback, useState } from 'react';
import Artefact from "@appTypes/Artefact";
import { Currency } from "@appTypes/StoreModel";
import { useStoreState } from "@hooks/store";
import Artefact from '@appTypes/Artefact';
import { Currency } from '@appTypes/StoreModel';
import { useStoreState } from '@hooks/store';
// Artefacts Data
const artefacts: Artefact[] = [
@ -322,6 +322,10 @@ export default function Shop() {
setError("CVC must be 3 or 4 digits.");
return;
}
// todo create receiving api route
// todo handle sending to api route
// todo remove order number generation - we don't need one
// todo add option to save details in new account
const genOrder = () => "#" + Math.random().toString(36).substring(2, 10).toUpperCase();
setOrderNumber(genOrder());
onClose();

View File

@ -1,8 +1,8 @@
"use client";
import { Dispatch, SetStateAction, useMemo, useState } from "react";
import { FaTimes } from "react-icons/fa";
import { FaCalendarPlus, FaCartShopping, FaWarehouse } from "react-icons/fa6";
import { IoFilter, IoFilterCircleOutline, IoFilterOutline, IoToday } from "react-icons/io5";
import { Dispatch, SetStateAction, useMemo, useState } from 'react';
import { FaTimes } from 'react-icons/fa';
import { FaCalendarPlus, FaCartShopping, FaWarehouse } from 'react-icons/fa6';
import { IoFilter, IoFilterCircleOutline, IoFilterOutline, IoToday } from 'react-icons/io5';
// import { Artefact } from "@appTypes/Prisma";
@ -275,6 +275,8 @@ function LogModal({ onClose }: { onClose: () => void }) {
}
setIsSubmitting(true);
try {
// todo create receiving api route
// todo handle sending fields to api route
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call
alert(`Logged ${name} to storage: ${storageLocation}`);
onClose();
@ -406,6 +408,8 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
};
const handleLog = async () => {
// todo create receiving api route
// todo handle sending fields to api route
if (!palletNote || !storageLocation) {
setError("All fields are required.");
return;
@ -504,6 +508,8 @@ function EditModal({ artefact, onClose }: { artefact: Artefact; onClose: () => v
const [error, setError] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
// todo add image display
const handleOverlayClick = (e: { target: any; currentTarget: any }) => {
if (e.target === e.currentTarget) {
onClose();

View File

@ -50,6 +50,7 @@ export default function Sidebar({
button1Name,
button2Name,
}: SidebarProps) {
// todo add buttons 1 and 2 click handlers
return (
<div className={`flex flex-col h-full w-80 relative bg-gradient-to-b from-neutral-100 to-neutral-50 shadow-lg`}>
<div className="py-6">