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] 임대가격 0원 가능하도록 구현 #319

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions src/components/Trade/Board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ export default function TradeBoard({
const [hiddenTags, setHiddenTags] = useState<string[]>([]);
const ulRef = useRef<HTMLUListElement>(null);

let displayPrice = '';

if (price === 0) {
displayPrice = '무료';
} else if (convertRentalTypeName(rentalType) === '월세') {
displayPrice = `보증금 ${priceCount(price)} / 월세 ${priceCount(
monthlyPrice,
)}`;
} else {
displayPrice = `${convertRentalTypeName(rentalType)} ${priceCount(price)}`;
}

const checkAndManageTags = () => {
if (ulRef.current) {
const containerWidth = ulRef.current.offsetWidth;
Expand Down Expand Up @@ -104,11 +116,8 @@ export default function TradeBoard({
<p>
<strong>위치</strong> : {city}
</p>
<p>
<strong>가격</strong> :{' '}
{convertRentalTypeName(rentalType) === '월세'
? `보증금 ${priceCount(price)} / 월세 ${priceCount(monthlyPrice)}`
: `${convertRentalTypeName(rentalType)} ${priceCount(price)}`}
<p style={{ fontWeight: displayPrice === '무료' ? 600 : undefined }}>
<strong>가격</strong> : {displayPrice}
</p>
<ul ref={ulRef} className={styles.tagWrapper}>
{visibleTags.map((tag, index) => (
Expand Down
7 changes: 5 additions & 2 deletions src/components/Trade/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ function TradeBoardInfo({ info }: TradeBoardInfoProps) {
<div>
가격{' '}
<p>
{info?.rentalType && getRentalName(info?.rentalType)}{' '}
{info?.price && priceCount(info?.price)}
{info?.price === 0
? '무료'
: `${info?.rentalType && getRentalName(info?.rentalType)} ${
info?.price && priceCount(info?.price)
}`}
</p>
</div>
<div>
Expand Down
64 changes: 51 additions & 13 deletions src/pages/Trade/Write/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default function TradeWritePage() {

const { state }: { state: { data: TradeBoardDetailType } } = useLocation();

const priceRef = useRef<HTMLInputElement>(null);
const montlyPriceRef = useRef<HTMLInputElement>(null);

const [form, setForm] = useState<TradeBoardForm>({
houseType: state ? state.data.houseType : 'LAND',
rentalType: state ? state.data.rentalType : 'SALE',
Expand Down Expand Up @@ -111,6 +114,28 @@ export default function TradeWritePage() {
return returnString;
};

const onCheckFree = (e: React.ChangeEvent<HTMLInputElement>) => {
const isChecked = e.currentTarget.checked;
if (isChecked) {
setForm((prev) => {
return { ...prev, price: 0, monthlyPrice: 0 };
});
if (priceRef.current) {
priceRef.current.disabled = true;
}
if (montlyPriceRef.current) {
montlyPriceRef.current.disabled = true;
}
} else {
if (priceRef.current) {
priceRef.current.disabled = false;
}
if (montlyPriceRef.current) {
montlyPriceRef.current.disabled = false;
}
}
};

const thumbnailHandler = async (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.currentTarget.files !== null) {
const file = e.currentTarget.files[0];
Expand Down Expand Up @@ -301,18 +326,30 @@ export default function TradeWritePage() {
value={form.detail}
/>
</div>
<div>
<label htmlFor="임대 가격">
{getRentalPriceType(form.rentalType)}
<span className={styles.essential}>*</span>
</label>
<input
id="임대 가격"
placeholder="만원 단위로 표기"
name="price"
value={addComma(form.price) || ''}
onChange={onChangePoints}
/>
<div className={styles.additionalInfoContainer}>
<div>
<label htmlFor="임대 가격">
{getRentalPriceType(form.rentalType)}
<span className={styles.essential}>*</span>
</label>
<input
ref={priceRef}
id="임대 가격"
placeholder="만원 단위로 표기"
name="price"
value={addComma(form.price) || ''}
onChange={onChangePoints}
/>
</div>
<span className={styles.checkboxContainer}>
<input
id="free"
type="checkbox"
value="무료 매물"
onChange={onCheckFree}
/>
<label htmlFor="free">무료 매물</label>
</span>
</div>
<div
style={{
Expand All @@ -323,6 +360,7 @@ export default function TradeWritePage() {
월세<span className={styles.essential}>*</span>
</label>
<input
ref={montlyPriceRef}
id="월세"
placeholder="만원 단위로 표기"
name="monthlyPrice"
Expand Down Expand Up @@ -388,7 +426,7 @@ export default function TradeWritePage() {
<span>기본 정보</span>
<p>*는 필수로 입력해야 하는 값입니다.</p>
<div>
<div className={styles.additionalIinfoContainer}>
<div className={styles.additionalInfoContainer}>
<div>
<label htmlFor="매물 면적">
매물 면적<span className={styles.essential}>*</span>
Expand Down
Loading