Skip to content

Commit e05db90

Browse files
committed
bug fixes
1 parent 058206c commit e05db90

File tree

7 files changed

+86
-59
lines changed

7 files changed

+86
-59
lines changed

web-next/app/(app)/pos/page.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
import { Suspense } from "react";
2+
import { redirect } from "next/navigation";
3+
import { headers } from "next/headers";
4+
import { auth } from "@/lib/auth";
25
import { getAllStudents } from "@/lib/repositories/students";
36
import { getStudentIdsWithTransactions } from "@/lib/repositories/transactions";
47
import { PosForm } from "./pos-form";
58

69
export const dynamic = "force-dynamic";
710

811
export default async function PosPage() {
12+
const session = await auth.api.getSession({
13+
headers: await headers(),
14+
});
15+
16+
if (!session) {
17+
redirect("/login");
18+
}
19+
920
const students = getAllStudents();
1021
const studentIdsWithTransactions = getStudentIdsWithTransactions();
1122

1223
return (
1324
<Suspense fallback={<div>Loading...</div>}>
14-
<PosForm students={students} studentIdsWithTransactions={studentIdsWithTransactions} />
25+
<PosForm
26+
students={students}
27+
studentIdsWithTransactions={studentIdsWithTransactions}
28+
userName={session.user.name}
29+
/>
1530
</Suspense>
1631
);
1732
}

web-next/app/(app)/pos/pos-form.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ import { useNFCWebSocket } from "@/lib/use-nfc-websocket";
3636
interface PosFormProps {
3737
students: StudentWithAccount[];
3838
studentIdsWithTransactions: number[];
39+
userName: string;
3940
}
4041

4142
type WorkflowMode = "tap-first" | "manual";
4243

43-
export function PosForm({ students, studentIdsWithTransactions }: PosFormProps) {
44+
export function PosForm({ students, studentIdsWithTransactions, userName }: PosFormProps) {
4445
const [mode, setMode] = useState<WorkflowMode>("tap-first");
4546
const [studentId, setStudentId] = useState<string>("");
4647
const [cardUid, setCardUid] = useState<string>("");
@@ -55,6 +56,13 @@ export function PosForm({ students, studentIdsWithTransactions }: PosFormProps)
5556
const router = useRouter();
5657
const searchParams = useSearchParams();
5758

59+
// Auto-fill staff name with current user's name
60+
useEffect(() => {
61+
if (userName && !staff) {
62+
setStaff(userName);
63+
}
64+
}, [userName, staff]);
65+
5866
// Dialog state for Tap mode
5967
const [dialogOpen, setDialogOpen] = useState(false);
6068
const [dialogStudentId, setDialogStudentId] = useState<number>(0);
@@ -65,6 +73,13 @@ export function PosForm({ students, studentIdsWithTransactions }: PosFormProps)
6573
const [dialogError, setDialogError] = useState("");
6674
const [dialogLoading, setDialogLoading] = useState(false);
6775

76+
// Auto-fill dialog staff name with current user's name
77+
useEffect(() => {
78+
if (userName && !dialogStaff) {
79+
setDialogStaff(userName);
80+
}
81+
}, [userName, dialogStaff]);
82+
6883
// Enrollment dialog state for unknown cards
6984
const [enrollDialogOpen, setEnrollDialogOpen] = useState(false);
7085
const [enrollCardUid, setEnrollCardUid] = useState<string>("");
@@ -148,7 +163,7 @@ export function PosForm({ students, studentIdsWithTransactions }: PosFormProps)
148163
setDialogCardUid(uid);
149164
setDialogAmount("");
150165
setDialogDescription("");
151-
setDialogStaff("");
166+
setDialogStaff(userName);
152167
setDialogError("");
153168
setDialogOpen(true);
154169
};
@@ -193,7 +208,7 @@ export function PosForm({ students, studentIdsWithTransactions }: PosFormProps)
193208
setDialogCardUid(enrollCardUid);
194209
setDialogAmount("");
195210
setDialogDescription("");
196-
setDialogStaff("");
211+
setDialogStaff(userName);
197212
setDialogError("");
198213
setDialogOpen(true);
199214
} else if (action === 'topup') {

web-next/app/(app)/topup/page.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
import { Suspense } from "react";
2+
import { redirect } from "next/navigation";
3+
import { headers } from "next/headers";
4+
import { auth } from "@/lib/auth";
25
import { getAllStudents } from "@/lib/repositories/students";
36
import { getStudentIdsWithTransactions } from "@/lib/repositories/transactions";
47
import { TopupForm } from "./topup-form";
58

69
export const dynamic = "force-dynamic";
710

811
export default async function TopupPage() {
12+
const session = await auth.api.getSession({
13+
headers: await headers(),
14+
});
15+
16+
if (!session) {
17+
redirect("/login");
18+
}
19+
920
const students = getAllStudents();
1021
const studentIdsWithTransactions = getStudentIdsWithTransactions();
1122

1223
return (
1324
<Suspense fallback={<div>Loading...</div>}>
14-
<TopupForm students={students} studentIdsWithTransactions={studentIdsWithTransactions} />
25+
<TopupForm
26+
students={students}
27+
studentIdsWithTransactions={studentIdsWithTransactions}
28+
userName={session.user.name}
29+
/>
1530
</Suspense>
1631
);
1732
}

web-next/app/(app)/topup/topup-form.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import { toDisplayValue, formatCurrency } from "@/lib/currency";
2323
interface TopupFormProps {
2424
students: StudentWithAccount[];
2525
studentIdsWithTransactions: number[];
26+
userName: string;
2627
}
2728

28-
export function TopupForm({ students, studentIdsWithTransactions }: TopupFormProps) {
29+
export function TopupForm({ students, studentIdsWithTransactions, userName }: TopupFormProps) {
2930
const [studentId, setStudentId] = useState<string>("");
3031
const [amount, setAmount] = useState("");
3132
const [description, setDescription] = useState("");
@@ -38,6 +39,13 @@ export function TopupForm({ students, studentIdsWithTransactions }: TopupFormPro
3839
const router = useRouter();
3940
const searchParams = useSearchParams();
4041

42+
// Auto-fill staff name with current user's name
43+
useEffect(() => {
44+
if (userName && !staff) {
45+
setStaff(userName);
46+
}
47+
}, [userName, staff]);
48+
4149
// Auto-select student from query parameter
4250
useEffect(() => {
4351
const studentFromUrl = searchParams.get("student");
@@ -53,12 +61,20 @@ export function TopupForm({ students, studentIdsWithTransactions }: TopupFormPro
5361
const [adjustAmount, setAdjustAmount] = useState("");
5462
const [adjustDescription, setAdjustDescription] = useState("");
5563
const [adjustStaff, setAdjustStaff] = useState("");
64+
5665
const [adjustError, setAdjustError] = useState("");
5766
const [adjustSuccess, setAdjustSuccess] = useState("");
5867
const [adjustTransactionId, setAdjustTransactionId] = useState<number | null>(null);
5968
const [adjustCopied, setAdjustCopied] = useState(false);
6069
const [adjustLoading, setAdjustLoading] = useState(false);
6170

71+
// Auto-fill adjust staff name with current user's name
72+
useEffect(() => {
73+
if (userName && !adjustStaff) {
74+
setAdjustStaff(userName);
75+
}
76+
}, [userName, adjustStaff]);
77+
6278
const selectedStudent = students.find((s) => s.id === parseInt(studentId));
6379
const selectedAdjustStudent = students.find((s) => s.id === parseInt(adjustStudentId));
6480

web-next/app/(auth)/login/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default function LoginPage() {
107107
<span className="w-full border-t" />
108108
</div>
109109
<div className="relative flex justify-center text-xs uppercase">
110-
<span className="bg-background px-2 text-muted-foreground">
110+
<span className="bg-card px-2 text-muted-foreground">
111111
Or continue with
112112
</span>
113113
</div>

web-next/app/(auth)/signup/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default function SignupPage() {
174174
<span className="w-full border-t" />
175175
</div>
176176
<div className="relative flex justify-center text-xs uppercase">
177-
<span className="bg-background px-2 text-muted-foreground">
177+
<span className="bg-card px-2 text-muted-foreground">
178178
Or continue with
179179
</span>
180180
</div>

web-next/components/app-sidebar.tsx

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
Sun,
1818
Eye,
1919
EyeOff,
20-
Palette,
2120
} from "lucide-react"
2221
import { useTheme } from "next-themes"
2322

@@ -212,7 +211,7 @@ export function AppSidebar({ user: initialUser, ...props }: AppSidebarProps) {
212211
try {
213212
const { data, error } = await authClient.updateUser({
214213
name: formData.name,
215-
image: formData.image || undefined,
214+
image: formData.image || null,
216215
})
217216

218217
if (error) {
@@ -443,10 +442,9 @@ export function AppSidebar({ user: initialUser, ...props }: AppSidebarProps) {
443442
</DialogDescription>
444443
</DialogHeader>
445444
<Tabs defaultValue="profile" className="w-full">
446-
<TabsList className="grid w-full grid-cols-3">
445+
<TabsList className="grid w-full grid-cols-2">
447446
<TabsTrigger value="profile">Profile</TabsTrigger>
448447
<TabsTrigger value="security">Security</TabsTrigger>
449-
<TabsTrigger value="preferences">Preferences</TabsTrigger>
450448
</TabsList>
451449
<TabsContent value="profile" className="space-y-4">
452450
<div className="space-y-2">
@@ -482,10 +480,21 @@ export function AppSidebar({ user: initialUser, ...props }: AppSidebarProps) {
482480
{formData.image && (
483481
<div className="mt-3">
484482
<Label className="text-xs text-muted-foreground mb-2 block">Preview:</Label>
485-
<Avatar className="h-16 w-16">
486-
<AvatarImage src={formData.image} alt={formData.name} />
487-
<AvatarFallback>{formData.name.charAt(0).toUpperCase()}</AvatarFallback>
488-
</Avatar>
483+
<div className="flex items-center gap-3">
484+
<Avatar className="h-16 w-16">
485+
<AvatarImage src={formData.image} alt={formData.name} />
486+
<AvatarFallback>{formData.name.charAt(0).toUpperCase()}</AvatarFallback>
487+
</Avatar>
488+
<Button
489+
type="button"
490+
variant="outline"
491+
size="sm"
492+
onClick={() => handleFormChange("image", "")}
493+
disabled={loading}
494+
>
495+
Remove Picture
496+
</Button>
497+
</div>
489498
</div>
490499
)}
491500
</div>
@@ -637,49 +646,6 @@ export function AppSidebar({ user: initialUser, ...props }: AppSidebarProps) {
637646
</div>
638647
</div>
639648
</TabsContent>
640-
<TabsContent value="preferences" className="space-y-4">
641-
<div className="space-y-4">
642-
<div>
643-
<h3 className="text-sm font-semibold mb-1">Appearance</h3>
644-
<p className="text-xs text-muted-foreground">
645-
Customize how the application looks on your device
646-
</p>
647-
</div>
648-
649-
<div className="flex items-center justify-between p-4 border rounded-lg">
650-
<div className="flex items-center gap-3">
651-
{resolvedTheme === "dark" ? (
652-
<Moon className="h-5 w-5 text-muted-foreground" />
653-
) : (
654-
<Sun className="h-5 w-5 text-muted-foreground" />
655-
)}
656-
<div>
657-
<Label className="text-sm font-medium">Theme</Label>
658-
<p className="text-xs text-muted-foreground">
659-
{resolvedTheme === "dark" ? "Dark mode" : "Light mode"}
660-
</p>
661-
</div>
662-
</div>
663-
<Button
664-
variant="outline"
665-
size="sm"
666-
onClick={handleToggleTheme}
667-
>
668-
{resolvedTheme === "dark" ? (
669-
<>
670-
<Sun className="mr-2 h-4 w-4" />
671-
Light
672-
</>
673-
) : (
674-
<>
675-
<Moon className="mr-2 h-4 w-4" />
676-
Dark
677-
</>
678-
)}
679-
</Button>
680-
</div>
681-
</div>
682-
</TabsContent>
683649
</Tabs>
684650
</DialogContent>
685651
</Dialog>

0 commit comments

Comments
 (0)