Skip to content

Commit

Permalink
Merge pull request #31 from 4bujak-4bujak/refactor/meetingroom
Browse files Browse the repository at this point in the history
fix: 미팅룸 관련 오류 수정
  • Loading branch information
jiohjung98 authored Jun 7, 2024
2 parents b375817 + 1f8c61f commit 86b7604
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
30 changes: 26 additions & 4 deletions src/components/home/CurrentOffice.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, useEffect } from 'react';
import SearchModal from './SearchModal';
import SelectOfficeMap from './SelectOfficeMap';
Expand All @@ -9,6 +10,27 @@ const CurrentOffice = () => {
const [showSelectOfficeMap, setShowSelectOfficeMap] = useState(false);
const selectedBranch = useBranchStore((state) => state.selectedBranch);
const setSelectedBranch = useBranchStore((state) => state.setSelectedBranch);
const [isHydrated, setIsHydrated] = useState(false);

const initialBranch: Branch = {
branchId: 27,
branchName: '강남1호점',
branchAddress: '서울 강남구 강남대로 382 메리츠타워 17, 18층 (메인라운지 17층)',
branchLatitude: 37.4971261,
branchLongitude: 127.0287132,
};

useEffect(() => {
setIsHydrated(true);

if (!selectedBranch) {
setSelectedBranch(initialBranch, Date.now());
}
}, [selectedBranch, setSelectedBranch]);

useEffect(() => {
console.log('Current selectedBranch:', selectedBranch);
}, [selectedBranch]);

const handleBranchSelect = (branch: Branch) => {
setSelectedBranch(branch, Date.now());
Expand All @@ -24,9 +46,9 @@ const CurrentOffice = () => {
setShowSelectOfficeMap(false);
};

useEffect(() => {
console.log('Selected Branch Updated:', selectedBranch);
}, [selectedBranch]);
if (!isHydrated) {
return null;
}

return (
<>
Expand All @@ -37,7 +59,7 @@ const CurrentOffice = () => {
<img src="/home/location.svg" alt="" />
</div>
<div className="text-white text-lg underline font-medium cursor-pointer" onClick={handleSearchClick}>
{selectedBranch ? selectedBranch.branchName : '지점을 설정해주세요'}
{selectedBranch?.branchName}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/BranchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const BranchModal: React.FC<ModalProps> = ({ isOpen, onClose, branchName, branch
try {
const data = await getSelectedOfficeInfo(branchName);
if (data.data) {
setReservedBranch(data.data, Date.now());
setReservedBranch(data?.data, Date.now());
router.push('/reservation/');
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/reservation/meetingRoom/MeetingRoomIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ const MeetingRoomIndex: React.FC = () => {
const updatedTimeReserved = useBranchStore2((state) => state.updatedTimeReserved);

const currentBranch =
updatedTimeSelected && updatedTimeReserved && updatedTimeSelected > updatedTimeReserved
? selectedBranch
: reservedBranch;
updatedTimeSelected && updatedTimeReserved && updatedTimeSelected > updatedTimeReserved
? selectedBranch
: reservedBranch || selectedBranch;

useEffect(() => {
if (!currentBranch) return;
Expand Down
14 changes: 6 additions & 8 deletions src/components/reservation/shared/CurrentRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ const CurrentRoom = () => {
}, [reservedBranch]);

const currentBranch =
selectedUpdatedTime &&
reservedUpdatedTime &&
selectedUpdatedTime > reservedUpdatedTime
? selectedBranch
: reservedBranch;

// const currentBranch = selectedBranch;
selectedUpdatedTime &&
reservedUpdatedTime &&
selectedUpdatedTime > reservedUpdatedTime
? selectedBranch
: reservedBranch || selectedBranch;

return (
<>
Expand All @@ -69,7 +67,7 @@ const CurrentRoom = () => {
<img src="/reservation/location.svg" alt="location icon" />
</div>
<div className="text-space-black font-semibold text-sm">
{currentBranch ? currentBranch.branchName : '강남1호점'}
{currentBranch?.branchName}
</div>
<div>
<img src="/reservation/toBottom.svg" alt="dropdown icon" />
Expand Down
13 changes: 9 additions & 4 deletions src/store/branch.store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// branch.store.ts
/* eslint-disable no-unused-vars */
import { create } from 'zustand';
import { Branch } from '@/api/types/branch';
import { persist } from 'zustand/middleware';
import { Branch } from '@/api/types/branch';

interface BranchStore {
selectedBranch: Branch | null;
Expand All @@ -14,12 +13,18 @@ export const useBranchStore = create(
persist<BranchStore>(
(set) => ({
selectedBranch: null,
setSelectedBranch: (branch: Branch | null, time: number) =>
set({ selectedBranch: branch, updatedTimeSelected: time }),
setSelectedBranch: (branch: Branch | null, time: number) => {
console.log('Setting selectedBranch:', branch);
set({ selectedBranch: branch, updatedTimeSelected: time });
},
updatedTimeSelected: null,
}),
{
name: 'selectedBranch',
getStorage: () => localStorage,
onRehydrateStorage: () => (state) => {
console.log('Rehydrated state:', state);
},
}
)
);

0 comments on commit 86b7604

Please sign in to comment.