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

Feat: 상품가격 수정 구현 #214

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/@types/socket.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface pubAddTripItem {
interface pubUpdatePrice {
tripId: string;
visitDate: string;
price: number;
price: string;
}

interface pubUpdateTripItem {
Expand Down
6 changes: 3 additions & 3 deletions src/api/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const pubAddTripItem = (
// 여행 아이템 예상 가격 업데이트 이벤트 발생시
export const pubUpdatePrice = (
pubUpdatePrice: pubUpdatePrice,
tripItemId: string,
tripItemId: number,
) => {
socketClient.publish({
destination: `/pub/tripItems/${tripItemId}/updatePrice`,
Expand All @@ -106,10 +106,10 @@ export const pubUpdateTripItem = (
// 여행 날짜별 교통 수단 변경 이벤트 발생시 (01/16 업데이트)
export const pubUpdateTransportation = (
pubUpdateTransportation: pubUpdateTransportation,
trips: string,
tripId: string,
) => {
socketClient.publish({
destination: `/pub/trips/${trips}/updateTransportation`,
destination: `/pub/trips/${tripId}/updateTransportation`,
body: JSON.stringify(pubUpdateTransportation),
});
};
Expand Down
11 changes: 6 additions & 5 deletions src/components/Plan/PlanEditItemBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PenIcon, DragAndDropIcon } from '@components/common/icons/Icons';
import { DragAndDropIcon } from '@components/common/icons/Icons';
import { TripItem } from '@/@types/service';
import {
DragDropContext,
Expand Down Expand Up @@ -139,9 +139,10 @@ const PlanEditItemBox = ({
alt="img"
/>
<div className="flex w-full flex-col p-[10px]">
<div className="flex justify-between text-left text-[14px] font-medium text-black">
{item.name}
<PenIcon size={14} className="cursor-pointer" />
<div className="flex text-left text-[14px] font-medium text-black">
{item.name.length > 17
? item.name.slice(0, 17) + '...'
: item.name}
</div>
<div className="mt-[3px] flex h-fit w-fit items-center justify-center gap-2 rounded-[3px] bg-[#ededed] p-[4px] text-center text-[11px] text-black">
{item.category}
Expand All @@ -166,7 +167,7 @@ const PlanEditItemBox = ({
)}
</Droppable>
</DragDropContext>
<div className="justify-cente fixed bottom-0 left-0 right-0 z-10 flex">
<div className="fixed bottom-0 left-0 right-0 z-10 flex justify-center">
<div className="mx-auto flex h-14 max-w-md">
<Alert
title={'여행지 삭제'}
Expand Down
1 change: 1 addition & 0 deletions src/components/Plan/PlanItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const PlanItem: React.FC<PlanItemProps> = ({ date, day }) => {
item={tripItem?.data?.tripItems || []}
paths={tripPath?.data?.paths || []}
transportation={transpo}
visitDate={date || ''}
day={day}
/>
)}
Expand Down
70 changes: 68 additions & 2 deletions src/components/Plan/PlanItemBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,55 @@ import {
CarIcon,
BusIcon,
SequenceIcon,
CloseIcon,
} from '@components/common/icons/Icons';
import { TripItem, Paths } from '@/@types/service';
import { v4 as uuidv4 } from 'uuid';
import { useGetTripsAuthority } from '@hooks/useGetTripsAuthority';
import Alert from '@components/common/alert/Alert';
import { useContext, useState } from 'react';
import { socketContext } from '@hooks/useSocket';
import { pubUpdatePrice } from '@api/socket';

type PlanItemBoxProps = {
item: TripItem[];
paths: Paths[];
transportation: string;
day: string;
visitDate: string;
};

const PlanItemBox = ({
item,
paths,
transportation,
day,
visitDate,
}: PlanItemBoxProps) => {
if (!item || !paths) {
return <div>Missing data</div>;
}

const { tripAuthority } = useGetTripsAuthority();
const { tripId } = useContext(socketContext);

const itemLength = item.length;
const [inputPrice, setInputPrice] = useState('');
const showCloseIcon = inputPrice;

const handlePrice = (inputBudget: string, tripItemId: number) => {
if (inputBudget && tripItemId) {
pubUpdatePrice(
{
tripId: tripId,
visitDate: visitDate,
price: inputBudget,
},
tripItemId,
);
setInputPrice('');
}
};

return (
<>
Expand All @@ -49,8 +76,47 @@ const PlanItemBox = ({
/>
<div className="flex w-full flex-col p-[10px]">
<div className="flex justify-between text-left text-[14px] font-medium text-black">
{item.name}
<PenIcon size={14} className="cursor-pointer" />
{item.name.length > 19
? item.name.slice(0, 19) + '...'
: item.name}
{tripAuthority == 'WRITE' && (
<Alert
title={'비용을 입력해주세요'}
message={''}
onConfirm={() =>
handlePrice(inputPrice, item.tripItemId)
}
closeOnConfirm={true}
children={
<button>
<PenIcon size={14} className="cursor-pointer" />
</button>
}
content={
<div className="mb-6 mt-8 flex w-[80%] items-center justify-between border-b-[1px] border-solid border-gray4">
<div className="flex w-full items-center justify-between">
<input
type="number"
className="title3 text-gray6 placeholder:text-gray4 focus:outline-none"
placeholder="금액"
value={inputPrice}
onChange={(e) => setInputPrice(e.target.value)}
/>
<div
className="cursor-pointer"
onClick={() => setInputPrice('')}>
{showCloseIcon && (
<CloseIcon size={16} fill="#D7D7D7" />
)}
</div>
</div>
<span className="title3 pl-[4.5px] text-gray4">
</span>
</div>
}
/>
)}
</div>
<div className="mt-[3px] flex h-fit w-fit items-center justify-center gap-2 rounded-[3px] bg-[#ededed] p-[4px] text-center text-[11px] text-black">
{item.category}
Expand Down
14 changes: 8 additions & 6 deletions src/components/Plan/TripBudget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useContext, useState } from 'react';

const TripBudget = () => {
const { tripAuthority } = useGetTripsAuthority();
const { tripBudget, tripId } = useContext(socketContext);
const { callBackPub, tripBudget, tripId } = useContext(socketContext);

const budget = tripBudget?.data;

Expand All @@ -28,11 +28,13 @@ const TripBudget = () => {
const handleSetTargetBudget = (inputBudget: string) => {
const newTargetBudget = parseInt(inputBudget, 10); // 문자열 숫자로 변환
if (!isNaN(newTargetBudget) && newTargetBudget !== budget?.budget) {
pubUpdateBudget(
{
budget: newTargetBudget,
},
tripId || '',
callBackPub(() =>
pubUpdateBudget(
{
budget: newTargetBudget,
},
tripId || '',
),
);
setInputBudget('');
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ export const useSocket = () => {
if (tripId && visitDate) {
socketConnect(tripId, visitDate.visitDate);
}
console.log('소켓연결');

return () => {
socketClient.deactivate();
console.log('소켓해제');
};
}, [tripId, visitDate, socketCallback]);

Expand Down
Loading