Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

메인페이지 기능 구현 완료 #59

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move: 폴더 구조 변경
  • Loading branch information
hb9901 committed Jul 30, 2024
commit 025e62f0f3081b0e8fdec8aa7fd389f07b358874

This file was deleted.

41 changes: 38 additions & 3 deletions src/app/(providers)/(root)/[workspaceId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
const HomePage = () => {
return <main>hello!</main>;
'use client';
import useWorkspaceUser from '@/hooks/useWorkspaceUser';
import useUserStore from '@/store/userStore';
import { useShallow } from 'zustand/react/shallow';
import Header from './_components/Header';
import HomeMemberCard from './_components/HomeMemberCard';
import MemberExistComponent from './_components/MemberExistComponent';
import MemberNotExistComponent from './_components/MemberNotExistComponent';

const Homepage = () => {
const userInfo = {
name: '이름',
position: 'Position',
status: 'Status'
};
const workspaceUserList = [];

const { workspaceUserId, workspaceList } = useUserStore(
useShallow((state) => ({
workspaceUserId: state.workspaceUserId,
workspaceList: state.workspaceList
}))
);
console.log(workspaceUserId);
const { workspaceUser } = useWorkspaceUser(workspaceUserId);
console.log(workspaceUser);
if (!workspaceUser) return;
return (
<div>
<Header />
<main className="px-[16px] mt-[26px]">
<HomeMemberCard name={workspaceUser.name} position={workspaceUser.position} status={workspaceUser.state} />

{workspaceUserList.length === 0 ? <MemberNotExistComponent /> : <MemberExistComponent />}
</main>
</div>
);
};

export default HomePage;
export default Homepage;
12 changes: 6 additions & 6 deletions src/app/(providers)/(root)/auth/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';
import useShallowSelector from '@/hooks/useShallowSelector';
import { useAuthStore } from '@/providers/AuthStoreProvider';
import { AuthStoreTypes } from '@/store/authStore';
import useUserStore from '@/store/userStore';
import { supabase } from '@/utils/supabase/supabaseClient';
import { useMutation } from '@tanstack/react-query';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import BackButton from '../_components/BackButton';
import useShallowSelector from '@/hooks/useShallowSelector';
import { AuthStoreTypes } from '@/store/authStore';
import { useAuthStore } from '@/providers/AuthStoreProvider';
import useUserStore from '@/store/userStore';

type UserType = {
user: AuthStoreTypes['user'];
Expand Down Expand Up @@ -58,7 +58,7 @@ const LoginPage = () => {
}

setUserData(session.user.id, workspaceUserData.workspace_id);
route.push('/home'); // TODO : 메인 홈 으로 이동
route.push(`/${workspaceUserData.workspace_id}`); // TODO : 메인 홈 으로 이동
}
});

Expand All @@ -67,7 +67,7 @@ const LoginPage = () => {
useEffect(() => {
if (user) {
// alert('이미 로그인 중입니다.');
route.push('/home'); // TODO : 메인 홈 화면 이동 변경
// route.push('/home'); // TODO : 메인 홈 화면 이동 변경
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StrictPropsWithChildren } from '@/types/common';
import { useEffect } from 'react';
import { useShallow } from 'zustand/react/shallow';

const HomeLayout = ({ children }: StrictPropsWithChildren) => {
const RootLayout = ({ children }: StrictPropsWithChildren) => {
const { userId, workspaceId, setWorkspaceData } = useUserStore(
useShallow((state) => ({
userId: state.userId,
Expand All @@ -27,4 +27,4 @@ const HomeLayout = ({ children }: StrictPropsWithChildren) => {
return <>{children}</>;
};

export default HomeLayout;
export default RootLayout;
2 changes: 1 addition & 1 deletion src/app/api/workspace-list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const GET = async (request: NextRequest) => {
const workspaceList = workspaceListData?.map((workspace) => {
const workspaceUserId = workspace.id;
const workspaceInfo = workspace.workspace_id;
console.log(workspace, workspaceInfo, workspaceListData);
// console.log(workspace, workspaceInfo, workspaceListData);
return { workspace_user_id: workspaceUserId, ...workspaceInfo };
});
const data = {
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useWorkspaceUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import api from '@/api/api';
import { Tables } from '@/types/supabase';
import { useMutation, useQuery } from '@tanstack/react-query';

const FAKE_WORKSPACE_USER_ID = '9f144ad8-59c1-4da1-be3d-e9e1c207eddb';

const useWorkspaceUser = () => {
const useWorkspaceUser = (userId: string) => {
const {
data: workspaceUser,
isPending,
isError
} = useQuery({
queryKey: ['workspaceUser'],
queryFn: () => api.workspaceUser.getWorkspaceUser(FAKE_WORKSPACE_USER_ID)
queryFn: () => api.workspaceUser.getWorkspaceUser(userId)
});

const { mutateAsync: updateWorkspaceUser } = useMutation({
Expand Down