Skip to content

Commit

Permalink
feat: 메인페이지서 예약하기 클릭 시, 메인페이지의 오피스 예약페이지로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
jiohjung98 committed Jun 10, 2024
1 parent e7bc8c2 commit 481f2c4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/home/AvailableRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import React, { useEffect, useState } from 'react';
import { useQuery, useQueryClient } from 'react-query';
import { getAllAvailableCount } from './remote/mainReservation';
import { useRouter } from 'next/router';
import { getSelectedOfficeInfo } from '@/api/map/getSelectedOffice';
import { useBranchStore2 } from '@/store/reserve.store';

const AvailableRoom = () => {
const router = useRouter();
const queryClient = useQueryClient();
const [currentTime, setCurrentTime] = useState(format(new Date(), 'HH:mm'));
const selectedBranch = useBranchStore((state) => state.selectedBranch);
const { setReservedBranch } = useBranchStore2();

const { data } = useQuery(
['AllAvailableCount', selectedBranch?.branchId],
Expand All @@ -32,6 +35,20 @@ const AvailableRoom = () => {
};
}, []);

const handleGoToReservation = async () => {
try {
const data = await getSelectedOfficeInfo(selectedBranch!.branchName);
if (data.data) {
setReservedBranch(data?.data, Date.now());
router.push({
pathname: '/reservation',
});
}
} catch (error) {
console.error('Error updating selected branch:', error);
}
};

if (!data) {
return null;
}
Expand Down Expand Up @@ -122,8 +139,7 @@ const AvailableRoom = () => {

{/* 하단 */}
<div
onClick={() => router.push('reservation')}
className="cursor-pointer mt-8 rounded-lg w-full h-12 border-2 border-space-purple flex justify-center items-center text-space-purple text-[15px] font-semibold">
className="cursor-pointer mt-8 rounded-lg w-full h-12 border-2 border-space-purple flex justify-center items-center text-space-purple text-[15px] font-semibold" onClick={handleGoToReservation}>
예약하기
</div>
</div>
Expand Down

0 comments on commit 481f2c4

Please sign in to comment.