|
| 1 | +import { useEffect, useState } from 'react'; |
| 2 | +import { useParams } from 'react-router-dom'; |
| 3 | +import { getDepositsDetail } from '../../shared/api/products'; |
| 4 | +import { formatLimit } from '../../shared/utils/format'; |
| 5 | +import * as styles from './deposit-detail-page.css'; |
| 6 | +import Header from '../../shared/components/header/header'; |
| 7 | + |
| 8 | +type Option = { |
| 9 | + interestType: string; |
| 10 | + saveTerm: number; |
| 11 | + baseRate: number; |
| 12 | + maxRate: number; |
| 13 | +}; |
| 14 | + |
| 15 | +type ProductDetail = { |
| 16 | + productId: number; |
| 17 | + optionId: number; |
| 18 | + bankName: string; |
| 19 | + productName: string; |
| 20 | + joinDeny: string; |
| 21 | + joinMember: string; |
| 22 | + joinWay: string; |
| 23 | + specialCondition: string; |
| 24 | + etcNote: string; |
| 25 | + maxLimit: string; |
| 26 | + maturityInterestInfo: string; |
| 27 | + options: Option[]; |
| 28 | +}; |
| 29 | + |
| 30 | +const DepositDetailPage = () => { |
| 31 | + const { productId, optionId } = useParams(); |
| 32 | + |
| 33 | + // TODO:API 연결 후 mockdata 삭제 |
| 34 | + const mockDetail: ProductDetail = { |
| 35 | + productId: 34, |
| 36 | + optionId: 293, |
| 37 | + bankName: '주식회사 케이뱅크', |
| 38 | + productName: '코드K 정기예금', |
| 39 | + joinDeny: '제한없음', |
| 40 | + joinMember: '만 17세 이상 실명의 개인 및 개인사업자', |
| 41 | + joinWay: '스마트폰', |
| 42 | + specialCondition: '우대조건 없음', |
| 43 | + etcNote: '가입금액 : 1백만원 이상\n가입기간 : 1개월~36개월', |
| 44 | + maxLimit: '제한 없음', |
| 45 | + maturityInterestInfo: |
| 46 | + '만기 후 \n- 1개월 이내 : 만기시점 기본금리 X 50%\n- 1개월 초과~6개월 이내 : 만기시점 기본금리 X 30%\n- 6개월 초과 : 연 0.20%', |
| 47 | + options: [ |
| 48 | + { |
| 49 | + interestType: '단리', |
| 50 | + saveTerm: 6, |
| 51 | + baseRate: 2.86, |
| 52 | + maxRate: 2.86, |
| 53 | + }, |
| 54 | + ], |
| 55 | + }; |
| 56 | + |
| 57 | + // TODO: API 연결 후 주석 삭제 |
| 58 | + //const [detail, setDetail] = useState<ProductDetail | null>(null); |
| 59 | + const [detail, setDetail] = useState<ProductDetail | null>(mockDetail); |
| 60 | + |
| 61 | + useEffect(() => { |
| 62 | + if (!productId || !optionId) return; |
| 63 | + |
| 64 | + getDepositsDetail(Number(productId), Number(optionId)).then((res) => { |
| 65 | + setDetail(res.result); |
| 66 | + }); |
| 67 | + }, [productId, optionId]); |
| 68 | + |
| 69 | + if (!detail) return <div>Loading...</div>; |
| 70 | + |
| 71 | + const option = detail.options[0]; |
| 72 | + |
| 73 | + return ( |
| 74 | + <> |
| 75 | + <Header /> |
| 76 | + <div className={styles.detailContainer}> |
| 77 | + <h2 className={styles.bank}>{detail.bankName}</h2> |
| 78 | + <h1 className={styles.product}>{detail.productName}</h1> |
| 79 | + <div className={styles.detailTextContainer}> |
| 80 | + <div className={styles.textContainer}> |
| 81 | + <h3 className={styles.textTitle}>가입 대상:</h3> |
| 82 | + <p className={styles.textValue}>{detail.joinMember}</p> |
| 83 | + </div> |
| 84 | + <div className={styles.textContainer}> |
| 85 | + <h3 className={styles.textTitle}>가입 방법:</h3> |
| 86 | + <p className={styles.textValue}>{detail.joinWay}</p> |
| 87 | + </div> |
| 88 | + <div className={styles.textContainer}> |
| 89 | + <h3 className={styles.textTitle}>가입 제한:</h3> |
| 90 | + <p className={styles.textValue}>{detail.joinDeny}</p> |
| 91 | + </div> |
| 92 | + <div className={styles.textContainer}> |
| 93 | + <h3 className={styles.textTitle}>최고 한도:</h3> |
| 94 | + <p className={styles.textValue}>{formatLimit(detail.maxLimit)}</p> |
| 95 | + </div> |
| 96 | + <div className={styles.textColContainer}> |
| 97 | + <h3 className={styles.textTitle}>우대 조건</h3> |
| 98 | + <pre className={styles.pre}>{detail.specialCondition}</pre> |
| 99 | + </div> |
| 100 | + <div className={styles.textColContainer}> |
| 101 | + <h3 className={styles.textTitle}>만기 후 이자율</h3> |
| 102 | + <pre className={styles.pre}>{detail.maturityInterestInfo}</pre> |
| 103 | + </div> |
| 104 | + <div className={styles.textColContainer}> |
| 105 | + <h3 className={styles.textTitle}>기타 유의사항</h3> |
| 106 | + <pre className={styles.pre}>{detail.etcNote}</pre> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + |
| 110 | + {option && ( |
| 111 | + <div className={styles.optionContainer}> |
| 112 | + <h3 className={styles.optionText}>상품 옵션 ⭐</h3> |
| 113 | + <div className={styles.optionTextContainer}> |
| 114 | + <h4 className={styles.optionTitle}>이자 유형:</h4> |
| 115 | + <p className={styles.optionValue}>{option.interestType}</p> |
| 116 | + </div> |
| 117 | + <div className={styles.optionTextContainer}> |
| 118 | + <h4 className={styles.optionTitle}>저축 기간:</h4> |
| 119 | + <p className={styles.optionValue}>{option.saveTerm}개월</p> |
| 120 | + </div> |
| 121 | + <div className={styles.optionTextContainer}> |
| 122 | + <h4 className={styles.optionTitle}>기본 금리:</h4> |
| 123 | + <p className={styles.optionValue}>{option.baseRate}%</p> |
| 124 | + </div> |
| 125 | + <div className={styles.optionTextContainer}> |
| 126 | + <h4 className={styles.optionTitle}>최대 금리:</h4> |
| 127 | + <p className={styles.optionValue}>{option.maxRate}%</p> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + )} |
| 131 | + </div> |
| 132 | + |
| 133 | + {/* TODO: 유사 상품 리스트 API 연결 후 구현 */} |
| 134 | + <div className={styles.similarProductsContainer}> |
| 135 | + <div>유사 상품 리스트</div> |
| 136 | + <div>유사 상품 리스트</div> |
| 137 | + </div> |
| 138 | + </> |
| 139 | + ); |
| 140 | +}; |
| 141 | + |
| 142 | +export default DepositDetailPage; |
0 commit comments