import { createFileRoute, Link } from '@tanstack/react-router' import { useState } from 'react' import { Stack, SimpleGrid, Card, Text, Group, Badge, Loader, Center, Drawer, TextInput, NumberInput, Select, Textarea, Button, ActionIcon, Tooltip, } from '@pikku/mantine/core' import { Pencil, Search, Plus } from 'lucide-react' import { useQueryClient } from '@tanstack/react-query' import { notifications } from '@mantine/notifications' import { usePikkuQuery, usePikkuMutation } from '@perauset/functions-sdk/pikku/api.gen' import { usePermission } from '@/lib/permissions' import { PageHeader } from '@perauset/components' import { m } from '@/i18n/messages' import { useLocale } from '@/i18n/config' import { asI18n } from '@pikku/react' type RoomType = 'dorm' | 'facilitator' | 'private' | 'shared' | 'staff' export const Route = createFileRoute('/_authenticated/rooms/')({ component: RoomsPage, }) type Room = { roomId: string code: string name: string roomType: string capacity: number pricePerNight: number | null isActive: boolean notes: string | null } const ROOM_TYPES = [ { value: 'dorm', label: 'Dorm' }, { value: 'facilitator', label: 'Facilitator' }, { value: 'private', label: 'Private' }, { value: 'shared', label: 'Shared' }, { value: 'staff', label: 'Staff' }, ] const cardStyle = { backgroundColor: '#ffffff', boxShadow: '0 2px 12px rgba(61, 43, 31, 0.08), 0 1px 4px rgba(61, 43, 31, 0.04)', } function formatType(type: string): string { return type.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()) } function RoomActions({ onCreateRoom }: { onCreateRoom?: () => void }) { const canManage = usePermission('rooms.manage') if (!canManage) return null return ( ) } function CreateRoomDrawer({ opened, onClose }: { opened: boolean; onClose: () => void }) { const queryClient = useQueryClient() const [code, setCode] = useState('') const [name, setName] = useState('') const [roomType, setRoomType] = useState(null) const [capacity, setCapacity] = useState(1) const [pricePerNight, setPricePerNight] = useState(undefined) const [notes, setNotes] = useState('') const resetForm = () => { setCode('') setName('') setRoomType(null) setCapacity(1) setPricePerNight(undefined) setNotes('') } const mutation = usePikkuMutation('createRoom', { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['listRooms'] }) notifications.show({ title: 'Room created', message: 'New room has been added.', color: 'green' }) resetForm() onClose() }, onError: (err) => notifications.show({ title: 'Error', message: err.message || 'Failed to create room.', color: 'red' }), }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!code || !name || !roomType) { notifications.show({ title: 'Missing fields', message: 'Code, name, and room type are required.', color: 'red' }) return } mutation.mutate({ code, name, roomType, capacity, pricePerNight: pricePerNight || undefined, notes: notes || undefined, }) } return (
setCode(e.currentTarget.value)} required /> setName(e.currentTarget.value)} required />