From 01e7f8ced7b20fe0174f1f0832e706d8cb86600d Mon Sep 17 00:00:00 2001 From: bacpactech Date: Thu, 19 Dec 2024 17:09:58 +0530 Subject: [PATCH] fix: userProfileCard --- .../organisms/ProfileCard/index.tsx | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/components/organisms/ProfileCard/index.tsx b/src/components/organisms/ProfileCard/index.tsx index e6955a6..16ecc2c 100644 --- a/src/components/organisms/ProfileCard/index.tsx +++ b/src/components/organisms/ProfileCard/index.tsx @@ -2,15 +2,12 @@ import Card from '@/components/atoms/Card' import avatar from '@assets/avatar.svg' import Image from 'next/image' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover' -//import { Badge } from "@/components/ui/badge"; -//import { Button } from "@/components/ui/button"; import { FaGraduationCap, FaEnvelope, FaPhone, FaMapMarkerAlt, FaBirthdayCake } from 'react-icons/fa' import { ImEarth } from 'react-icons/im' import { HiDotsHorizontal, HiPencilAlt } from 'react-icons/hi' import badge from '@assets/badge.svg' import useDeviceType from '@/hooks/useDeviceType' import { format } from 'date-fns' -import { ModalContentType } from '@/types/global' import { useUniStore } from '@/store/store' import { useToggleFollow } from '@/services/connection' import { IoIosShareAlt } from 'react-icons/io' @@ -19,7 +16,14 @@ import { IoFlagOutline } from 'react-icons/io5' import { RiMessage2Fill } from 'react-icons/ri' import { FaCalendarCheck } from 'react-icons/fa6' import { MdSubject } from 'react-icons/md' +import { FaCamera } from 'react-icons/fa' import Buttons from '@/components/atoms/Buttons' +import { useEditProfile } from '@/services/edit-profile' +import { replaceImage } from '@/services/uploadImage' +import { ChangeEvent } from 'react' +import { openModal } from '@/components/molecules/Modal/ModalManager' +import EditProfileModal from '@/components/Timeline/Modals/EditProfileModal' +import ConnectionsModal from '@/components/Timeline/Modals/ConnectionsModal' interface UserProfileCardProps { name: string @@ -39,18 +43,16 @@ interface UserProfileCardProps { isVerifiedUniversity: boolean degree: string country: string - setModalContentType: React.Dispatch> - setIsModalOpen: React.Dispatch> isSelfProfile?: boolean userId?: string universityLogo: string occupation: string affiliation: string - handleShowModal: (value: string) => void } export function UserProfileCard({ name, + isPremium, description, university, isVerified, @@ -66,27 +68,32 @@ export function UserProfileCard({ avatarUrl, isVerifiedUniversity, country, - setModalContentType, - setIsModalOpen, + isSelfProfile, userId, universityLogo, occupation, affiliation, - handleShowModal, }: UserProfileCardProps) { const { isDesktop } = useDeviceType() const { userProfileData } = useUniStore() const { mutate: toggleFollow } = useToggleFollow('Following') + const { mutate: mutateEditProfile, isPending } = useEditProfile() const userFollowingIDs = userProfileData && userProfileData?.following?.map((following) => following.userId) - const handleOpenModal = (modalType: ModalContentType) => { - setModalContentType(modalType) - setIsModalOpen(true) - handleShowModal(modalType || '') - } + const handleImageUpload = async (e: ChangeEvent) => { + const files = e.target.files + if (files && files[0]) { + const data: any = await replaceImage(files[0], userProfileData?.profile_dp?.publicId) + + const dataToPush = { profile_dp: { imageUrl: data?.imageUrl, publicId: data?.publicId } } + mutateEditProfile(dataToPush) + } else { + console.error('No file selected.') + } + } return (
@@ -98,6 +105,14 @@ export function UserProfileCard({ height={isDesktop ? 126 : 90} className="rounded-full object-cover lg:w-[126px] lg:h-[126px] w-[90px] h-[90px]" /> + {isSelfProfile && ( +
+ handleImageUpload(e)} /> + +
+ )}
@@ -107,7 +122,7 @@ export function UserProfileCard({
{isSelfProfile ? (
handleOpenModal('EditProfileModal')} + onClick={() => openModal()} className="flex gap-2 items-center text-2xs lg:text-xs text-primary-500 cursor-pointer" > @@ -155,10 +170,10 @@ export function UserProfileCard({ {isVerifiedUniversity && {name}}
- handleOpenModal('ConnectionsModal')} className=" text-xs lg:text-sm cursor-pointer"> + openModal()} className=" text-xs lg:text-sm cursor-pointer"> {following || '0'} Following - handleOpenModal('ConnectionsModal')} className=" text-xs lg:text-sm cursor-pointer"> + openModal()} className=" text-xs lg:text-sm cursor-pointer"> {followers || '0'} Followers