(null);
+
+ // Initialize formData when data is loaded
+ useEffect(() => {
+ if (data && data.length > 0 && data[0]) {
+ setFormData(data[0]);
+ }
+ }, [data]);
+
+ if (isLoading) {
+ return Loading...
;
+ }
+
+ if (error ?? !formData) {
+ return (
+ Error loading user data. Please check the URL and try again.
+ );
+ }
+
+ // Handle input changes
+ const handleChange = (e: React.ChangeEvent) => {
+ const { name, value, type, checked } = e.target;
+ setFormData((prev) => {
+ if (!prev) return null;
-export default function Page() {
- const params = useParams() as unknown as Params; // Correct type casting
- const { id } = params;
+ const updatedProfile = {
+ ...prev.profile,
+ [name]: type === "checkbox" ? checked : value ?? "",
+ };
+
+ return {
+ ...prev,
+ profile: {
+ ...prev.profile,
+ firstName: updatedProfile.firstName ?? prev.profile?.firstName ?? "",
+ lastName: updatedProfile.lastName ?? prev.profile?.lastName ?? "",
+ },
+ };
+ });
+ };
+
+ // Handle form submission
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ // Implementation for form submission goes here
+ };
return (
Uređivanje volontera {id}
+
+ Uređivanje volontera {formData.profile?.firstName}{" "}
+ {formData.profile?.lastName}
+
}
>
- {/* form */}
+
);
}
diff --git a/src/app/users/page.tsx b/src/app/users/page.tsx
index c5c5ae2..613d5f1 100644
--- a/src/app/users/page.tsx
+++ b/src/app/users/page.tsx
@@ -1,4 +1,5 @@
"use client";
+import { useEffect, useState } from "react";
import MainLayout from "~/components/layout/mainLayout";
import { api } from "~/trpc/react";
import {
@@ -15,28 +16,25 @@ import {
PaginationContent,
PaginationPages,
} from "~/components/organisms/Pagination";
-import { useState, useEffect } from "react";
import LoadingSpinner from "~/components/organisms/loadingSpinner/LoadingSpinner";
import SearchInput from "~/components/atoms/SearchInput";
import { useDebounce } from "@uidotdev/usehooks";
-import { useRouter } from "next/navigation";
+import Link from "next/link";
-// Define the types for user and API response
interface UserProfile {
firstName: string;
lastName: string;
}
-interface FindUserReturnDTO {
+export interface FindUserReturnDTO {
id: string;
email: string;
active: boolean | null;
profile: UserProfile | null;
- createdAt: Date;
+ createdAt?: Date;
}
const Users = () => {
- const router = useRouter();
const [page, setPage] = useState(0);
const [totalPageNumber, setTotalPageNumber] = useState(1);
const [filter, setFilter] = useState | undefined>(
@@ -62,10 +60,6 @@ const Users = () => {
setPage(0);
};
- const handleEditClick = (user: FindUserReturnDTO) => {
- router.push(`/users/${user.id}`);
- };
-
return (
Pretraživanje i odabir volontera}>
@@ -121,11 +115,14 @@ const Users = () => {
)}