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

annagu/sort-cat-alphabetically #75

Merged
merged 6 commits into from
Jun 15, 2024
Merged
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
13 changes: 6 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ enum Location {
}

enum Category {
CLOTHING
BEVERAGE_CONTAINER
CHARGER
UMBRELLA
CLOTHING
EARBUDS_HEADPHONES_CASES
GLASSES_CASES
JEWELRY_WATCHES
EARBUDS_HEADPHONES_CASES
KEYS
PHONES_LAPTOPS_TABLETS
BEVERAGE_CONTAINER
STATIONARY
KEYS
UMBRELLA
OTHER
}

Expand Down Expand Up @@ -81,8 +81,7 @@ enum Status {
}

enum Value {
LOW
MEDIUM
GENERAL
HIGH
}

Expand Down
1 change: 1 addition & 0 deletions src/components/Form/Listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function MyListbox<T, K extends FieldValues>({
? field.value?.length > 0
? field.value
.map((value: T) => displayValue(value))
.sort()
.join(', ')
: placeholder
: field.value
Expand Down
3 changes: 2 additions & 1 deletion src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export const clientSchema = z.object({
*/
export const clientEnv = {
// NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
};
5 changes: 4 additions & 1 deletion src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const ItemSchema = z.object({
shortDescription: z.string().min(3),
categories: z.array(z.nativeEnum(Category)),
color: z.nativeEnum(Color),
value: z.nativeEnum(Value),
value: z.nativeEnum(Value, {
required_error: 'Required',
invalid_type_error: 'Required'
}),
identifiable: z.boolean(),
itemLocation: z.string().min(3),
retrieveLocation: z.nativeEnum(Location),
Expand Down
10 changes: 9 additions & 1 deletion src/pages/manage/items/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ const CreateItem: NextPageWithLayout = () => {
</span>
</label>
<MyListbox
values={Object.values(Category)}
values={Object.values(Category).sort((a, b) => {
if (a === 'OTHER') {
return 1;
}
if (b === 'OTHER') {
return -1;
}
return a.localeCompare(b);
})}
displayValue={(prop) => Categories[prop]}
keyValue={(prop) => prop}
name="categories"
Expand Down
2 changes: 1 addition & 1 deletion src/server/trpc/router/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default router({
ctx.prisma.account.delete({
where: { clerkId: input }
})
),
)
});
10 changes: 5 additions & 5 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export const Colors: Record<Color, string> = {
OTHER: 'Other'
};
export const Categories: Record<Category, string> = {
CLOTHING: 'Clothing',
BEVERAGE_CONTAINER: 'Beverage Container',
CHARGER: 'Charger',
UMBRELLA: 'Umbrellas',
CLOTHING: 'Clothing',
EARBUDS_HEADPHONES_CASES: 'Earbuds/Headphones/Case',
GLASSES_CASES: 'Glasses/Sunglasses/Cases',
JEWELRY_WATCHES: 'Jewelry/Watches',
EARBUDS_HEADPHONES_CASES: 'Earbuds/Headphones/Case',
KEYS: 'Keys',
PHONES_LAPTOPS_TABLETS: 'Phones/Laptops/Tablets',
BEVERAGE_CONTAINER: 'Beverage Container',
STATIONARY: 'Stationary',
KEYS: 'Keys',
UMBRELLA: 'Umbrellas',
OTHER: 'Other'
};
Loading