From 5c4ed84dc72e8a7c6a37beab575657e7792891b2 Mon Sep 17 00:00:00 2001 From: Aamil13 Date: Thu, 12 Dec 2024 12:13:56 +0530 Subject: [PATCH] sort, api fail on reload, zustand store remove on logout, logout hook --- .../[communityId]/[groupId]/page.tsx | 2 +- .../communityGroup/[group_id]/page.tsx | 5 -- src/app/(withLayout)/messages/old_page.tsx | 49 -------------- src/app/(withLayout)/profile/[...id]/page.tsx | 7 +- src/app/(withLayout)/profile/page.tsx | 64 ------------------- src/app/post/[id]/page.tsx | 6 +- src/components/Navbar/Navbar.tsx | 3 +- .../Timeline/Modals/EditProfileModal.tsx | 6 +- src/components/Timeline/ProfileCard.tsx | 6 +- src/components/atoms/LogoNavbar/index.tsx | 14 ++-- .../communityUniversity/GroupInfo.tsx | 12 ++-- .../communityUniversity/HeroSec.tsx | 12 ++-- src/components/messages/MessageSideBar.tsx | 24 +++---- .../messages/UserMessageContainer.tsx | 6 +- .../molecules/CommunityGroupBanner/index.tsx | 12 ++-- .../molecules/CommunityGroupFilter/index.tsx | 5 +- .../molecules/MessageNotification/index.tsx | 4 +- .../molecules/NavbarUniversityItem/index.tsx | 44 +++++++++++-- .../molecules/NewPostComment/index.tsx | 4 +- src/components/molecules/PostCard/index.tsx | 4 +- .../molecules/PostCommentBox/index.tsx | 2 +- .../molecules/UniversityCard/index.tsx | 2 +- .../molecules/UserMessages/index.tsx | 4 +- .../CommunityGroupPostContainer/index.tsx | 22 ++++++- src/components/organisms/LeftNavbar/index.tsx | 12 ++-- .../organisms/MessageContainer/index.tsx | 20 +++--- .../SettingTabs/SettingAccount.tsx | 19 +++++- src/components/organisms/UserChats/index.tsx | 22 +++---- src/hooks/useLogOut.ts | 21 ++++++ src/middleware.ts | 2 +- src/services/edit-profile.ts | 2 +- src/services/university-community.ts | 2 +- src/store/store.ts | 26 ++++++-- src/store/storeType.ts | 7 +- .../userProfileSlice/userProfileSlice.ts | 7 +- src/store/userSlice/userSlice.ts | 6 +- src/types/CommuityGroup/index.ts | 2 + src/utils/ZustandSocketProvider.tsx | 15 +++-- 38 files changed, 235 insertions(+), 247 deletions(-) delete mode 100644 src/app/(withLayout)/communityGroup/[group_id]/page.tsx delete mode 100644 src/app/(withLayout)/messages/old_page.tsx delete mode 100644 src/app/(withLayout)/profile/page.tsx create mode 100644 src/hooks/useLogOut.ts diff --git a/src/app/(withLayout)/community/[communityId]/[groupId]/page.tsx b/src/app/(withLayout)/community/[communityId]/[groupId]/page.tsx index 663d9065..620a9bd1 100644 --- a/src/app/(withLayout)/community/[communityId]/[groupId]/page.tsx +++ b/src/app/(withLayout)/community/[communityId]/[groupId]/page.tsx @@ -18,7 +18,7 @@ export default function Page({ params }: { params: { communityId: string; groupI isGroupAdmin={isGroupAdmin} setIsGroupAdmin={setIsGroupAdmin} /> - {isGroupAdmin && } + ) diff --git a/src/app/(withLayout)/communityGroup/[group_id]/page.tsx b/src/app/(withLayout)/communityGroup/[group_id]/page.tsx deleted file mode 100644 index 36ef33be..00000000 --- a/src/app/(withLayout)/communityGroup/[group_id]/page.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react' - -export default function CommunityGroup() { - return
CommunityGroup
-} diff --git a/src/app/(withLayout)/messages/old_page.tsx b/src/app/(withLayout)/messages/old_page.tsx deleted file mode 100644 index d496749d..00000000 --- a/src/app/(withLayout)/messages/old_page.tsx +++ /dev/null @@ -1,49 +0,0 @@ -'use client' -import MessageSideBar from '@/components/messages/MessageSideBar' -import UserMessageContainer from '@/components/messages/UserMessageContainer' -import { useUpdateMessageIsSeen } from '@/services/Messages' -import { useUniStore } from '@/store/store' -import { Chat } from '@/types/constants' -import React, { useEffect, useState } from 'react' - -const ChatScreen = () => { - const [selectedChat, setSelectedChat] = useState(undefined) - - const { userData } = useUniStore() - const userName = selectedChat?.users?.find((item) => item?.userId._id !== userData.id) - - const { mutate: updateIsSeen } = useUpdateMessageIsSeen() - const [isRequest, setIsRequest] = useState(true) - - const updateMessageSeen = () => { - const isRead = selectedChat?.latestMessage?.readByUsers?.includes(userData.id || '') - - if (!isRead && isRead !== undefined && selectedChat) { - updateIsSeen({ chatId: selectedChat?._id, messageId: selectedChat?.latestMessage?._id, data: { readByUserId: userData.id } }) - } - } - - useEffect(() => { - updateMessageSeen() - }, [selectedChat]) - - return ( -
-
- - {selectedChat?._id && ( - - )} -
-
- ) -} - -export default ChatScreen diff --git a/src/app/(withLayout)/profile/[...id]/page.tsx b/src/app/(withLayout)/profile/[...id]/page.tsx index 66316f2e..da121d77 100644 --- a/src/app/(withLayout)/profile/[...id]/page.tsx +++ b/src/app/(withLayout)/profile/[...id]/page.tsx @@ -1,19 +1,14 @@ 'use client' -import Spinner from '@/components/atoms/spinner' import { openModal } from '@/components/molecules/Modal/ModalManager' import ProfilePostContainer from '@/components/organisms/PostsContainer' -import PostContainer from '@/components/organisms/PostsContainer' import { UserProfileCard } from '@/components/organisms/ProfileCard' -import Modal from '@/components/Timeline/Modal' import ConnectionsModal from '@/components/Timeline/Modals/ConnectionsModal' import EditProfileModal from '@/components/Timeline/Modals/EditProfileModal' -import ProfileCard from '@/components/Timeline/ProfileCard' import { Skeleton } from '@/components/ui/Skeleton' import { useCheckSelfProfile } from '@/lib/utils' import { useGetUserData } from '@/services/user' -import { PostType } from '@/types/constants' import { ModalContentType } from '@/types/global' -import React, { useEffect, useRef, useState } from 'react' +import React, { useRef, useState } from 'react' export default function Profile({ params }: { params: { id: string } }) { const userId = params.id[0] diff --git a/src/app/(withLayout)/profile/page.tsx b/src/app/(withLayout)/profile/page.tsx deleted file mode 100644 index 7ef575fc..00000000 --- a/src/app/(withLayout)/profile/page.tsx +++ /dev/null @@ -1,64 +0,0 @@ -'use client' - -import PostContainer from '@/components/organisms/PostsContainer' -import { UserProfileCard } from '@/components/organisms/ProfileCard' -import TimelinePostContainer from '@/components/organisms/TimelinePostContainer' -import Modal from '@/components/Timeline/Modal' -import ConnectionsModal from '@/components/Timeline/Modals/ConnectionsModal' -import EditProfileModal from '@/components/Timeline/Modals/EditProfileModal' -import ProfileCard from '@/components/Timeline/ProfileCard' -import { useUniStore } from '@/store/store' -import { PostType } from '@/types/constants' -import { ModalContentType } from '@/types/global' -import React, { useState } from 'react' - -export default function Profile() { - const [isModalOpen, setIsModalOpen] = useState(false) - const [modalContentType, setModalContentType] = useState() - const { userData, userProfileData } = useUniStore() - const modalContent = (modalContentType: string) => { - switch (modalContentType) { - case 'EditProfileModal': - return - case 'ConnectionsModal': - return - default: - return null - } - } - const { bio, university_name, university_id, followers, following, study_year, major, phone_number, dob, degree, country } = userProfileData - const { firstName, lastName, email } = userData - return ( -
- {/* setIsModalOpen(false)}> - {modalContentType && modalContent(modalContentType)} - */} - {/* - {modalContentType && modalContent(modalContentType)} - */} - {/* */} - -
- ) -} diff --git a/src/app/post/[id]/page.tsx b/src/app/post/[id]/page.tsx index b07d3b8a..b855584c 100644 --- a/src/app/post/[id]/page.tsx +++ b/src/app/post/[id]/page.tsx @@ -27,9 +27,9 @@ const SinglePost = () => { currImageIndex: null, }) - if (Object.keys(data).length === 0) { - return
Not Allowed
- } + // if (!data || Object.keys(data).length === 0) { + // return
Not Allowed
+ // } if (isError) { return
Not Allowed
diff --git a/src/components/Navbar/Navbar.tsx b/src/components/Navbar/Navbar.tsx index de6b1bf2..21a327a3 100644 --- a/src/components/Navbar/Navbar.tsx +++ b/src/components/Navbar/Navbar.tsx @@ -43,7 +43,7 @@ const Navbar: React.FC = () => { const [hover, setHover] = useState(false) const [activeItem, setActiveItem] = useState('') const [, , deleteCookie] = useCookie('uni_user_token') - const { userProfileData, userData, resetUserData, resetUserProfileData } = useUniStore() + const { userProfileData, userData, resetUserData } = useUniStore() const router = useRouter() const { refetch: refetchNotification } = useGetNotification(3, false) const { data: notificationData } = useGetNotification(3, false) @@ -67,7 +67,6 @@ const Navbar: React.FC = () => { const handleLogout = () => { deleteCookie() resetUserData() - resetUserProfileData() setIsLogin(false) router.push('/login') } diff --git a/src/components/Timeline/Modals/EditProfileModal.tsx b/src/components/Timeline/Modals/EditProfileModal.tsx index 4ca66bcc..02970c23 100644 --- a/src/components/Timeline/Modals/EditProfileModal.tsx +++ b/src/components/Timeline/Modals/EditProfileModal.tsx @@ -51,11 +51,11 @@ const EditProfileModal = () => { formState: { errors }, } = useForm({ defaultValues: { - first_name: userData.firstName, - last_name: userData.lastName, + first_name: userData?.firstName, + last_name: userData?.lastName, bio: userProfileData?.bio, phone_number: userProfileData?.phone_number, - gender: userData.gender, + gender: userData?.gender, dob: userProfileData?.dob ? new Date(userProfileData?.dob).toISOString().split('T')[0] : '', country: userProfileData?.country, city: userProfileData?.city, diff --git a/src/components/Timeline/ProfileCard.tsx b/src/components/Timeline/ProfileCard.tsx index 844e2ebb..c8c4d935 100644 --- a/src/components/Timeline/ProfileCard.tsx +++ b/src/components/Timeline/ProfileCard.tsx @@ -142,7 +142,7 @@ const ProfileCard: React.FC = ({
Profile = ({
-

{userData.firstName}

+

{userData?.firstName}

{userProfileData?.bio}

{!isUserProfile && }
@@ -180,7 +180,7 @@ const ProfileCard: React.FC = ({ /> - + pathname.includes(path)) || pathname === '/' - const { userProfileData, resetUserProfileData } = useUniStore() - const [, , deleteCookie] = useCookie('uni_user_token') + const { userProfileData, userData } = useUniStore() + + const { handleLogout } = useLogout() const [isLogin, setIsLogin] = useState(undefined) const { data: notificationData } = useGetNotification(3, true) const { data: messageNotificationData } = useGetMessageNotification(3, true) const notifications = notificationData?.pages.flatMap((page) => page.notifications) || [] const messageNotifications = messageNotificationData?.pages.flatMap((page) => page.message) || [] const isUserLoggedIn = useCallback(() => { - setIsLogin(!!userProfileData.users_id) + setIsLogin(!!userProfileData?.users_id) }, [userProfileData]) - const handleLogout = () => { - deleteCookie() - resetUserProfileData() - router.push('/login') - } - useEffect(() => { isUserLoggedIn() }, [userProfileData, isUserLoggedIn]) diff --git a/src/components/communityUniversity/GroupInfo.tsx b/src/components/communityUniversity/GroupInfo.tsx index 9595f3d5..bde3e9d8 100644 --- a/src/components/communityUniversity/GroupInfo.tsx +++ b/src/components/communityUniversity/GroupInfo.tsx @@ -93,7 +93,7 @@ const GroupInfo = ({ data, isJoinedinCommunity, setIsJoinedInGroup, isJoinedInGr <> bg
-
+
handleCoverImageUpload(e)} />
@@ -102,7 +102,7 @@ const GroupInfo = ({ data, isJoinedinCommunity, setIsJoinedInGroup, isJoinedInGr ) : ( <>
-
+
handleCoverImageUpload(e)} />
@@ -111,7 +111,7 @@ const GroupInfo = ({ data, isJoinedinCommunity, setIsJoinedInGroup, isJoinedInGr {logoImage ? (
dp -
+
handleLogoImageUpload(e)} />
) : (
-
+
handleLogoImageUpload(e)} />
- {data?.adminUserId?._id == userData.id ? ( + {data?.adminUserId?._id == userData?.id ? ( diff --git a/src/components/communityUniversity/HeroSec.tsx b/src/components/communityUniversity/HeroSec.tsx index ac29c54f..4fd8c52b 100644 --- a/src/components/communityUniversity/HeroSec.tsx +++ b/src/components/communityUniversity/HeroSec.tsx @@ -73,7 +73,7 @@ const HeroSec = ({ data, setIsJoined, isJoined }: any) => { />
handleCoverImageUpload(e)} /> @@ -82,7 +82,7 @@ const HeroSec = ({ data, setIsJoined, isJoined }: any) => { ) : (
-
+
handleCoverImageUpload(e)} />
@@ -111,7 +111,7 @@ const HeroSec = ({ data, setIsJoined, isJoined }: any) => { src={data?.community?.communityLogoUrl.imageUrl} alt="dp" /> -
+
handleLogoImageUpload(e)} />