fix(rental): extract category labels en fichier neutre (importable client)
All checks were successful
CI / test (pull_request) Successful in 2m9s
All checks were successful
CI / test (pull_request) Successful in 2m9s
This commit is contained in:
parent
46d3c2d3ab
commit
90cc7a94af
3 changed files with 24 additions and 30 deletions
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
import { useState, useTransition } from "react";
|
||||
import { FormField, inputCls, selectCls, textareaCls } from "@/components/admin/FormField";
|
||||
import { RENTAL_CATEGORY_LABEL } from "@/lib/admin/rental-items";
|
||||
import { RentalCategory } from "@/generated/prisma/enums";
|
||||
import { RENTAL_CATEGORY_LABEL, RENTAL_CATEGORIES } from "@/lib/rental-category-labels";
|
||||
|
||||
type Props = {
|
||||
providers: { id: string; name: string; isSystemD: boolean }[];
|
||||
|
|
@ -26,14 +25,6 @@ type Props = {
|
|||
submitLabel?: string;
|
||||
};
|
||||
|
||||
const CATEGORIES: RentalCategory[] = [
|
||||
RentalCategory.SLEEP,
|
||||
RentalCategory.NAVIGATION,
|
||||
RentalCategory.FISHING,
|
||||
RentalCategory.COOKING,
|
||||
RentalCategory.SAFETY,
|
||||
];
|
||||
|
||||
export function ItemForm({ providers, initial = {}, action, submitLabel = "Enregistrer" }: Props) {
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
|
@ -66,7 +57,7 @@ export function ItemForm({ providers, initial = {}, action, submitLabel = "Enreg
|
|||
<FormField label="Catégorie" required>
|
||||
<select name="category" defaultValue={initial.category ?? ""} required className={selectCls}>
|
||||
<option value="" disabled>— sélectionner —</option>
|
||||
{CATEGORIES.map((c) => (
|
||||
{RENTAL_CATEGORIES.map((c) => (
|
||||
<option key={c} value={c}>{RENTAL_CATEGORY_LABEL[c]}</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -4,13 +4,7 @@ import { Prisma } from "@/generated/prisma/client";
|
|||
import { RentalCategory } from "@/generated/prisma/enums";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const RENTAL_CATEGORY_LABEL: Record<RentalCategory, string> = {
|
||||
SLEEP: "💤 Couchage",
|
||||
NAVIGATION: "🛶 Navigation",
|
||||
FISHING: "🎣 Pêche",
|
||||
COOKING: "🍳 Cuisine",
|
||||
SAFETY: "🦺 Sécurité",
|
||||
};
|
||||
export { RENTAL_CATEGORY_LABEL, RENTAL_CATEGORIES, isRentalCategory } from "@/lib/rental-category-labels";
|
||||
|
||||
export type AdminRentalItemFilters = {
|
||||
q?: string;
|
||||
|
|
@ -38,18 +32,6 @@ export type AdminRentalItemListItem = {
|
|||
updatedAt: Date;
|
||||
};
|
||||
|
||||
const CATEGORY_VALUES: RentalCategory[] = [
|
||||
RentalCategory.SLEEP,
|
||||
RentalCategory.NAVIGATION,
|
||||
RentalCategory.FISHING,
|
||||
RentalCategory.COOKING,
|
||||
RentalCategory.SAFETY,
|
||||
];
|
||||
|
||||
export function isRentalCategory(v: string): v is RentalCategory {
|
||||
return (CATEGORY_VALUES as string[]).includes(v);
|
||||
}
|
||||
|
||||
export async function listRentalItemsAdmin(
|
||||
filters: AdminRentalItemFilters = {},
|
||||
): Promise<AdminRentalItemListItem[]> {
|
||||
|
|
|
|||
21
src/lib/rental-category-labels.ts
Normal file
21
src/lib/rental-category-labels.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { RentalCategory } from "@/generated/prisma/enums";
|
||||
|
||||
export const RENTAL_CATEGORY_LABEL: Record<RentalCategory, string> = {
|
||||
SLEEP: "💤 Couchage",
|
||||
NAVIGATION: "🛶 Navigation",
|
||||
FISHING: "🎣 Pêche",
|
||||
COOKING: "🍳 Cuisine",
|
||||
SAFETY: "🦺 Sécurité",
|
||||
};
|
||||
|
||||
export const RENTAL_CATEGORIES: RentalCategory[] = [
|
||||
RentalCategory.SLEEP,
|
||||
RentalCategory.NAVIGATION,
|
||||
RentalCategory.FISHING,
|
||||
RentalCategory.COOKING,
|
||||
RentalCategory.SAFETY,
|
||||
];
|
||||
|
||||
export function isRentalCategory(v: string): v is RentalCategory {
|
||||
return (RENTAL_CATEGORIES as string[]).includes(v);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue