Skip to content

Commit df50d6a

Browse files
authored
Merge pull request #55 from pennlabs/james/optional-description
make description optional
2 parents deac4fd + e90c195 commit df50d6a

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

frontend/components/listings/detail/ListingInfo.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { formatDate } from "@/lib/utils";
88
interface Props {
99
title: string;
1010
price: number;
11-
description: string;
11+
description?: string;
1212
category?: string;
1313
condition?: string;
1414
priceLabel?: string;
@@ -19,6 +19,7 @@ interface Props {
1919
}
2020

2121
const MAX_DESCRIPTION_LENGTH = 250;
22+
const NO_DESCRIPTION = "No description";
2223

2324
export const ListingInfo = ({
2425
title,
@@ -33,11 +34,13 @@ export const ListingInfo = ({
3334
end_date,
3435
}: Props) => {
3536
const [isExpanded, setIsExpanded] = useState(false);
36-
const shouldTruncate = description.length > MAX_DESCRIPTION_LENGTH;
37+
const hasDescription = description && description.trim().length > 0;
38+
const descriptionText = hasDescription ? description : NO_DESCRIPTION;
39+
const shouldTruncate = hasDescription && descriptionText.length > MAX_DESCRIPTION_LENGTH;
3740
const displayDescription =
3841
!shouldTruncate || isExpanded
39-
? description
40-
: `${description.slice(0, MAX_DESCRIPTION_LENGTH)}...`;
42+
? descriptionText
43+
: `${descriptionText.slice(0, MAX_DESCRIPTION_LENGTH)}...`;
4144

4245
return (
4346
<div className="space-y-3">

frontend/components/listings/form/BaseListingForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const BaseListingForm = <T extends BaseCreatePayload>({
135135
>
136136
<Textarea
137137
{...field}
138-
placeholder={`Enter ${displayLabel} Description`}
138+
placeholder={`Enter description (optional)`}
139139
className="min-h-[120px] resize-y"
140140
aria-invalid={!!errors.description}
141141
disabled={disabled}

frontend/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export type ListingFiltersMap = {
145145
// ------------------------------------------------------------
146146
export type BaseCreatePayload = {
147147
title: string;
148-
description: string;
148+
description?: string;
149149
price: string;
150150
};
151151

frontend/lib/validations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export const createItemSchema = z.object({
101101
description: z
102102
.string()
103103
.trim()
104-
.min(1, "Description is required")
105-
.max(5000, "Description must be less than 5000 characters"),
104+
.max(5000, "Description must be less than 5000 characters")
105+
.optional(),
106106
price: priceSchema,
107107
tags: z.array(z.string().trim()),
108108
condition: z.enum(itemConditionValues, "Condition is required"),
@@ -121,8 +121,8 @@ export const createSubletSchema = z
121121
description: z
122122
.string()
123123
.trim()
124-
.min(1, "Description is required")
125-
.max(5000, "Description must be less than 5000 characters"),
124+
.max(5000, "Description must be less than 5000 characters")
125+
.optional(),
126126
price: priceSchema,
127127
tags: z.array(z.string().trim()),
128128
street_address: z.string().trim().min(1, "Street address is required"),

0 commit comments

Comments
 (0)