diff --git a/src/components/Trip/TripPreference.tsx b/src/components/Trip/TripPreference.tsx
index ca11afda..432c72f2 100644
--- a/src/components/Trip/TripPreference.tsx
+++ b/src/components/Trip/TripPreference.tsx
@@ -8,9 +8,10 @@ import {
} from '@utils/calculatePercentage';
import { modalChildrenState, isModalOpenState } from '@recoil/modal';
import { getTripsSurveyMembers } from '@api/trips';
-import { tripIdState } from '@recoil/socket';
-import { useRecoilValue, useSetRecoilState, useRecoilState } from 'recoil';
+import { useSetRecoilState, useRecoilState } from 'recoil';
import { participantsState } from '@recoil/trip';
+import { useGetTripsAuthority } from '@hooks/useGetTripsAuthority';
+
interface RatioBarParams {
value: number;
total: number;
@@ -96,6 +97,7 @@ const Percentage = ({ value, total, color }: PercentageParams) => (
);
const TripPreference: React.FC = () => {
+ const { tripId } = useGetTripsAuthority();
const [A, setA] = useState<[number, number]>([0, 0]);
const [B, setB] = useState<[number, number]>([0, 0]);
const [C, setC] = useState<[number, number]>([0, 0]);
@@ -103,12 +105,15 @@ const TripPreference: React.FC = () => {
const [E, setE] = useState<[number, number]>([0, 0]);
const setModalChildren = useSetRecoilState(modalChildrenState);
const setIsModalOpen = useSetRecoilState(isModalOpenState);
- const tripId = Number(useRecoilValue(tripIdState));
const [participants, setParticipants] = useRecoilState(participantsState);
const { data: tripsSurveyMembers } = useQuery({
queryKey: ['tripsSurveyMembers', tripId],
- queryFn: () => getTripsSurveyMembers(tripId),
+ queryFn: () =>
+ tripId != null
+ ? getTripsSurveyMembers(tripId)
+ : Promise.reject('tripId is null'),
+ enabled: !!tripId,
});
useEffect(() => {
@@ -118,7 +123,11 @@ const TripPreference: React.FC = () => {
const { data: tripPreference, isLoading } = useQuery({
queryKey: ['tripPreference', tripId],
- queryFn: () => getTripsSurvey(tripId),
+ queryFn: () =>
+ tripId != null
+ ? getTripsSurvey(tripId)
+ : Promise.reject('tripId is null'),
+ enabled: !!tripId,
});
useEffect(() => {
diff --git a/src/components/Trip/TripRealtimeEditor.tsx b/src/components/Trip/TripRealtimeEditor.tsx
index 895b51e4..b7f83c6d 100644
--- a/src/components/Trip/TripRealtimeEditor.tsx
+++ b/src/components/Trip/TripRealtimeEditor.tsx
@@ -1,46 +1,15 @@
-import { useRecoilValue } from 'recoil';
-import { tripIdState } from '@recoil/socket';
import { useEffect, useState } from 'react';
import { socketContext } from '@hooks/useSocket';
import { useContext } from 'react';
-import { pubConnectMember, pubDisconnectMember } from '@api/socket';
import { UserIcon } from '@components/common/icons/Icons';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Navigation } from 'swiper/modules';
-import { getItem } from '@utils/localStorageFun';
const TripRealtimeEditor = () => {
- const tripId = useRecoilValue(tripIdState);
- const { callBackPub, tripMember } = useContext(socketContext);
- const [token, setToken] = useState('');
- const [pubMember, setPubMember] = useState({ token: '' });
-
- useEffect(() => {
- const accessToken = getItem('accessToken');
- if (accessToken) {
- setToken(accessToken);
- }
- }, []);
-
- useEffect(() => {
- setPubMember({ token: token || '' });
- }, [token]);
-
- useEffect(() => {
- if (pubMember && tripId) {
- callBackPub(() => {
- pubConnectMember(pubMember, tripId);
- });
- return () => {
- callBackPub(() => pubDisconnectMember(pubMember, tripId));
- };
- }
- }, [pubMember]);
+ const { tripMember } = useContext(socketContext);
const tripMemberData = tripMember?.data;
- useEffect(() => {
- console.log('tripMemberData', tripMemberData);
- }, [tripMemberData]);
+
return (
{
+ const { tripName, startDate, endDate, numberOfPeople } = useGetTrips();
+
return (
<>
-
-
강릉 여행 일정
+
+
{tripName}
- 5
+ {numberOfPeople}
+
+
+
+
-
23.12.23 - 23.12.25
+
+ {startDate?.substring(2).replace(/-/g, '.') || ''} -{' '}
+ {endDate?.substring(5).replace(/-/g, '.') || ''}
+
>
);
};
diff --git a/src/components/Trip/TripSectionTop.tsx b/src/components/Trip/TripSectionTop.tsx
index d1388108..a966bab9 100644
--- a/src/components/Trip/TripSectionTop.tsx
+++ b/src/components/Trip/TripSectionTop.tsx
@@ -5,6 +5,10 @@ import { BackBox } from '@components/common';
import { useNavigate } from 'react-router-dom';
import PlanTripButton from './PlanTripButton';
import { LikedToursList } from './LikedToursList';
+
+
+const TripSectionTop = () => {
+ const navigate = useNavigate();
import { useGetTripsAuthority } from '@hooks/useGetTripsAuthority';
import { useEffect, useState } from 'react';
import IsEditableModal from '@components/Share/IsEditableModal';
@@ -22,6 +26,7 @@ const TripSectionTop = () => {
}
}, [tripAuthority]);
+
return (
diff --git a/src/components/common/icons/Icons.tsx b/src/components/common/icons/Icons.tsx
index b6eead6c..6704db50 100644
--- a/src/components/common/icons/Icons.tsx
+++ b/src/components/common/icons/Icons.tsx
@@ -480,6 +480,7 @@ export const PlusIcon: React.FC
= ({
size = 20,
color = 'black',
fill = 'none',
+ className,
}) => {
return (
);
};
+
+export const DropdownIcon: React.FC = ({}) => {
+ return (
+
+ );
+};
+
+
diff --git a/src/hooks/useGetMyTrips.ts b/src/hooks/useGetMyTrips.ts
new file mode 100644
index 00000000..754188ed
--- /dev/null
+++ b/src/hooks/useGetMyTrips.ts
@@ -0,0 +1,28 @@
+import { useQuery } from '@tanstack/react-query';
+import { getMyTrips } from '@api/trips';
+
+interface Trip {
+ tripId: number;
+ tripName: string;
+ startDate: string;
+ endDate: string;
+ numberOfPeople: number;
+ tripStatus: string;
+ tripThumbnailUrl: string;
+}
+
+export const useGetMyTrips = (): { myTrips: Trip[] } => {
+ const { data, isLoading, isError } = useQuery({
+ queryKey: ['getMyTrips'],
+ queryFn: () => getMyTrips(),
+ staleTime: 60000,
+ });
+
+ const myTrips = data?.data.data;
+
+ if (isLoading || isError) {
+ return { myTrips: [] };
+ }
+
+ return { myTrips };
+};
diff --git a/src/hooks/useGetTrips.ts b/src/hooks/useGetTrips.ts
new file mode 100644
index 00000000..7e1c0445
--- /dev/null
+++ b/src/hooks/useGetTrips.ts
@@ -0,0 +1,43 @@
+import { useQuery } from '@tanstack/react-query';
+import { getTrips } from '@api/trips';
+import { useParams } from 'react-router-dom';
+
+type useGetTripsReturn = {
+ tripName: string | null;
+ startDate: string | null;
+ endDate: string | null;
+ numberOfPeople: number | null;
+};
+
+export const useGetTrips = (): useGetTripsReturn => {
+ const { id } = useParams();
+
+ const defaultReturn = {
+ tripName: null,
+ startDate: null,
+ endDate: null,
+ numberOfPeople: null,
+ };
+
+ if (!id) {
+ return defaultReturn;
+ }
+
+ const { data, isLoading, isError } = useQuery({
+ queryKey: ['getTrips', id],
+ queryFn: () => getTrips(id),
+ enabled: !!id,
+ staleTime: 60000,
+ });
+
+ const tripName = data?.data.data.tripName;
+ const startDate = data?.data.data.startDate;
+ const endDate = data?.data.data.endDate;
+ const numberOfPeople = data?.data.data.numberOfPeople;
+
+ if (isLoading || isError) {
+ return defaultReturn;
+ }
+
+ return { tripName, startDate, endDate, numberOfPeople };
+};
diff --git a/src/hooks/useGetTripsAuthority.ts b/src/hooks/useGetTripsAuthority.ts
index efef5695..1dd72859 100644
--- a/src/hooks/useGetTripsAuthority.ts
+++ b/src/hooks/useGetTripsAuthority.ts
@@ -6,7 +6,7 @@ import { useParams } from 'react-router-dom';
type useGetTripsAuthorityReturn = {
tripAuthority: string | null;
memberId: number | null;
- TripId: number | null;
+ tripId: string | null;
};
export const useGetTripsAuthority = (): useGetTripsAuthorityReturn => {
@@ -15,7 +15,7 @@ export const useGetTripsAuthority = (): useGetTripsAuthorityReturn => {
const defaultReturn = {
tripAuthority: null,
memberId: null,
- TripId: null,
+ tripId: null,
};
if (!id) {
@@ -25,15 +25,16 @@ export const useGetTripsAuthority = (): useGetTripsAuthorityReturn => {
queryKey: ['getTripsAuthority', id],
queryFn: () => getTripsAuthority(id),
enabled: !!id,
+ staleTime: 60000,
});
const tripAuthority = data?.data.data.tripAuthority;
const memberId = data?.data.data.memberId;
- const TripId = data?.data.data.TripId;
+ const tripId = data?.data.data.TripId;
if (isLoading || isError) {
return defaultReturn;
}
- return { tripAuthority, memberId, TripId };
+ return { tripAuthority, memberId, tripId };
};
diff --git a/src/hooks/useSocket.ts b/src/hooks/useSocket.ts
index 6f07b0ca..37b7831a 100644
--- a/src/hooks/useSocket.ts
+++ b/src/hooks/useSocket.ts
@@ -16,6 +16,9 @@ import {
} from '@/@types/service';
import { createContext } from 'react';
import { useState, useEffect } from 'react';
+import { useParams } from 'react-router-dom';
+import { useRecoilValue } from 'recoil';
+import { visitDateState } from '@recoil/socket';
export const socketContext = createContext({
tripInfo: null,
@@ -23,16 +26,20 @@ export const socketContext = createContext({
tripPath: null,
tripMember: null,
tripBudget: null,
+ tripId: '',
callBackPub: () => {},
});
-export const useSocket = (tripId: string, visitDate: string) => {
+export const useSocket = () => {
+ const { id } = useParams();
+ const tripId = id ?? '';
+ const visitDate = useRecoilValue(visitDateState);
+
const [tripInfo, setTripInfo] = useState(null);
const [tripItem, setTripItem] = useState(null);
const [tripPath, setTripPath] = useState(null);
const [tripMember, setTripMember] = useState(null);
const [tripBudget, setTripBudget] = useState(null);
-
const [socketCallback, setSocketCallback] = useState<(() => void) | null>(
null,
);
@@ -41,7 +48,7 @@ export const useSocket = (tripId: string, visitDate: string) => {
setSocketCallback(() => callback);
};
- const socketConnect = () => {
+ const socketConnect = (tripId: string, visitDate: string) => {
socketClient.onConnect = () => {
subInfo(tripId, (res) => {
if (res) {
@@ -63,7 +70,6 @@ export const useSocket = (tripId: string, visitDate: string) => {
subMember(tripId, (res) => {
if (res) {
- // console.log('subMemberRes', res);
setTripMember(res);
}
});
@@ -83,13 +89,23 @@ export const useSocket = (tripId: string, visitDate: string) => {
};
useEffect(() => {
- socketConnect();
- console.log('소켓연결');
+ if (tripId && visitDate) {
+ socketConnect(tripId, visitDate.visitDate);
+ console.log(visitDate);
+ }
return () => {
socketClient.deactivate();
};
}, [tripId, visitDate, socketCallback]);
- return { tripInfo, tripItem, tripPath, tripMember, tripBudget, callBackPub };
+ return {
+ tripInfo,
+ tripItem,
+ tripPath,
+ tripMember,
+ tripBudget,
+ tripId,
+ callBackPub,
+ };
};
diff --git a/src/recoil/socket.ts b/src/recoil/socket.ts
index ab7bb76b..fca451c7 100644
--- a/src/recoil/socket.ts
+++ b/src/recoil/socket.ts
@@ -2,15 +2,10 @@ import { atom } from 'recoil';
export const tripIdState = atom({
key: 'tripIdState',
- default: '1',
+ default: '',
});
export const visitDateState = atom<{ visitDate: string } | null>({
key: 'visitDateState',
- default: { visitDate: '2024-01-03' },
-});
-
-export const memberIdState = atom<{ token: number | null }>({
- key: 'memberIdState',
- default: { token: null },
+ default: { visitDate: '' },
});
diff --git a/src/router/socketRouter.tsx b/src/router/socketRouter.tsx
index fd1115bf..9892bd95 100644
--- a/src/router/socketRouter.tsx
+++ b/src/router/socketRouter.tsx
@@ -13,14 +13,8 @@ import { AddOurList } from '@pages/trip/AddOurList';
const SocketRoutes = () => {
- const tripId = useRecoilValue(tripIdState);
- const visitDate = useRecoilValue(visitDateState);
- if (!tripId || !visitDate) {
- return 에러
;
- }
-
return (
-
+
} />
} />
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index b371a609..6176f3e0 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -30,13 +30,19 @@ export const getEmoji = (content: string) => {
export function calculateDayAndDate(startDate: string, endDate: string) {
let start = new Date(startDate);
const end = new Date(endDate);
- const differenceInDays: number =
- (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
-
- const DayArr = Array.from(
- { length: Math.ceil(differenceInDays) + 1 },
- (_, i) => `DAY ${i + 1}`,
+ const differenceInDays: number = Math.round(
+ (end.getTime() - start.getTime()) / (1000 * 3600 * 24),
);
+
+ const createDayArray = (prefix: string) =>
+ Array.from(
+ { length: differenceInDays + 1 },
+ (_, i) => `${prefix} ${i + 1}`,
+ );
+
+ const DayArr = createDayArray('DAY');
+ const SmallDayArr = createDayArray('Day');
+
const DateArr = [];
while (start <= end) {
@@ -47,5 +53,6 @@ export function calculateDayAndDate(startDate: string, endDate: string) {
return {
DayArr,
DateArr,
+ SmallDayArr,
};
}