From bc8290475efe3e84b906b0c9a4b2937251b610e7 Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Fri, 31 May 2024 23:59:16 +0530 Subject: [PATCH] Minor fixes --- app/(pages)/(auth)/login/page.tsx | 3 ++- app/(pages)/(auth)/signup/page.tsx | 3 ++- app/api/auth/verifyotp/route.ts | 4 +++- app/api/patient/appointment/route.ts | 6 ------ app/components/otp/index.tsx | 8 +++++++- lib/emails/templates.tsx | 6 ++++-- lib/logs/index.tsx | 5 +++-- lib/verifyOtp.ts | 2 ++ 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/(pages)/(auth)/login/page.tsx b/app/(pages)/(auth)/login/page.tsx index 012d1985..f8b607c4 100644 --- a/app/(pages)/(auth)/login/page.tsx +++ b/app/(pages)/(auth)/login/page.tsx @@ -26,7 +26,7 @@ export default function Login() { const [isVisible, setIsVisible] = useState(false); const [Error, setError] = useState(null || String); const [showOtp, setShowOtp] = useState(false); - const [userData, setUserData] = useState({ email: "", role: "" }); + const [userData, setUserData] = useState({ email: "", role: "", action: "" }); const emailRef = useRef(null); const passwordRef = useRef(null); @@ -99,6 +99,7 @@ export default function Login() { setUserData({ email: userEmail.toString(), role: userRole?.toString() || "", + action: "Login", }); toast.success("OTP successfully sent !", { diff --git a/app/(pages)/(auth)/signup/page.tsx b/app/(pages)/(auth)/signup/page.tsx index 53b7fd45..60d833e1 100644 --- a/app/(pages)/(auth)/signup/page.tsx +++ b/app/(pages)/(auth)/signup/page.tsx @@ -32,7 +32,7 @@ export default function Signup() { const [confirmPasswordError, setConfirmPasswordError] = useState(""); const [isVisible, setIsVisible] = useState(false); const [showOtp, setShowOtp] = useState(false); - const [userData, setUserData] = useState({ email: "", role: "" }); + const [userData, setUserData] = useState({ email: "", role: "", action: "" }); const firstNameRef = useRef(null); const lastNameRef = useRef(null); @@ -183,6 +183,7 @@ export default function Signup() { setUserData({ email: userEmail.toString(), role: userRole?.toString() || "", + action: "Signup", }); toast.success( diff --git a/app/api/auth/verifyotp/route.ts b/app/api/auth/verifyotp/route.ts index b3535a14..24e45ca4 100644 --- a/app/api/auth/verifyotp/route.ts +++ b/app/api/auth/verifyotp/route.ts @@ -6,6 +6,7 @@ type bodyType = { email: string; otp: string; role: string; + action: string; }; const allowedRoles = ["patient", "hospital", "doctor", "receptionist"]; @@ -14,7 +15,7 @@ export async function POST(req: Request) { try { const body: bodyType = await req.json(); - if (!body || !body.email || !body.role || !body.otp) { + if (!body || !body.email || !body.role || !body.action || !body.otp) { return Response.json({ error: "Email, OTP, and role are required fields in the request body.", }); @@ -60,6 +61,7 @@ async function checkOTP(body: bodyType, req: Request) { name: `${user.firstname} ${user.lastname}`, email, role: body.role, + action: body.action, }; // storing user logs in db diff --git a/app/api/patient/appointment/route.ts b/app/api/patient/appointment/route.ts index 44d4ffc4..873fe6f3 100644 --- a/app/api/patient/appointment/route.ts +++ b/app/api/patient/appointment/route.ts @@ -32,12 +32,6 @@ export async function GET(request: Request) { const appointments = await appointmentsCursor.toArray(); // convert cursor to array - if (appointments.length === 0) { - return new Response(JSON.stringify({ error: "Appointments not found" }), { - status: 404, - }); - } - const projection = { _id: 1, firstname: 1, diff --git a/app/components/otp/index.tsx b/app/components/otp/index.tsx index 7a06aad2..683044b2 100644 --- a/app/components/otp/index.tsx +++ b/app/components/otp/index.tsx @@ -18,6 +18,7 @@ type userDataType = { userData: { email: string; role: string; + action: string; }; }; @@ -54,7 +55,12 @@ export default function OtpSection({ userData }: userDataType) { }; const handleSubmit = async () => { - const data = await verifyOtp(userData.email, userData.role, otp); + const data = await verifyOtp( + userData.email, + userData.role, + userData.action, + otp + ); if (data.error) { setShowError(data.error); diff --git a/lib/emails/templates.tsx b/lib/emails/templates.tsx index b795ae70..05fe349c 100644 --- a/lib/emails/templates.tsx +++ b/lib/emails/templates.tsx @@ -317,7 +317,7 @@ export function UserActivityTemplate(user: UserLog) { color: "#1f1f1f", }} > - User Login Notification + User {user.action} Notification

- A user has logged into the Patient Fitness Tracker application. + {user.action === "Login" + ? "A user has logged into the Patient Fitness Tracker application." + : "A user just created an account for Patient Fitness Tracker application."} Here are the details: