diff --git a/app/api/profiles/[id]/route.ts b/app/api/profiles/[id]/route.ts index b211917d..218601c5 100644 --- a/app/api/profiles/[id]/route.ts +++ b/app/api/profiles/[id]/route.ts @@ -9,17 +9,21 @@ export async function GET( const params = await context.params; const { id } = params; - // Find the user by ID const user = await prisma.user.findUnique({ where: { id }, select: { id: true, name: true, email: true, - image: true, - gender: true, - description: true, createdAt: true, + profile: { + include: { + intellectualInterests: { include: { interest: true } }, + causeAreas: { include: { causeArea: true } }, + desiredConnections: { include: { connection: true } }, + promptAnswers: true, + }, + }, }, }); @@ -31,6 +35,8 @@ export async function GET( }); } + console.log("Fetched user profile:", user); + return new NextResponse(JSON.stringify(user), { status: 200, headers: { "Content-Type": "application/json" }, diff --git a/app/api/profiles/route.ts b/app/api/profiles/route.ts index 0415f11a..3fc427d6 100644 --- a/app/api/profiles/route.ts +++ b/app/api/profiles/route.ts @@ -1,5 +1,6 @@ import { prisma }from "@/lib/prisma"; import { NextResponse } from "next/server"; +import {getSession} from "@/lib/auth"; export async function GET(request: Request) { const url = new URL(request.url); @@ -7,12 +8,50 @@ export async function GET(request: Request) { const profilesPerPage = 20; const offset = (page - 1) * profilesPerPage; + const session = await getSession(); + console.log(`Session: ${session?.user?.name}`); + // Fetch paginated posts const profiles = await prisma.user.findMany({ skip: offset, take: profilesPerPage, orderBy: { createdAt: "desc" }, - // include: { author: { select: { name: true } } }, + where: { id: {not: session?.user?.id} }, + select: { + id: true, + name: true, + email: true, + createdAt: true, + profile: { + include: { + intellectualInterests: { include: { interest: true } }, + causeAreas: { include: { causeArea: true } }, + desiredConnections: { include: { connection: true } }, + promptAnswers: true, + }, + }, + }, + // where: { + // id: { + // not: session?.user?.id, // Exclude the logged-in user + // gender: 'FEMALE', + // intellectualInterests: { + // some: { + // interest: { name: 'Philosophy' } + // } + // }, + // causeAreas: { + // some: { + // causeArea: { name: 'AI Safety' } + // } + // } + // }, + // include: { + // user: true, + // intellectualInterests: { include: { interest: true } }, + // causeAreas: { include: { causeArea: true } } + // } + // }, }); const totalProfiles = await prisma.user.count(); diff --git a/app/api/user/update-profile/route.ts b/app/api/user/update-profile/route.ts index f5f75ef5..d7546422 100644 --- a/app/api/user/update-profile/route.ts +++ b/app/api/user/update-profile/route.ts @@ -13,33 +13,28 @@ export async function POST(req: Request) { ); } - const {description, gender, image} = await req.json(); - console.log(`Req: ${description}, ${gender}, ${image}`) - - // Validate required fields - if (!gender) { - return NextResponse.json( - {error: "Gender is required"}, - {status: 400} - ); - } + const data = await req.json(); + console.log(`Req: ${data}`) // Update user with the new profile information const updatedUser = await prisma.user.update({ where: {email: session.user.email}, data: { - description: description || null, - gender: gender || null, - ...(image && { image }), // Only update image if provided - }, - select: { - id: true, - email: true, - name: true, - description: true, - gender: true, - image: true, + ...(data.image && { image: data.image }), + profile: { + upsert: { + create: data.profile, + update: data.profile, + }, + }, }, + // , // Only update image if provided + // select: { + // id: true, + // email: true, + // name: true, + // image: true, + // }, }); return NextResponse.json(updatedUser); diff --git a/app/complete-profile/page.tsx b/app/complete-profile/page.tsx index 5404a19b..bfb2e021 100644 --- a/app/complete-profile/page.tsx +++ b/app/complete-profile/page.tsx @@ -1,13 +1,18 @@ 'use client'; -import { useState, useRef, ChangeEvent, useEffect } from 'react'; -import { useRouter } from 'next/navigation'; -import { useSession } from 'next-auth/react'; +import {ChangeEvent, useEffect, useRef, useState} from 'react'; +import {useRouter} from 'next/navigation'; +import {useSession} from 'next-auth/react'; import Image from 'next/image'; +import {ConflictStyle, Gender, PersonalityType} from "@prisma/client"; export default function CompleteProfile() { const [description, setDescription] = useState(''); + const [contactInfo, setContactInfo] = useState(''); + const [location, setLocation] = useState(''); const [gender, setGender] = useState(''); + const [personalityType, setPersonalityType] = useState(''); + const [conflictStyle, setConflictStyle] = useState(''); const [image, setImage] = useState(null); const [key, setKey] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); @@ -15,7 +20,22 @@ export default function CompleteProfile() { const [error, setError] = useState(''); const fileInputRef = useRef(null); const router = useRouter(); - const { data: session, update } = useSession(); + const {data: session, update} = useSession(); + + // const [selected, setSelected] = useState(new Set(selectedInterests)); + // + // const toggleInterest = (interestId) => { + // setSelected((prev) => { + // const newSet = new Set(prev); + // newSet.has(interestId) ? newSet.delete(interestId) : newSet.add(interestId); + // return newSet; + // }); + // }; + + // const handleInterestSubmit = (e) => { + // e.preventDefault(); + // onSave(Array.from(selected)); // send to API + // }; const handleImageUpload = async (e: ChangeEvent) => { const file = e.target.files?.[0]; @@ -39,7 +59,7 @@ export default function CompleteProfile() { try { setIsUploading(true); setError(''); - + const response = await fetch('/api/upload', { method: 'POST', body: formData, @@ -51,7 +71,7 @@ export default function CompleteProfile() { return; } - const { url, key } = await response.json(); + const {url, key} = await response.json(); setImage(url); setKey(key); } catch (error) { @@ -64,7 +84,7 @@ export default function CompleteProfile() { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - + if (!gender) { setError('Please select your gender'); return; @@ -75,9 +95,15 @@ export default function CompleteProfile() { setError(''); const body = JSON.stringify({ - description, - gender, - ...(key && { image: key }), + profile: { + description, + contactInfo, + location, + gender, + personalityType, + conflictStyle, + }, + ...(key && {image: key}), }); console.log(`Body: ${body}`) // alert(body) @@ -97,7 +123,7 @@ export default function CompleteProfile() { // Update the session to reflect the changes await update(); - + // Redirect to the home page or dashboard router.push('/'); } catch (error) { @@ -115,6 +141,21 @@ export default function CompleteProfile() { } }, [session]); + const genderOptions = Object.values(Gender); + const personalityOptions = Object.values(PersonalityType); + const conflictOptions = Object.values(ConflictStyle); + + // const answers = [ + // { + // prompt: 'What is your favorite color?', + // answer: 'Blue', + // }, + // { + // prompt: 'What is your favorite animal?', + // answer: 'Dog', + // } + // ] + return (
@@ -122,17 +163,17 @@ export default function CompleteProfile() {

Complete Your Profile

- {/*

*/} - {/* Help us know you better (this information can be updated later)*/} - {/*

*/}
- + {error && (
- - + +
@@ -167,7 +208,9 @@ export default function CompleteProfile() { title="Upload photo" > - +
-
+
+
+
+ +