Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6e6e049
feat: 설정 페이지 이용약관, 개인정보처리방침 외부 링크 연결 (#129)
udam9 Oct 20, 2023
3246c4c
REFACTOR : edit 페이지에서 완료 버튼 클릭 시 제대로 페이지 이동 (#130)
Whale2200d Oct 22, 2023
97aa441
[REFACTOR] QueryClient를 이용한 Edit 페이지 자산 삭제 (#133)
Whale2200d Oct 23, 2023
d72f4df
Refactor : Modal 및 Toast 수정, 무한스크롤 수정 (#134)
Whale2200d Oct 23, 2023
36628e1
feat: 로딩 Snackbar 또한 탭 이동시 숨김처리
udam9 Oct 24, 2023
6945454
feat: 세팅 페이지 고객센터 메뉴 추가 (#139)
udam9 Oct 25, 2023
488e602
[FIX] main page negative number handle (#144)
udam9 Oct 26, 2023
78e6735
[FEAT] Main Page 첫방문 Event Loaging 관련 작업 SNO-77 (#145)
udam9 Oct 26, 2023
bea63d0
Merge branch 'develop' of https://github.com/fire-tribes/client into …
Whale2200d Oct 26, 2023
55441bf
Refactor : resetSnackbar 복구
Whale2200d Oct 26, 2023
5f5d821
Merge branch 'develop' of https://github.com/fire-tribes/client into …
Whale2200d Nov 28, 2023
b5bad4a
⚡️ [IMPROVE] 현재가 호출 시, 소수점 3자리부터 제거하도록 수정 (#170)
Whale2200d Nov 28, 2023
9318050
⚡️ [IMPROVE] 현재가 입력에 따른 가격 변경 외 1 (#171)
Whale2200d Nov 29, 2023
53bf8c1
[FIX] auth api instance base url (#176)
udam9 Dec 6, 2023
4a3aab4
chore: upgrade next.js v12 to v13 (#181)
udam9 Dec 26, 2023
57b620a
Chore/change next js version (#182)
udam9 Dec 26, 2023
f5039b0
Chore/change next js version (#183)
udam9 Dec 26, 2023
b2d0592
Create sitemap.xml
udam9 Jan 4, 2024
5607ec4
Create robots.txt
udam9 Jan 4, 2024
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
55 changes: 19 additions & 36 deletions components/EditStocksGroup/EditStockInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ import {
handleDecimalPoint,
} from '@/core/utils/handleNumber';
import { useExchangeRate } from '@/hook/useExchangeRate';
import { changeIsPressButtonInEditAtom } from '@/hook/useChangeIsPressButtonInEdit/state';
import Image from 'next/image';
import { ChangeEvent, useEffect, useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { AxiosResponse } from 'axios';
import { useAtom } from 'jotai';
// import { useRouter } from 'next/router';

interface EditStockInfoProps {
slug: string[];
}

export default function EditStockInfo({ slug }: EditStockInfoProps) {
// const router = useRouter();
/** 3. '정보 확인' API로 수량 및 가격 데이터 가져오기(GET) */
/** COMPLETED: 3-1. GET 요청에 필요한 portfolioId와 portfolioAssetId 가져오기 */
const portfolioId = Number(slug?.[0]);
Expand Down Expand Up @@ -86,25 +85,17 @@ export default function EditStockInfo({ slug }: EditStockInfoProps) {
const handleCurrencyType = (newCurrencyType: ExchangeRateSymbol) => {
setEditAssetDetail((prev) => {
let newPurchasePrice = prev.purchasePrice;

if (
newCurrencyType === 'USD' &&
typeof newPurchasePrice === 'number' &&
EXCHANGE_RATE !== undefined
) {
console.log('newPurchasePrice: ', newPurchasePrice);
if (newCurrencyType === 'USD' && EXCHANGE_RATE !== undefined) {
newPurchasePrice = handleDecimalPoint(
Math.round,
newPurchasePrice / EXCHANGE_RATE,
Math.floor,
Number(newPurchasePrice) / EXCHANGE_RATE,
2,
);
} else if (
newCurrencyType === 'KRW' &&
typeof newPurchasePrice === 'number' &&
EXCHANGE_RATE !== undefined
) {
} else if (newCurrencyType === 'KRW' && EXCHANGE_RATE !== undefined) {
newPurchasePrice = handleDecimalPoint(
Math.round,
newPurchasePrice * EXCHANGE_RATE,
Math.floor,
Number(newPurchasePrice) * EXCHANGE_RATE,
0,
);
}
Expand All @@ -115,35 +106,28 @@ export default function EditStockInfo({ slug }: EditStockInfoProps) {
currencyType: newCurrencyType,
};
});
return;
};
/** COMPLETED: 4-3. '현재가 입력' 버튼으로 price 데이터 변경하기 */
const [isPressButton, setIsPressButton] = useState(true);
const { getCurrentPriceDatas, invalidateCurrentPrice } =
const [isPressButtonInEdit, setIsPressButtonInEdit] = useAtom(
changeIsPressButtonInEditAtom,
);
const { getCurrentPriceData, invalidateCurrentPrice } =
useGetCurrentPriceInAssetDetails(
assetId,
editAssetDetail.currencyType,
isPressButton,
isPressButtonInEdit,
);
const handleCurrentPrice = async (
const handleCurrentPrice = (
assetId: number,
currencyType: ExchangeRateSymbol,
) => {
const result = getCurrentPriceDatas?.data;
invalidateCurrentPrice(assetId, currencyType);

setIsPressButtonInEdit(true);
const result = getCurrentPriceData?.data;
if (result) {
const roundedPriceToTwoDemicalPoint = handleDecimalPoint(
Math.round,
result.data[0].currentPrice,
2,
);

setEditAssetDetail((prev) => ({
...prev,
purchasePrice: roundedPriceToTwoDemicalPoint,
}));
invalidateCurrentPrice(assetId, currencyType);
return;
}
setIsPressButton(true);
};
/** COMPLETED: 4-4. count, price 데이터를 입력하지 않을 때, Error 처리하기 */
const [errorText, setErrorText] = useState('');
Expand Down Expand Up @@ -196,7 +180,6 @@ export default function EditStockInfo({ slug }: EditStockInfoProps) {
};
/** 5-1-3. 수정된 데이터로 Cache 업데이트하기 */
queryClient.setQueryData(queryKeys.myPortFolio(), () => updater());
// router.push(`/edit?portfolioId=${portfolioId}&deleteAssetDetails=success`);
/** 5-2. 서버 내 해당 주식 객체 삭제하기 */
deleteAssetDetailsData({
portfolioId,
Expand Down
26 changes: 23 additions & 3 deletions components/FeedStockInfoGroup/FeedStockInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import belowArrowSvg from '@/public/icon/below_arrow.svg';
import { basic } from '@/styles/palette';
import StockAvatar from '@/components/common/StockAvatar';
import { ExchangeRateSymbol } from '@/@types/models/exchangeRate';
import { useGetCurrentPriceInSelectedStocks } from '@/hook/useGetCurrentPriceInSelectedStocks';
import { changeIsPressButtonAtom } from '@/hook/useChangeIsPressButton/state';
import Image from 'next/image';
import { ChangeEvent, useState } from 'react';
import { useAtom } from 'jotai';

interface FeedStockInfoProps {
/** 선택한 배열의 index */
index: number;
/** 선택한 배열의 객체값 */
stock: SelectedStocksAtomProps;
/** 선택한 값을 배열 삭제 */
removeSelected: (stock: SelectedStocksAtomProps) => void;
/** 현재가 입력 버튼 */
handleCurrentPrice: () => void;
/** 가격 input */
inputCountValue: string | number;
/** 가격 input */
Expand All @@ -32,7 +35,6 @@ interface FeedStockInfoProps {
function FeedStockInfo({
stock,
removeSelected,
handleCurrentPrice,
inputCountValue,
inputPriceValue,
changeCountEventHandle,
Expand All @@ -54,6 +56,24 @@ function FeedStockInfo({
}
};

/* 2-2. '현재가 입력' 버튼으로 price 데이터 변경하기 */
const [isPressButton, setIsPressButton] = useAtom(changeIsPressButtonAtom);
const { getCurrentPriceData, invalidateCurrentPrice } =
useGetCurrentPriceInSelectedStocks(
stock.assetId,
stock.currencyType,
isPressButton,
);
const handleCurrentPrice = () => {
setIsPressButton(true);
const result = getCurrentPriceData.data?.data;

if (result) {
invalidateCurrentPrice(stock.assetId, stock.currencyType);
return;
}
};

return (
<FeedStockInfoUI.Container>
<FeedStockInfoUI.Item>
Expand Down
71 changes: 13 additions & 58 deletions components/FeedStockInfoGroup/FeedStockInfos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import {
} from '@/hook/useGetSelectedStocks/state';
import CheckSvg from '@/public/icon/check.svg';
import { basic } from '@/styles/palette';
import { useGetCurrentPriceInSelectedStocks } from '@/hook/useGetCurrentPriceInSelectedStocks';
import { ExchangeRateSymbol } from '@/@types/models/exchangeRate';
import { useExchangeRate } from '@/hook/useExchangeRate';
import {
checkDecimalPointLength,
handleDecimalPoint,
} from '@/core/utils/handleNumber';
import { useGetCurrentPriceAllInSelectedStocks } from '@/hook/useGetCurrentPriceAllInSelectedStocks';
import { useAtom } from 'jotai';
import Image from 'next/image';
import { ChangeEvent, useEffect, useState } from 'react';
import { ChangeEvent, useState } from 'react';

function FeedStockInfos() {
/** COMPLETED: 1. 선택된 주식 배열 가져오기 */
Expand All @@ -42,47 +42,11 @@ function FeedStockInfos() {
* '(전체)현재가', '(개별)현재가'가 따로 존재하며, 서버로 요청은 '(개별)현재가'만 존재한다.
* 전체 현재가 버튼 클릭 시, 한꺼번에 재요청할 수 있도록 핸들링할 수 있는 배열이 필요하다.
*/
const [isPressAllButton, setIsPressAllButton] = useState<boolean[]>([]);
// const [isPressAllButton, setIsPressAllButton] = useState<boolean[]>([]);
const [newIsPressAllButton, setNewIsPressAllButton] = useState(false);
useEffect(() => {
const array = Array.from({ length: selectedStocks.length }, () => false);
setIsPressAllButton(array);
}, [selectedStocks]);
/* 3-2. 서버로 현재가 데이터 GET 요청하기 */
const {
getCurrentPriceDatas,
invalidateCurrentPrice,
invalidateCurrentPrices,
} = useGetCurrentPriceInSelectedStocks(isPressAllButton, newIsPressAllButton);
/* 2-2. '현재가 입력' 버튼으로 price 데이터 변경하기 */
const handleCurrentPriceButton = (
assetId: number,
index: number,
currencyType: ExchangeRateSymbol,
) => {
const result = getCurrentPriceDatas[index].data?.data;
invalidateCurrentPrice(assetId, currencyType);

if (result) {
const roundedPriceToTwoDemicalPoint = handleDecimalPoint(
Math.round,
result.data[0].currentPrice,
2,
);

setSelectedStocks((prev) => {
const newSelectedStocks = [...prev];
newSelectedStocks[index].price = roundedPriceToTwoDemicalPoint;
return newSelectedStocks;
});
}

setIsPressAllButton((prev) => {
const newArray = [...prev];
newArray[index] = true;
return newArray;
});
};
const { invalidateCurrentPrices } =
useGetCurrentPriceAllInSelectedStocks(newIsPressAllButton);
/* 2-3. '현재가 전체 입력' 버튼으로 price 데이터 전체 변경하기 */
const handleCurrentPriceAllButton = () => {
invalidateCurrentPrices();
Expand Down Expand Up @@ -133,7 +97,7 @@ function FeedStockInfos() {
) {
setSelectedStocks((stock) => {
const array = [...stock];
array[id].count = handleDecimalPoint(Math.round, value, 2);
array[id].count = handleDecimalPoint(Math.floor, value, 2);
return array;
});
return;
Expand All @@ -152,7 +116,6 @@ function FeedStockInfos() {
e: ChangeEvent<HTMLInputElement>,
) => {
const { value } = e.currentTarget;

const currentPriceValueDecimalPointLength =
checkDecimalPointLength(selectedStocks[id].price) || 0;
const newPriceValueDecimalPointLength =
Expand All @@ -163,7 +126,6 @@ function FeedStockInfos() {
const array = [...stock];
const result = handleDecimalPoint(Math.floor, value, 0);
array[id].price = result.toString().replace(/[^0-9]/g, '');

return array;
});
return;
Expand All @@ -176,7 +138,8 @@ function FeedStockInfos() {
) {
setSelectedStocks((stock) => {
const array = [...stock];
array[id].price = handleDecimalPoint(Math.floor, value, 2);
const result = handleDecimalPoint(Math.floor, value, 2);
array[id].price = result;
return array;
});
return;
Expand All @@ -196,10 +159,9 @@ function FeedStockInfos() {
) => {
setSelectedStocks((prev: SelectedStocksAtomProps[]) => {
let newPrice = prev[id].price;

if (newCurrencyType === 'USD' && EXCHANGE_RATE !== undefined) {
newPrice = handleDecimalPoint(
Math.round,
Math.floor,
Number(newPrice) / EXCHANGE_RATE,
2,
);
Expand All @@ -208,38 +170,31 @@ function FeedStockInfos() {
EXCHANGE_RATE !== undefined
) {
newPrice = handleDecimalPoint(
Math.round,
Math.floor,
Number(newPrice) * EXCHANGE_RATE,
0,
);
}

// 이전 상태를 복사하여 새로운 배열 생성한다.
const updatedSelectedStocks = [...prev];

// 특정 id의 객체를 찾아서 currencyType를 newCurrencyType으로 변경한다.
updatedSelectedStocks[id] = {
...updatedSelectedStocks[id],
price: newPrice,
currencyType: newCurrencyType,
};

return updatedSelectedStocks;
});
return;
};

console.log('stock.price: ', stock.price);
return (
<FeedStockInfo
key={id}
index={id}
stock={stock}
removeSelected={handleRemoveSelected}
handleCurrentPrice={() =>
handleCurrentPriceButton(
stock.assetId,
id,
stock.currencyType,
)
}
inputCountValue={stock.count}
inputPriceValue={stock.price}
changeCountEventHandle={onChangeCountEventHandle}
Expand Down
32 changes: 28 additions & 4 deletions core/api/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import axios from 'axios';
import type { AxiosRequestConfig } from 'axios';

const AUTHORIZATION = 'Authorization';
const BASE_URL = global.location?.origin;

const createAPIInstance = (config: AxiosRequestConfig) => {
const instance = axios.create({
Expand All @@ -14,10 +13,30 @@ const createAPIInstance = (config: AxiosRequestConfig) => {
return instance;
};

const currentUrlHostname = global.location?.hostname;

export const productServerHostname =
process.env.NEXT_PUBLIC_PRODUCT_SERVER_HOSTNAME;
export const productServerURL = process.env.NEXT_PUBLIC_SERVER_URL;
const devServerURL = process.env.NEXT_PUBLIC_DEV_SERVER_URL;

const baseURL =
BASE_URL === process.env.NEXT_PUBLIC_PRODUCT_SERVER_ORIGIN
? process.env.NEXT_PUBLIC_SERVER_URL
: process.env.NEXT_PUBLIC_DEV_SERVER_URL;
currentUrlHostname === productServerHostname
? productServerURL
: devServerURL;

console.log('instance.ts baseURL', baseURL);

export const changeAuthAPIInstanceBaseUrlIntoProductServerUrl = (
hostname: string,
) => {
if (hostname === productServerHostname) {
const newBaseURL = productServerURL + '/api/v1/user/';
AuthAPIInstance.defaults.baseURL = newBaseURL;
}
};

console.log('instance.ts baseURL', baseURL);

const APIInstance = createAPIInstance({
baseURL: baseURL + '/api/v1/',
Expand Down Expand Up @@ -48,5 +67,10 @@ const token = new Token({
APIInstance.interceptors.request.use(tokenVerifyHandler);
APIInstance.interceptors.response.use();

AuthAPIInstance.interceptors.request.use((config) => {
console.log('intercepter', config.baseURL);
return config;
});

export { APIInstance, AuthAPIInstance };
export default APIInstance;
10 changes: 5 additions & 5 deletions core/api/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export const SignApi = {
},
});
},
checkSignUp: (params: CheckSignUpRequestBody) => {
return AuthAPIInstance.get(`email`, {
params,
});
},
signUp: (body: SignUpRequestBody) => {
return AuthAPIInstance.post('signup', body, {});
},
Expand All @@ -28,9 +33,4 @@ export const SignApi = {

return data;
},
checkSignUp: (params: CheckSignUpRequestBody) => {
return AuthAPIInstance.get(`email`, {
params,
});
},
};
Loading