diff --git a/packages/admin/src/routes/_authenticated.tsx b/packages/admin/src/routes/_authenticated.tsx index d790e1c..64367af 100644 --- a/packages/admin/src/routes/_authenticated.tsx +++ b/packages/admin/src/routes/_authenticated.tsx @@ -1,5 +1,5 @@ import { createFileRoute, Outlet, Link, redirect, useRouter } from '@tanstack/react-router' -import { useQuery } from '@tanstack/react-query' +import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query' import { queryOptions } from '@tanstack/react-query' import { useEffect, useState } from 'react' import { api } from '@/lib/api-client' @@ -9,6 +9,9 @@ import { moduleListOptions } from '@/api/modules' import { Avatar } from '@/components/shared/avatar-upload' import { Button } from '@/components/ui/button' import { Users, UserRound, HelpCircle, Shield, UserCog, LogOut, User, Wrench, Package, ClipboardList, FolderOpen, KeyRound, Settings, PanelLeftClose, PanelLeft, CalendarDays, GraduationCap, CalendarRange, BookOpen, BookMarked, Package2, Tag, Truck, ShoppingCart } from 'lucide-react' +import { Input } from '@/components/ui/input' +import { Label } from '@/components/ui/label' +import { toast } from 'sonner' export const Route = createFileRoute('/_authenticated')({ beforeLoad: () => { @@ -104,6 +107,58 @@ function NavGroup({ label, children, collapsed }: { label: string; children: Rea ) } +function SetPinModal() { + const queryClient = useQueryClient() + const [pin, setPin] = useState('') + const [confirmPin, setConfirmPin] = useState('') + const [error, setError] = useState('') + + const setPinMutation = useMutation({ + mutationFn: () => api.post('/v1/auth/set-pin', { pin }), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['auth', 'me'] }) + toast.success('PIN set successfully') + }, + onError: (err) => setError(err.message), + }) + + function handleSubmit(e: React.FormEvent) { + e.preventDefault() + setError('') + if (pin.length < 4 || pin.length > 6) { setError('PIN must be 4-6 digits'); return } + if (!/^\d+$/.test(pin)) { setError('PIN must be digits only'); return } + if (pin !== confirmPin) { setError('PINs do not match'); return } + setPinMutation.mutate() + } + + return ( +
+ A PIN is required to use the Point of Sale. Choose a 4-6 digit PIN you'll use to unlock the terminal. +
+ +