insuranceCred half
This commit is contained in:
@@ -5,7 +5,7 @@ import userRoutes from './users'
|
|||||||
import staffRoutes from './staffs'
|
import staffRoutes from './staffs'
|
||||||
import pdfExtractionRoutes from './pdfExtraction';
|
import pdfExtractionRoutes from './pdfExtraction';
|
||||||
import claimsRoutes from './claims';
|
import claimsRoutes from './claims';
|
||||||
|
import insuranceCredsRoutes from './insuranceCreds';
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.use('/patients', patientRoutes);
|
router.use('/patients', patientRoutes);
|
||||||
@@ -14,5 +14,6 @@ router.use('/users', userRoutes);
|
|||||||
router.use('/staffs', staffRoutes);
|
router.use('/staffs', staffRoutes);
|
||||||
router.use('/pdfExtraction', pdfExtractionRoutes);
|
router.use('/pdfExtraction', pdfExtractionRoutes);
|
||||||
router.use('/claims', claimsRoutes);
|
router.use('/claims', claimsRoutes);
|
||||||
|
router.use('/insuranceCreds', insuranceCredsRoutes);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
79
apps/Backend/src/routes/insuranceCreds.ts
Normal file
79
apps/Backend/src/routes/insuranceCreds.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import express, { Request, Response, NextFunction } from "express";
|
||||||
|
import { storage } from "../storage";
|
||||||
|
import { InsuranceCredentialUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// ✅ Types
|
||||||
|
type InsuranceCredential = z.infer<typeof InsuranceCredentialUncheckedCreateInputObjectSchema>;
|
||||||
|
|
||||||
|
const insertInsuranceCredentialSchema = (
|
||||||
|
InsuranceCredentialUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||||
|
).omit({ id: true });
|
||||||
|
|
||||||
|
type InsertInsuranceCredential = z.infer<typeof insertInsuranceCredentialSchema>;
|
||||||
|
|
||||||
|
// ✅ Get all credentials for a user
|
||||||
|
router.get("/", async (req: Request, res: Response):Promise<any> => {
|
||||||
|
try {
|
||||||
|
if (!req.user || !req.user.id) {
|
||||||
|
return res.status(401).json({ message: "Unauthorized: user info missing" });
|
||||||
|
}
|
||||||
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
const credentials = await storage.getInsuranceCredentialsByUser(userId);
|
||||||
|
return res.status(200).json(credentials);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).json({ error: "Failed to fetch credentials", details: String(err) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Create credential for a user
|
||||||
|
router.post("/", async (req: Request, res: Response):Promise<any> => {
|
||||||
|
try {
|
||||||
|
if (!req.user || !req.user.id) {
|
||||||
|
return res.status(401).json({ message: "Unauthorized: user info missing" });
|
||||||
|
}
|
||||||
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
const parseResult = insertInsuranceCredentialSchema.safeParse({ ...req.body, userId });
|
||||||
|
if (!parseResult.success) {
|
||||||
|
return res.status(400).json({ error: parseResult.error.flatten() });
|
||||||
|
}
|
||||||
|
|
||||||
|
const credential = await storage.createInsuranceCredential(parseResult.data);
|
||||||
|
return res.status(201).json(credential);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).json({ error: "Failed to create credential", details: String(err) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Update credential
|
||||||
|
router.put("/:id", async (req: Request, res: Response):Promise<any> => {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (isNaN(id)) return res.status(400).send("Invalid credential ID");
|
||||||
|
|
||||||
|
const updates = req.body as Partial<InsuranceCredential>;
|
||||||
|
const credential = await storage.updateInsuranceCredential(id, updates);
|
||||||
|
return res.status(200).json(credential);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).json({ error: "Failed to update credential", details: String(err) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Delete a credential
|
||||||
|
router.delete("/:id", async (req: Request, res: Response):Promise<any> => {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (isNaN(id)) return res.status(400).send("Invalid ID");
|
||||||
|
|
||||||
|
await storage.deleteInsuranceCredential(id);
|
||||||
|
return res.status(204).send();
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).json({ error: "Failed to delete credential", details: String(err) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
@@ -3,6 +3,9 @@ import type { Request, Response } from "express";
|
|||||||
import { storage } from "../storage";
|
import { storage } from "../storage";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { UserUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
import { UserUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
import bcrypt from 'bcrypt';
|
||||||
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -64,6 +67,13 @@ router.post("/", async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Function to hash password using bcrypt
|
||||||
|
async function hashPassword(password: string) {
|
||||||
|
const saltRounds = 10; // Salt rounds for bcrypt
|
||||||
|
const hashedPassword = await bcrypt.hash(password, saltRounds);
|
||||||
|
return hashedPassword;
|
||||||
|
}
|
||||||
|
|
||||||
// PUT: Update user
|
// PUT: Update user
|
||||||
router.put("/:id", async (req: Request, res: Response):Promise<any> => {
|
router.put("/:id", async (req: Request, res: Response):Promise<any> => {
|
||||||
try {
|
try {
|
||||||
@@ -75,6 +85,15 @@ router.put("/:id", async (req: Request, res: Response):Promise<any> => {
|
|||||||
|
|
||||||
|
|
||||||
const updates = userUpdateSchema.parse(req.body);
|
const updates = userUpdateSchema.parse(req.body);
|
||||||
|
|
||||||
|
// If password is provided and non-empty, hash it
|
||||||
|
if (updates.password && updates.password.trim() !== "") {
|
||||||
|
updates.password = await hashPassword(updates.password);
|
||||||
|
} else {
|
||||||
|
// Remove password field if empty, so it won't overwrite existing password with blank
|
||||||
|
delete updates.password;
|
||||||
|
}
|
||||||
|
|
||||||
const updatedUser = await storage.updateUser(id, updates);
|
const updatedUser = await storage.updateUser(id, updates);
|
||||||
if (!updatedUser) return res.status(404).send("User not found");
|
if (!updatedUser) return res.status(404).send("User not found");
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
UserUncheckedCreateInputObjectSchema,
|
UserUncheckedCreateInputObjectSchema,
|
||||||
StaffUncheckedCreateInputObjectSchema,
|
StaffUncheckedCreateInputObjectSchema,
|
||||||
ClaimUncheckedCreateInputObjectSchema,
|
ClaimUncheckedCreateInputObjectSchema,
|
||||||
|
InsuranceCredentialUncheckedCreateInputObjectSchema,
|
||||||
} from "@repo/db/usedSchemas";
|
} from "@repo/db/usedSchemas";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -118,6 +119,19 @@ type UpdateClaim = z.infer<typeof updateClaimSchema>;
|
|||||||
|
|
||||||
type Claim = z.infer<typeof ClaimUncheckedCreateInputObjectSchema>;
|
type Claim = z.infer<typeof ClaimUncheckedCreateInputObjectSchema>;
|
||||||
|
|
||||||
|
// InsuraneCreds types:
|
||||||
|
type InsuranceCredential = z.infer<
|
||||||
|
typeof InsuranceCredentialUncheckedCreateInputObjectSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
const insertInsuranceCredentialSchema = (
|
||||||
|
InsuranceCredentialUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||||
|
).omit({ id: true });
|
||||||
|
|
||||||
|
type InsertInsuranceCredential = z.infer<
|
||||||
|
typeof insertInsuranceCredentialSchema
|
||||||
|
>;
|
||||||
|
|
||||||
export interface IStorage {
|
export interface IStorage {
|
||||||
// User methods
|
// User methods
|
||||||
getUser(id: number): Promise<User | undefined>;
|
getUser(id: number): Promise<User | undefined>;
|
||||||
@@ -160,6 +174,17 @@ export interface IStorage {
|
|||||||
createClaim(claim: InsertClaim): Promise<Claim>;
|
createClaim(claim: InsertClaim): Promise<Claim>;
|
||||||
updateClaim(id: number, updates: UpdateClaim): Promise<Claim>;
|
updateClaim(id: number, updates: UpdateClaim): Promise<Claim>;
|
||||||
deleteClaim(id: number): Promise<void>;
|
deleteClaim(id: number): Promise<void>;
|
||||||
|
|
||||||
|
// InsuranceCredential methods
|
||||||
|
getInsuranceCredentialsByUser(userId: number): Promise<InsuranceCredential[]>;
|
||||||
|
createInsuranceCredential(
|
||||||
|
data: InsertInsuranceCredential
|
||||||
|
): Promise<InsuranceCredential>;
|
||||||
|
updateInsuranceCredential(
|
||||||
|
id: number,
|
||||||
|
updates: Partial<InsuranceCredential>
|
||||||
|
): Promise<InsuranceCredential>;
|
||||||
|
deleteInsuranceCredential(id: number): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const storage: IStorage = {
|
export const storage: IStorage = {
|
||||||
@@ -356,4 +381,27 @@ export const storage: IStorage = {
|
|||||||
throw new Error(`Claim with ID ${id} not found`);
|
throw new Error(`Claim with ID ${id} not found`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Insurance Creds
|
||||||
|
async getInsuranceCredentialsByUser(userId: number) {
|
||||||
|
return await db.insuranceCredential.findMany({ where: { userId } });
|
||||||
|
},
|
||||||
|
|
||||||
|
async createInsuranceCredential(data: InsertInsuranceCredential) {
|
||||||
|
return await db.insuranceCredential.create({ data: data as InsuranceCredential });
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateInsuranceCredential(
|
||||||
|
id: number,
|
||||||
|
updates: Partial<InsuranceCredential>
|
||||||
|
) {
|
||||||
|
return await db.insuranceCredential.update({
|
||||||
|
where: { id },
|
||||||
|
data: updates,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteInsuranceCredential(id: number) {
|
||||||
|
await db.insuranceCredential.delete({ where: { id } });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
113
apps/Frontend/src/components/settings/InsuranceCredForm.tsx
Normal file
113
apps/Frontend/src/components/settings/InsuranceCredForm.tsx
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { apiRequest } from "@/lib/queryClient";
|
||||||
|
import { toast } from "@/hooks/use-toast";
|
||||||
|
|
||||||
|
type CredentialFormProps = {
|
||||||
|
onClose: () => void;
|
||||||
|
userId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CredentialForm({ onClose, userId }: CredentialFormProps) {
|
||||||
|
const [siteKey, setSiteKey] = useState("");
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const createCredentialMutation = useMutation({
|
||||||
|
mutationFn: async () => {
|
||||||
|
const payload = {
|
||||||
|
siteKey: siteKey.trim(),
|
||||||
|
username: username.trim(),
|
||||||
|
password: password.trim(),
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await apiRequest("POST", "/api/insuranceCreds/", payload);
|
||||||
|
if (!res.ok) {
|
||||||
|
const errorData = await res.json().catch(() => null);
|
||||||
|
throw new Error(errorData?.message || "Failed to create credential");
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast({ title: "Credential created." });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["/api/insuranceCreds/"] });
|
||||||
|
onClose();
|
||||||
|
},
|
||||||
|
onError: (error: any) => {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: error.message || "Unknown error",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!siteKey || !username || !password) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: "All fields are required.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createCredentialMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50">
|
||||||
|
<div className="bg-white rounded-lg p-6 w-full max-w-md shadow-lg">
|
||||||
|
<h2 className="text-lg font-bold mb-4">Create Credential</h2>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium">Site Key</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={siteKey}
|
||||||
|
onChange={(e) => setSiteKey(e.target.value)}
|
||||||
|
className="mt-1 p-2 border rounded w-full"
|
||||||
|
placeholder="e.g., github, slack"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium">Username</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
className="mt-1 p-2 border rounded w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium">Password</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
className="mt-1 p-2 border rounded w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
className="text-gray-600 hover:underline"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={createCredentialMutation.isPending}
|
||||||
|
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
|
||||||
|
>
|
||||||
|
{createCredentialMutation.isPending ? "Creating..." : "Create"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
57
apps/Frontend/src/components/settings/insuranceCredTable.tsx
Normal file
57
apps/Frontend/src/components/settings/insuranceCredTable.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// components/CredentialTable.tsx
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { apiRequest } from "@/lib/queryClient";
|
||||||
|
import { toast } from "@/hooks/use-toast";
|
||||||
|
|
||||||
|
type Credential = {
|
||||||
|
id: number;
|
||||||
|
siteKey: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CredentialTable() {
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
queryKey: ["/api/credentials/"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await apiRequest("GET", "/api/insuranceCreds/");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("Failed to fetch credentials");
|
||||||
|
}
|
||||||
|
return res.json() as Promise<Credential[]>;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isLoading) return <p className="text-gray-600">Loading credentials...</p>;
|
||||||
|
if (error) return <p className="text-red-600">Failed to load credentials.</p>;
|
||||||
|
if (!data || data.length === 0)
|
||||||
|
return <p className="text-gray-600">No credentials found.</p>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="min-w-full border rounded shadow">
|
||||||
|
<thead className="bg-gray-100">
|
||||||
|
<tr>
|
||||||
|
<th className="px-4 py-2 text-left">Site</th>
|
||||||
|
<th className="px-4 py-2 text-left">Username</th>
|
||||||
|
<th className="px-4 py-2 text-left">Password</th>
|
||||||
|
<th className="px-4 py-2 text-right">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{data.map((cred) => (
|
||||||
|
<tr key={cred.id} className="border-t">
|
||||||
|
<td className="px-4 py-2">{cred.siteKey}</td>
|
||||||
|
<td className="px-4 py-2">{cred.username}</td>
|
||||||
|
<td className="px-4 py-2 font-mono">{cred.password}</td>
|
||||||
|
<td className="px-4 py-2 text-right space-x-2">
|
||||||
|
<button className="text-blue-600 hover:underline">Edit</button>
|
||||||
|
<button className="text-red-600 hover:underline">Delete</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ import { z } from "zod";
|
|||||||
import { apiRequest, queryClient } from "@/lib/queryClient";
|
import { apiRequest, queryClient } from "@/lib/queryClient";
|
||||||
import { StaffForm } from "@/components/staffs/staff-form";
|
import { StaffForm } from "@/components/staffs/staff-form";
|
||||||
import { DeleteConfirmationDialog } from "@/components/ui/deleteDialog";
|
import { DeleteConfirmationDialog } from "@/components/ui/deleteDialog";
|
||||||
|
import { CredentialForm } from "@/components/settings/InsuranceCredForm";
|
||||||
|
import { CredentialTable } from "@/components/settings/insuranceCredTable";
|
||||||
|
|
||||||
// Correctly infer Staff type from zod schema
|
// Correctly infer Staff type from zod schema
|
||||||
type Staff = z.infer<typeof StaffUncheckedCreateInputObjectSchema>;
|
type Staff = z.infer<typeof StaffUncheckedCreateInputObjectSchema>;
|
||||||
@@ -20,6 +22,7 @@ export default function SettingsPage() {
|
|||||||
|
|
||||||
// Modal and editing staff state
|
// Modal and editing staff state
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [credentialModalOpen, setCredentialModalOpen] = useState(false);
|
||||||
const [editingStaff, setEditingStaff] = useState<Staff | null>(null);
|
const [editingStaff, setEditingStaff] = useState<Staff | null>(null);
|
||||||
|
|
||||||
const toggleMobileMenu = () => setIsMobileMenuOpen((prev) => !prev);
|
const toggleMobileMenu = () => setIsMobileMenuOpen((prev) => !prev);
|
||||||
@@ -217,6 +220,68 @@ export default function SettingsPage() {
|
|||||||
`Viewing staff member:\n${staff.name} (${staff.email || "No email"})`
|
`Viewing staff member:\n${staff.name} (${staff.email || "No email"})`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// MANAGE USER
|
||||||
|
|
||||||
|
const [usernameUser, setUsernameUser] = useState("");
|
||||||
|
|
||||||
|
//fetch user
|
||||||
|
const {
|
||||||
|
data: currentUser,
|
||||||
|
isLoading: isUserLoading,
|
||||||
|
isError: isUserError,
|
||||||
|
error: userError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["/api/users/"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await apiRequest("GET", "/api/users/");
|
||||||
|
if (!res.ok) throw new Error("Failed to fetch user");
|
||||||
|
return res.json();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Populate fields after fetch
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentUser) {
|
||||||
|
setUsernameUser(currentUser.username);
|
||||||
|
}
|
||||||
|
}, [currentUser]);
|
||||||
|
|
||||||
|
//update user mutation
|
||||||
|
const updateUserMutate = useMutation({
|
||||||
|
mutationFn: async (
|
||||||
|
updates: Partial<{ username: string; password: string }>
|
||||||
|
) => {
|
||||||
|
if (!currentUser?.id) throw new Error("User not loaded");
|
||||||
|
const res = await apiRequest(
|
||||||
|
"PUT",
|
||||||
|
`/api/users/${currentUser.id}`,
|
||||||
|
updates
|
||||||
|
);
|
||||||
|
if (!res.ok) {
|
||||||
|
const errorData = await res.json().catch(() => null);
|
||||||
|
throw new Error(errorData?.error || "Failed to update user");
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["/api/users/"] });
|
||||||
|
toast({
|
||||||
|
title: "Updated",
|
||||||
|
description: "Your profile has been updated.",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (err: any) => {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: err?.message || "Failed to update user",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen overflow-hidden bg-gray-100">
|
<div className="flex h-screen overflow-hidden bg-gray-100">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
@@ -270,6 +335,95 @@ export default function SettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Card className="mt-6">
|
||||||
|
<CardContent className="space-y-4 py-6">
|
||||||
|
<h3 className="text-lg font-semibold">User Settings</h3>
|
||||||
|
|
||||||
|
{isUserLoading ? (
|
||||||
|
<p>Loading user...</p>
|
||||||
|
) : isUserError ? (
|
||||||
|
<p className="text-red-500">{(userError as Error)?.message}</p>
|
||||||
|
) : (
|
||||||
|
<form
|
||||||
|
className="space-y-4"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(e.currentTarget);
|
||||||
|
const password =
|
||||||
|
formData.get("password")?.toString().trim() || undefined;
|
||||||
|
|
||||||
|
updateUserMutate.mutate({
|
||||||
|
username: usernameUser?.trim() || undefined,
|
||||||
|
password: password || undefined,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium">
|
||||||
|
Username
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="username"
|
||||||
|
value={usernameUser}
|
||||||
|
onChange={(e) => setUsernameUser(e.target.value)}
|
||||||
|
className="mt-1 p-2 border rounded w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium">
|
||||||
|
New Password
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
name="password"
|
||||||
|
className="mt-1 p-2 border rounded w-full"
|
||||||
|
placeholder="••••••••"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
|
Leave blank to keep current password.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
|
||||||
|
disabled={updateUserMutate.isPending}
|
||||||
|
>
|
||||||
|
{updateUserMutate.isPending ? "Saving..." : "Save Changes"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Credential Section */}
|
||||||
|
<div className="mt-8">
|
||||||
|
<button
|
||||||
|
onClick={() => setCredentialModalOpen(true)}
|
||||||
|
className="mb-4 bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700"
|
||||||
|
>
|
||||||
|
Add Credential
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<h3 className="text-lg font-semibold mb-4">Saved Credentials</h3>
|
||||||
|
<CredentialTable />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{credentialModalOpen && currentUser?.id && (
|
||||||
|
<CredentialForm
|
||||||
|
userId={currentUser.id}
|
||||||
|
onClose={() => setCredentialModalOpen(false)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
username String @unique
|
username String @unique
|
||||||
password String
|
password String
|
||||||
patients Patient[]
|
patients Patient[]
|
||||||
appointments Appointment[]
|
appointments Appointment[]
|
||||||
claims Claim[]
|
claims Claim[]
|
||||||
|
insuranceCredentials InsuranceCredential[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Patient {
|
model Patient {
|
||||||
@@ -71,7 +72,6 @@ model Appointment {
|
|||||||
user User @relation(fields: [userId], references: [id])
|
user User @relation(fields: [userId], references: [id])
|
||||||
staff Staff? @relation(fields: [staffId], references: [id])
|
staff Staff? @relation(fields: [staffId], references: [id])
|
||||||
claims Claim[]
|
claims Claim[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Staff {
|
model Staff {
|
||||||
@@ -86,27 +86,27 @@ model Staff {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Claim {
|
model Claim {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
patientId Int
|
patientId Int
|
||||||
appointmentId Int
|
appointmentId Int
|
||||||
userId Int
|
userId Int
|
||||||
staffId Int
|
staffId Int
|
||||||
patientName String
|
patientName String
|
||||||
memberId String
|
memberId String
|
||||||
dateOfBirth DateTime @db.Date
|
dateOfBirth DateTime @db.Date
|
||||||
remarks String
|
remarks String
|
||||||
serviceDate DateTime
|
serviceDate DateTime
|
||||||
insuranceProvider String // e.g., "Delta MA"
|
insuranceProvider String // e.g., "Delta MA"
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
status String @default("pending") // "pending", "completed", "cancelled", "no-show"
|
status String @default("pending") // "pending", "completed", "cancelled", "no-show"
|
||||||
|
|
||||||
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
|
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
|
||||||
appointment Appointment @relation(fields: [appointmentId], references: [id], onDelete: Cascade)
|
appointment Appointment @relation(fields: [appointmentId], references: [id], onDelete: Cascade)
|
||||||
user User? @relation(fields: [userId], references: [id])
|
user User? @relation(fields: [userId], references: [id])
|
||||||
staff Staff? @relation("ClaimStaff", fields: [staffId], references: [id])
|
staff Staff? @relation("ClaimStaff", fields: [staffId], references: [id])
|
||||||
|
|
||||||
serviceLines ServiceLine[]
|
serviceLines ServiceLine[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model ServiceLine {
|
model ServiceLine {
|
||||||
@@ -120,3 +120,15 @@ model ServiceLine {
|
|||||||
billedAmount Float
|
billedAmount Float
|
||||||
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
|
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model InsuranceCredential {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
userId Int
|
||||||
|
siteKey String @unique // Unique key for site (e.g. "github", "slack")
|
||||||
|
username String
|
||||||
|
password String
|
||||||
|
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@index([userId])
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export * from '../shared/schemas/objects/PatientUncheckedCreateInput.schema';
|
|||||||
export * from '../shared/schemas/objects/UserUncheckedCreateInput.schema';
|
export * from '../shared/schemas/objects/UserUncheckedCreateInput.schema';
|
||||||
export * from '../shared/schemas/objects/StaffUncheckedCreateInput.schema'
|
export * from '../shared/schemas/objects/StaffUncheckedCreateInput.schema'
|
||||||
export * from '../shared/schemas/objects/ClaimUncheckedCreateInput.schema'
|
export * from '../shared/schemas/objects/ClaimUncheckedCreateInput.schema'
|
||||||
|
export * from '../shared/schemas/objects/InsuranceCredentialUncheckedCreateInput.schema'
|
||||||
Reference in New Issue
Block a user