diff --git a/src/app/(dashboard)/layout.tsx b/src/app/(dashboard)/layout.tsx index b7e1c3e..adc45d1 100644 --- a/src/app/(dashboard)/layout.tsx +++ b/src/app/(dashboard)/layout.tsx @@ -1,10 +1,12 @@ "use client"; import React from 'react'; import Sidebar from '@/components/Sidebar'; +import { Toaster } from 'react-hot-toast'; export default function DashboardLayout({ children }: { children: React.ReactNode }) { return (
+ {/* Mobile Header*/}
@@ -14,7 +16,6 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
Home
-
{/* Desktop Sidebar*/}
diff --git a/src/app/(dashboard)/profile/components/EditProfileComponent.tsx b/src/app/(dashboard)/profile/components/EditProfileComponent.tsx index 95e1181..3878bed 100644 --- a/src/app/(dashboard)/profile/components/EditProfileComponent.tsx +++ b/src/app/(dashboard)/profile/components/EditProfileComponent.tsx @@ -1,14 +1,10 @@ "use client"; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; +import { GetProfileService } from '@/services/profile-services'; +import { MemberProfileDetails } from '@/types/types'; +import toast from 'react-hot-toast'; -type ProfileData = { - name: string; - email: string; - username: string; - bio: string; - profileImage: string; -} type EditProfileProps = { onCancel: () => void; @@ -16,17 +12,29 @@ type EditProfileProps = { export default function EditProfileComponent({ onCancel }: EditProfileProps) { const router = useRouter(); - - const [profileData, setProfileData] = useState({ - name: "John Doe", - email: "johndoe@example.com", - username: "johndoe", - bio: "just a random code to have a profile structure to later code on", - profileImage: "/placeholder.webp" + + const [profileData, setProfileData] = useState({ + memberId:0, + groupId:1, + githubUser:"", + year:1, + name: "", + rollNo: "", + sex: "", + track: "", + email: "", + hostel: '', + discordId: '', + macAddress: '', }); - + const tracks = ['Web', 'Systems', 'AI', 'Mobile']; + + const [isSubmitting, setIsSubmitting] = useState(false); - const [previewUrl, setPreviewUrl] = useState(profileData.profileImage); + const [isLoading, setIsLoading] = useState(true); + const [GenToggle, setGenToggle] = useState([false, false]); + const [previewUrl, setPreviewUrl] = useState("/placeholder.webp"); + const [isUserEnrolling, setUserEnrolling] = useState(false); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; @@ -36,32 +44,57 @@ export default function EditProfileComponent({ onCancel }: EditProfileProps) { }); }; - const handleImageChange = (e: React.ChangeEvent) => { - if (e.target.files && e.target.files[0]) { - const file = e.target.files[0]; - const fileUrl = URL.createObjectURL(file); - setPreviewUrl(fileUrl); - - // You would typically upload the image to your server here - // and then update the profileData with the returned URL - // For this demo, we'll just update the preview + useEffect(()=>{ + async function getProfileDetails() { + const member = await GetProfileService.getProfileDetails(); + if(member){ + setProfileData(member); + const url = await GetProfileService.HandleProfileImage(member); + if(url != "") setPreviewUrl(url); + setGenToggle([member?.sex == "M",member?.sex == "F"]); + setIsLoading(false); + } + else { + setIsLoading(false); + setUserEnrolling(true); + } } - }; + getProfileDetails(); + },[]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsSubmitting(true); - - // Simulate API call - setTimeout(() => { + async function Update() { + let data = await GetProfileService.UpdateProfileDetails(profileData); + if(data){ + setProfileData(data); + handleCancel(); + } + else{ + toast.error("Error in Updating User"); + } setIsSubmitting(false); - // Always redirect back to the main profile page after successful update - router.push('/profile'); - }, 1000); + } + + async function Create() { + let data = await GetProfileService.CreateProfileDetails(profileData); + if(data){ + setProfileData(data); + handleCancel(); + } + else{ + toast.error("Error in Creating User"); + } + setIsSubmitting(false); + } + + !isUserEnrolling ? Update() : Create(); }; const handleCancel = () => { if (onCancel) { + console.log(profileData); onCancel(); } else { // Always navigate to the main profile route @@ -69,103 +102,207 @@ export default function EditProfileComponent({ onCancel }: EditProfileProps) { } }; - return ( + const trackUi: JSX.Element[] = tracks.map((track) => ( + + )); + + if(!isLoading){ + return (
-
-

Edit Profile

- -
-
-
-
- {profileData.name} - -
+ {isUserEnrolling ? ( +

SetUp Profile

+ ) : ( +

Update Profile

+ )} +
+ +
+

Personal Details

+
+
+
+ {profileData.name} +
+
+ +
+
+
+ + +
+
+ +
+ {['Male', 'Female'].map((label, idx) => ( + + ))} +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ +
- +
+
+
+
+
+ +
+

Additional Details

+
- - Hostel +
+
- - Email + +
+
+ +
- - Mac Address +
- -
- -