|
| 1 | +import Btn from '@/common/components/Button'; |
| 2 | + |
| 3 | +import * as s from './style.css'; |
| 4 | +import type { TransactionType } from '@/libs/types/item'; |
| 5 | +import type { ItemInfoInterface } from '@/features/detail/types'; |
| 6 | + |
| 7 | +interface PickButtonProps { |
| 8 | + type: TransactionType; |
| 9 | + index: number; |
| 10 | + salePrice: number; |
| 11 | + deposit: number; |
| 12 | + rentalFee: number; |
| 13 | +} |
| 14 | +const PickButton = ({ type, index, salePrice, deposit, rentalFee }: PickButtonProps) => { |
| 15 | + const color = index === 0 ? 'red' : 'blue'; |
| 16 | + const label = type === 'RENTAL' ? 'λμ¬' : 'ꡬ맀'; |
| 17 | + const priceText = |
| 18 | + type === 'RENTAL' |
| 19 | + ? `λμ¬λ£+보μ¦κΈ ${(deposit + rentalFee).toLocaleString()}μ` |
| 20 | + : `νλ§€κ° ${salePrice.toLocaleString()}μ`; |
| 21 | + |
| 22 | + const handlePickClick = () => { |
| 23 | + alert(`${type} μ ν`); |
| 24 | + }; |
| 25 | + |
| 26 | + return ( |
| 27 | + <button className={s.PickButton({ color })} onClick={handlePickClick} aria-label={`${label}, ${priceText}`}> |
| 28 | + <span>{label}</span> |
| 29 | + <p>{priceText}</p> |
| 30 | + </button> |
| 31 | + ); |
| 32 | +}; |
| 33 | + |
| 34 | +interface Props { |
| 35 | + itemInfo: ItemInfoInterface; |
| 36 | +} |
| 37 | +const BottomActions = ({ itemInfo }: Props) => { |
| 38 | + const { transactionTypes, mine, salePrice, deposit, rentalFee } = itemInfo; |
| 39 | + |
| 40 | + // TODO: μ€μ μ‘μ
μΆκ° |
| 41 | + const handleChatClick = () => { |
| 42 | + alert('μ±ν
μ°κ²°'); |
| 43 | + }; |
| 44 | + |
| 45 | + return ( |
| 46 | + <div className={s.Container}> |
| 47 | + <Btn className={s.ChatButton({ isMine: mine })} onClick={handleChatClick}> |
| 48 | + <span className="mgc_chat_2_fill" /> |
| 49 | + {mine && <p>μ±ν
</p>} |
| 50 | + </Btn> |
| 51 | + {!mine && ( |
| 52 | + <div className={s.PickButtonContainer}> |
| 53 | + {transactionTypes.map((type, index) => { |
| 54 | + return ( |
| 55 | + <PickButton |
| 56 | + key={type} |
| 57 | + type={type} |
| 58 | + index={index} |
| 59 | + salePrice={salePrice} |
| 60 | + deposit={deposit} |
| 61 | + rentalFee={rentalFee} |
| 62 | + /> |
| 63 | + ); |
| 64 | + })} |
| 65 | + </div> |
| 66 | + )} |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
| 70 | +export default BottomActions; |
0 commit comments