diff --git a/frontend/src/app/profile/page.tsx b/frontend/src/app/profile/page.tsx index a3a48bba..50a319a4 100644 --- a/frontend/src/app/profile/page.tsx +++ b/frontend/src/app/profile/page.tsx @@ -10,13 +10,15 @@ import { validatePassword } from "@/lib/validatePassword"; import { Edit2, ExternalLink, Settings, X } from "lucide-react"; import { useRouter } from "next/navigation"; import React, { useState } from "react"; -import Image from "next/image"; +import Image from "next/image"; +import {useStudents} from "@/hooks/useStudents"; const AdminProfile: React.FC = () => { const { userId: therapistId } = useAuthContext(); const { therapist, error, refetch } = useTherapist(therapistId); const { updateTherapist } = useTherapists({ fetchOnMount: false }); const { updatePassword, deleteAccount } = useAuth(); + const { students, deleteStudent } = useStudents() const router = useRouter(); const [isModalOpen, setIsModalOpen] = useState(false); @@ -85,6 +87,10 @@ const AdminProfile: React.FC = () => { const handleFinalDelete = async () => { try { + students.forEach(student => { + deleteStudent(student.id) + }) + const userId = localStorage.getItem("userId"); if (!userId) { @@ -333,7 +339,7 @@ const AdminProfile: React.FC = () => { onClose={() => setOpenDeleteConfirm(false)} onConfirm={handleFinalDelete} title="Delete Account" - description="This action is permanent and cannot be undone." + description="Please note that deleting your account will also delete all your students. This action is permanent and cannot be undone. Are you sure you'd like to continue?" confirmText="Delete" cancelText="Cancel" variant="danger" diff --git a/frontend/src/app/therapistProfile/page.tsx b/frontend/src/app/therapistProfile/page.tsx deleted file mode 100644 index cd9cbf5d..00000000 --- a/frontend/src/app/therapistProfile/page.tsx +++ /dev/null @@ -1,160 +0,0 @@ -"use client"; - -import AppLayout from "@/components/AppLayout"; -import { Button } from "@/components/ui/button"; -import { ConfirmDialog } from "@/components/ui/confirm-dialog"; -import { - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import { useAuth } from "@/hooks/useAuth"; -import { validatePassword } from "@/lib/validatePassword"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; - -export default function TherapistProfile() { - const { updatePassword, deleteAccount } = useAuth(); - - const [openPassword, setOpenPassword] = useState(false); - const [currentPassword, setCurrentPassword] = useState(""); - const [newPassword, setNewPassword] = useState(""); - const [confirmPassword, setConfirmPassword] = useState(""); - const [passwordError, setPasswordError] = useState(""); - - const [openDeleteConfirm, setOpenDeleteConfirm] = useState(false); - - const router = useRouter(); - - const handlePasswordSave = () => { - setPasswordError(""); - - if (!currentPassword || !newPassword || !confirmPassword) { - setPasswordError("All fields are required"); - return; - } - if (newPassword !== confirmPassword) { - setPasswordError("New passwords do not match."); - return; - } - if (validatePassword(newPassword)) { - setPasswordError( - "Password must include at least one special character (!@#$%^&*()_+-=[]{};:'\",.<>?/~`|)" - ); - } - - try { - updatePassword({ password: newPassword }); - - setOpenPassword(false); - setCurrentPassword(""); - setNewPassword(""); - setConfirmPassword(""); - } catch { - setPasswordError("Failed to update password"); - } - }; - - const handleFinalDelete = async () => { - try { - const userId = localStorage.getItem("userId"); - - if (!userId) { - console.error("User ID Missing"); - return; - } - - await deleteAccount(userId); - - setOpenDeleteConfirm(false); - setOpenDeleteConfirm(false); - - router.push("/login"); - } catch { - const message = "Failed to delete account"; - console.error(message); - } - }; - - return ( - -
-

Therapist Profile

-
- -
- -
- - - - - Update Password - - -
-
- - setCurrentPassword(e.target.value)} - /> -
- -
- - setNewPassword(e.target.value)} - /> -
- -
- - setConfirmPassword(e.target.value)} - /> -
- - {passwordError && ( -

{passwordError}

- )} -
- - - - - -
-
- -
- -
- - setOpenDeleteConfirm(false)} - onConfirm={handleFinalDelete} - title="Delete Account" - description="This action is permanent and cannot be undone." - confirmText="Delete" - cancelText="Cancel" - variant="danger" - /> -
- ); -}