Skip to content

Commit

Permalink
Merge branch 'fix/hojinerror' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
banhogu committed Jun 10, 2024
2 parents ca59330 + 9cff461 commit 9c94d0a
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 71 deletions.
55 changes: 47 additions & 8 deletions src/components/home/AvailableRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
'use client';
import { useBranchStore } from '@/store/branch.store';
import { format } from 'date-fns';
import React, { useEffect, useState } from 'react';
import { useQuery, useQueryClient } from 'react-query';
import { getAllAvailableCount } from './remote/mainReservation';
import { useRouter } from 'next/router';

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

const { data } = useQuery(
['AllAvailableCount', selectedBranch?.branchId],
() => getAllAvailableCount(selectedBranch?.branchId as number),
{
enabled: !!selectedBranch?.branchId
}
);

useEffect(() => {
const handleVisibilityChange = () => {
Expand All @@ -17,6 +32,10 @@ const AvailableRoom = () => {
};
}, []);

if (!data) {
return null;
}

return (
<div className="pb-10">
{/* 상단 */}
Expand All @@ -26,7 +45,13 @@ const AvailableRoom = () => {
<div>{currentTime} 기준</div>
<div
className="cursor-pointer"
onClick={() => setCurrentTime(format(new Date(), 'HH:mm'))}>
onClick={() => {
queryClient.invalidateQueries([
'AllAvailableCount',
selectedBranch?.branchId
]);
setCurrentTime(format(new Date(), 'HH:mm'));
}}>
<img src="/home/refresh.svg" alt="" />
</div>
</div>
Expand All @@ -41,12 +66,16 @@ const AvailableRoom = () => {
<div className="text-gray-600 text-sm font-normal ">미팅룸</div>
<div className="flex justify-center items-center gap-1">
<div>
<span className="text-space-purple text-[26px] font-medium">1</span>
<span className="text-space-purple text-[26px] font-medium">
{data?.availableMeetingRoomCount}
</span>
</div>
<div>
<img src="/home/slash.svg" alt="" />
</div>
<div className="text-gray-400 font-medium text-base">30</div>
<div className="text-gray-400 font-medium text-base">
{data?.totalMeetingRoomCount}
</div>
</div>
</div>

Expand All @@ -57,12 +86,16 @@ const AvailableRoom = () => {
<div className="text-gray-600 text-sm font-normal ">리차징룸</div>
<div className="flex justify-center items-center gap-1">
<div>
<span className="text-space-purple text-[26px] font-medium">1</span>
<span className="text-space-purple text-[26px] font-medium">
{data?.availableRechargingRoomCount}
</span>
</div>
<div>
<img src="/home/slash.svg" alt="" />
</div>
<div className="text-gray-400 font-medium text-base">30</div>
<div className="text-gray-400 font-medium text-base">
{data?.totalRechargingRoomCount}
</div>
</div>
</div>

Expand All @@ -73,18 +106,24 @@ const AvailableRoom = () => {
<div className="text-gray-600 text-sm font-normal ">포커스존</div>
<div className="flex justify-center items-center gap-1">
<div>
<span className="text-space-purple text-[26px] font-medium">1</span>
<span className="text-space-purple text-[26px] font-medium">
{data?.availableFocusDeskCount}
</span>
</div>
<div>
<img src="/home/slash.svg" alt="" />
</div>
<div className="text-gray-400 font-medium text-base">30</div>
<div className="text-gray-400 font-medium text-base">
{data?.totalFocusDeskCount}
</div>
</div>
</div>
</div>

{/* 하단 */}
<div 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">
<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">
예약하기
</div>
</div>
Expand Down
9 changes: 2 additions & 7 deletions src/components/home/CurrentOffice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const CurrentOffice = () => {
const setSelectedBranch = useBranchStore((state) => state.setSelectedBranch);
const [isHydrated, setIsHydrated] = useState(false);
const { isCurrent } = useIsCurrentBranch();
console.log(!isCurrent);

const initialBranch: Branch = {
branchId: 27,
Expand All @@ -31,10 +30,6 @@ const CurrentOffice = () => {
}
}, [selectedBranch, setSelectedBranch]);

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

const handleBranchSelect = (branch: Branch) => {
setSelectedBranch(branch, Date.now());
setShowSearchModal(false);
Expand Down Expand Up @@ -70,10 +65,10 @@ const CurrentOffice = () => {

{!isCurrent ? (
<div className="absolute z-50 top-6 right-20">
<div className="ml-[22px] opacity-85 ">
<div className="ml-[22px] opacity-95 ">
<img src="/home/triangle.svg" alt="" />
</div>
<div className="border-t border-space-purple-dark-active p-2 opacity-85 bg-space-purple-dark-active rounded text-white text-sm font-normal">
<div className="border-t border-space-purple-dark-active p-2 opacity-95 bg-space-purple-dark-active rounded text-white text-sm font-normal">
이 지점이 맞나요?
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/home/MainPageIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import UserInfo from './UserInfo';
import OfficeInfo from './OfficeInfo';
import WeekSchedule from './weekSchedule/WeekSchedule';
import AvailableRoom from './AvailableRoom';
import { useReservationStore } from '@/store/reservationModal.store';
import OfficeDeleteModal from './officeInfo/OfficeDeleteModal';

const MainPageIndex = () => {
const { deleteOpen, deleteDeskId } = useReservationStore();
return (
<div className="mb-[100px]">
<BgPurpleLayout>
Expand All @@ -24,6 +27,7 @@ const MainPageIndex = () => {
<WeekSchedule />
<AvailableRoom />
</div>
{deleteOpen && deleteDeskId !== null && <OfficeDeleteModal />}
</div>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/home/OfficeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const OfficeInfo = () => {
setIsCurrent(true);
}
}
if (data?.length == 0) {
setIsCurrent(true);
}
}, [selectedBranch, setIsCurrent, data]);

if (!data) {
Expand Down
12 changes: 12 additions & 0 deletions src/components/home/model/mainReservation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ICommon } from '@/api/types/common';

export interface AllAvailableCountData {
totalMeetingRoomCount: number;
availableMeetingRoomCount: number;
totalRechargingRoomCount: number;
availableRechargingRoomCount: number;
totalFocusDeskCount: number;
availableFocusDeskCount: number;
}

export type AllAvailableCountType = ICommon<AllAvailableCountData>;
101 changes: 101 additions & 0 deletions src/components/home/officeInfo/OfficeDeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import useOnClickOutside from '@/components/community/hooks/useOnClickOutside';
import {
deleteFocuszone,
deleteMeetingRoom,
deleteRechargingRoom
} from '@/components/reservation/remote/myreservation';
import { useBranchStore } from '@/store/branch.store';
import { useReservationStore } from '@/store/reservationModal.store';
import React, { useRef } from 'react';
import { useMutation, useQueryClient } from 'react-query';

const OfficeDeleteModal = () => {
const { deleteDeskId, setDeleteOpen, isMeeting, isLeader, roomType } =
useReservationStore();
const queryClient = useQueryClient();
const selectedBranch = useBranchStore((state) => state.selectedBranch);

const { mutateAsync } = useMutation(
(deskId: number) => {
if (roomType === 'FOCUS') {
return deleteFocuszone(deskId);
} else if (roomType === 'RECHARGING') {
return deleteRechargingRoom(deskId);
} else {
return deleteMeetingRoom(deskId);
}
},
{
onSuccess: () => {
queryClient.invalidateQueries(['todayReservationList']);
queryClient.invalidateQueries(['AllAvailableCount', selectedBranch?.branchId]);
setDeleteOpen(false);
}
}
);

const ref = useRef<HTMLDivElement>(null);
useOnClickOutside(ref, () => setDeleteOpen(false));

const renderTitle = () => {
if (isMeeting && isLeader && roomType === 'MEETING') {
return (
<div className="mx-[30px] mt-10 text-space-black font-bold text-lg">
예약을 취소하시겠어요?
</div>
);
} else if (isMeeting && !isLeader && roomType === 'MEETING') {
return (
<div className="mx-[30px] mt-10 text-space-black font-bold text-lg">
참여를 취소하시겠어요?
</div>
);
} else if (roomType === 'RECHARGING') {
return (
<div className="mx-[30px] mt-10 text-space-black font-bold text-lg">
예약을 취소하시겠어요?
</div>
);
} else {
return (
<div className="mx-[30px] mt-10 text-space-black font-bold text-lg">
이용을 종료하시겠어요?
</div>
);
}
};

return (
<div className="fixed inset-0 bg-gray-900 bg-opacity-30 z-[99999]">
<div
ref={ref}
className="z-50 w-[393px] bg-white absolute left-1/2 bottom-0 transform -translate-x-1/2 rounded-t-2xl">
{/* 공통부분 */}
{renderTitle()}
{isMeeting && isLeader && (
<div className="text-base font-normal text-space-black mx-[30px] mt-[26px]">
예약을 취소하시면, 등록된 참석자 모두의 일정에 반영됩니다. 삭제하시겠어요?
</div>
)}
<div className="mb-5 mt-[26px] mx-6 flex items-center gap-3">
<div
onClick={() => setDeleteOpen(false)}
className="cursor-pointer flex-1 flex items-center justify-center py-[12.5px] rounded-lg border border-space-purple text-base text-space-purple font-semibold">
취소
</div>
<div
onClick={() => {
if (deleteDeskId) {
mutateAsync(deleteDeskId);
}
}}
className=" cursor-pointer flex-1 flex items-center justify-center py-[12.5px] rounded-lg text-white bg-space-purple font-semibold text-base">
확인
</div>
</div>
</div>
</div>
);
};

export default OfficeDeleteModal;
25 changes: 13 additions & 12 deletions src/components/home/officeInfo/OfficeInfoFocus.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import { todayListData } from '@/components/reservation/model/myreservation';
import {
deleteFocuszone,
getReservationDetail
} from '@/components/reservation/remote/myreservation';
import { getReservationDetail } from '@/components/reservation/remote/myreservation';
import { useReservationStore } from '@/store/reservationModal.store';
import { format, parse } from 'date-fns';
import React from 'react';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useQuery } from 'react-query';

interface OfficeInfoFocusType {
data: todayListData;
}

const OfficeInfoFocus = ({ data }: OfficeInfoFocusType) => {
const queryClient = useQueryClient();
const { setDeleteOpen, setDeleteDeskId, setRoomType, setIsLeader, setIsMeeting } =
useReservationStore();

const { data: focusData } = useQuery(
['reservationDetail', data?.reservationId],
() => getReservationDetail(data?.reservationId),
{
enabled: data?.reservationId != null
}
);
const { mutateAsync } = useMutation((deskId: number) => deleteFocuszone(deskId), {
onSuccess: () => {
queryClient.invalidateQueries(['todayReservationList']);
}
});

const date = parse(data?.startAt, 'yyyy-MM-dd HH:mm', new Date());
const formattedTime = format(date, 'HH:mm');
Expand All @@ -45,7 +40,13 @@ const OfficeInfoFocus = ({ data }: OfficeInfoFocusType) => {
</div>

<div
onClick={() => mutateAsync(focusData?.spaceId)}
onClick={() => {
setRoomType('FOCUS');
setIsMeeting(false);
setIsLeader(false);
setDeleteDeskId(focusData?.spaceId);
setDeleteOpen(true);
}}
className="cursor-pointer w-[107px] h-9 text-red-700 flex items-center justify-center border-2 border-red-700 font-medium rounded-md">
이용 종료
</div>
Expand Down
Loading

0 comments on commit 9c94d0a

Please sign in to comment.