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

S1/#625 fix order api #627

Merged
merged 2 commits into from
Feb 27, 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
29 changes: 8 additions & 21 deletions src/components/Order/OrderFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,16 @@ const OrderFooter = ({
setOrderLoading: React.Dispatch<React.SetStateAction<boolean>>;
}) => {
const navigate = useNavigate();
const url = stickerId && count ? `/order?stickerId=${stickerId}&count=${count}` : '/order';

const fetchData = async () => {
setOrderLoading(true);
await api
.post(url, {
...postData,
contact: postData.contact.replace(/-/g, ''),
})
.then(() => {
setOrderLoading(false);
navigate('/order-deposit', {
state: response,
});
})
.catch((err) => {
console.log(err);
navigate('/error');
});
};

const handleClickButton = () => {
fetchData();
navigate('/order-deposit', {
state: {
postData: postData,
stickerId: stickerId,
count: count,
orderAmountDetailRes: response?.orderAmountDetailRes,
},
});
};

return (
Expand Down
63 changes: 61 additions & 2 deletions src/page/Order/OrderDepositPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,84 @@ import DirectDepositFooter from '../../components/DirectDeposit/DirectDepositFoo
import Header from '../../components/Header';
import OrderDeposit from '../../components/Order/Deposit/OrderDeposit';
import PageLayout from '../../components/PageLayout';
import { useNavigate } from 'react-router-dom';
import { api } from '../../libs/api';
import CancelBtn from '../../common/Header/CancelBtn';
import { orderAmountDetailResProps } from '../../libs/hooks/order/useGetOrdersheet';

interface OrderRequest {
stickerId: number;
productAmount: number;
shippingFee: number;
totalAmount: number | undefined;
recipientName: string;
contact: string;
mailingAddress: string;
baseAddress: string;
detailAddress: string;
}

const OrderDepositPage = () => {
const [depositModalOn, setDepositModalOn] = useState(false);
const [isActiveNext, setIsActiveNext] = useState(false);

const navigate = useNavigate();
const location = useLocation();

const { postData, stickerId, count } = location.state as {
postData: OrderRequest;
stickerId: number;
count: number;
orderAmountDetailRes: orderAmountDetailResProps;
};

const renderCustomDirectDepositPageHeader = () => {
return <Header leftSection={<BackBtn />} title='๋ฌดํ†ต์žฅ ์ž…๊ธˆ' rightSection={<IcCancelDark />} />;
return (
<Header
leftSection={<BackBtn />}
title='๋ฌดํ†ต์žฅ ์ž…๊ธˆ'
rightSection={
<CancelBtn
modalOn={depositModalOn}
setModalOn={setDepositModalOn}
targetModal={
<CheckDepositModal
setModalOn={setDepositModalOn}
setIsActiveNext={setIsActiveNext}
depositModalHandler={() => handleClickOrderDepositBtn()}
/>
}
/>
}
/>
);
};

const url = stickerId && count ? `/order?stickerId=${stickerId}&count=${count}` : '/order';

const handleClickFooter = () => {
{
isActiveNext && setDepositModalOn(true);
}
};

const fetchData = async () => {
await api
.post(url, {
...postData,
contact: postData.contact.replace(/-/g, ''),
})
.then(() => {
navigate('/');
})
.catch((err) => {
console.log(err);
navigate('/error');
});
};

const handleClickOrderDepositBtn = () => {
//@๊ตฌ ์—ฌ๊ธฐ์— orderPage์—์„œ ๋ฌดํ†ต์žฅ ์ž…๊ธˆ ํ›„ '์†ก๊ธˆํ–ˆ์–ด์š”' ๋ฒ„ํŠผ ๋ˆŒ๋ €์„ ๋•Œ์˜ ์•ก์…˜(navigate, data fetching)์„ ์ž‘์„ฑ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
fetchData();
};

return (
Expand Down