- {restaurant.name[0].toUpperCase() + restaurant.name.slice(1)}
+ {restaurant.name[0].toUpperCase() +
+ restaurant.name.slice(1)}
|
{restaurant.email} |
diff --git a/app/sait-staff/overviewDash/index.js b/app/sait-staff/overviewDash/index.js
index ea4750d..3e92112 100644
--- a/app/sait-staff/overviewDash/index.js
+++ b/app/sait-staff/overviewDash/index.js
@@ -21,13 +21,11 @@ export default function Dash() {
async function fetchData() {
const data = await getSaitData();
- console.log(data);
setAdmin(data);
}
async function fetchDataByUser() {
const data = await getSaitDataByUser(user);
setUserData(data);
- console.log(data);
}
useEffect(() => {
@@ -35,7 +33,6 @@ export default function Dash() {
fetchData();
fetchDataByUser(user);
}
- console.log(user);
}, [user]);
useEffect(() => {
@@ -44,14 +41,12 @@ export default function Dash() {
}, [admin]);
const handleEditRequest = (user) => {
- console.log(user);
setEditEmployeData(user);
setIsEditing(true);
};
const handleDelete = (id) => {
// Handle delete logic
- console.log(`Delete user with id: ${id}`);
setAdmin(admin.filter((user) => user.id !== id));
};
diff --git a/app/sait-staff/overviewDash/table.js b/app/sait-staff/overviewDash/table.js
index 71c387f..306c8b9 100644
--- a/app/sait-staff/overviewDash/table.js
+++ b/app/sait-staff/overviewDash/table.js
@@ -2,6 +2,8 @@ import React, { useState } from "react";
import { LuPencil, LuTrash } from "react-icons/lu";
import { IoMdPersonAdd } from "react-icons/io";
import Modal from "@/Components/Modal";
+import { FaFilter } from "react-icons/fa";
+import { MdOutlineDoneOutline } from "react-icons/md";
const Table = ({
admin,
@@ -9,22 +11,96 @@ const Table = ({
setIsAdding,
handleChangeStatus,
}) => {
+ const [search, setSearch] = useState(false);
+ const [searchTerm, setSearchTerm] = useState("");
+ const [searchBy, setSearchBy] = useState("name");
const [isVisible, setIsVisisble] = useState(false);
const [isActive, setIsActive] = useState(null);
const [email, setEmail] = useState("");
const [docId, setDocId] = useState("");
+ const filteredEmployees =
+ admin && admin.length > 0
+ ? admin.filter(user => {
+ if (searchBy === "name") {
+ return user.name.toLowerCase().includes(searchTerm.toLowerCase());
+ } else if (searchBy === "email") {
+ return user.email.toLowerCase().includes(searchTerm.toLowerCase());
+ } else if (searchBy === "phone") {
+ return user.phoneNumber.includes(searchTerm);
+ }
+ return true;
+ })
+ : [];
+
return (
-
+
+
+
+
+
+
+ setSearchTerm(e.target.value)}
+ />
+
+
+
+
+
@@ -32,6 +108,9 @@ const Table = ({
User
|
+
+ Email
+ |
Role
|
@@ -47,77 +126,78 @@ const Table = ({
- {admin && admin.length > 0 ? (
- admin.map((user) => (
-
-
-
-
-
-
-
-
- |
-
-
- {user.role}
-
- |
-
+ {filteredEmployees.length > 0 ? (filteredEmployees.map((user) => (
+ |
+
+
+
+
+
+
- {user.accountCreated.toDate().toDateString()}
+ {user.name}
- |
-
- {
- setIsVisisble(true);
- setIsActive(user.active),
- setEmail(user.email),
- setDocId(user.id);
- }}
- className={`relative inline-block px-3 py-1 font-semibold leading-tight rounded ${
- user.active ? "bg-green-400" : "bg-red-400"
- }`}
- >
-
-
- {user.active ? "Active" : "InActive"}
-
-
- |
-
-
- |
-
- ))
- ) : (
-
+
+
+
+
+
+ {user.email}
+
+ |
+
+
+ {user.role}
+
+ |
+
+
+ {user.accountCreated.toDate().toDateString()}
+
+ |
+
+ {
+ setIsVisisble(true);
+ setIsActive(user.active),
+ setEmail(user.email),
+ setDocId(user.id);
+ }}
+ className={`relative inline-block px-3 py-1 font-semibold leading-tight rounded ${
+ user.active ? "bg-green-400" : "bg-red-400"
+ }`}
+ >
+
+
+ {user.active ? "Active" : "InActive"}
+
+
+ |
+
+
+ |
+
+ ))):(<>
No data available
|
-
- )}
+ >)}
diff --git a/app/sait-staff/settingS/index.js b/app/sait-staff/settingS/index.js
index f83cf1d..7b76139 100644
--- a/app/sait-staff/settingS/index.js
+++ b/app/sait-staff/settingS/index.js
@@ -1,20 +1,58 @@
/**
* v0 by Vercel.
*/
+"use client";
import { Button } from "@/components/ui/button"
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card"
import Passwordreset from "./passwordreset/page"
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"
import { Input } from "@/components/ui/input"
+import { getSaitDataByUser } from "@/services/GetRequest/getRequest"
+import { useUserAuth } from "@/services/utils"
+import { useEffect, useState } from "react";
+import { getAuth } from "firebase/auth";
+import { deleteSaitUser } from "@/services/PostRequest/postRequest";
+import { useRouter } from "next/navigation";
export default function Settings() {
+ const route = useRouter();
+ const [userEmail, setUserEmail] = useState("");
+ const { user } = useUserAuth();
+ const auth = getAuth();
+ const [saitData, setSaitData] = useState(null);
+ async function getUserData(){
+ const data = await getSaitDataByUser(user);
+ setSaitData(data);
+ }
+ useEffect(() => {
+ if(user){
+ getUserData();
+ console.log(auth.currentUser)
+ }
+ if(user==false){
+ route.push("/");
+ }
+ },[user]);
+
+ const handleDeleteAccount = async (e) => {
+ e.preventDefault();
+ if(userEmail !== saitData[0].email){
+ alert("Email does not match");
+ return;
+ }
+ if(userEmail == saitData[0].email){
+ await deleteSaitUser(auth.currentUser,saitData[0].id).then(()=>{
+ alert("Account deleted successfully");
+ })};
+
+ };
return (
-
-
+ {saitData ? (
+
@@ -26,10 +64,10 @@ export default function Settings() {
@@ -38,7 +76,12 @@ export default function Settings() {
+ ):(
+
+ )}
+
)
diff --git a/app/sait-staff/settingS/passwordreset/page.js b/app/sait-staff/settingS/passwordreset/page.js
index 8328efa..d4b92dc 100644
--- a/app/sait-staff/settingS/passwordreset/page.js
+++ b/app/sait-staff/settingS/passwordreset/page.js
@@ -11,11 +11,49 @@ import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
+import { updatePassword, EmailAuthProvider, reauthenticateWithCredential } from "firebase/auth";
-export default function Passwordreset() {
+export default function Passwordreset({auth,email}) {
+ const user = auth.currentUser;
+ const [oldPassword, setOldPassword] = useState("");
+ const [newPassword, setNewPassword] = useState("");
+ const [confirmPassword, setConfirmPassword] = useState("");
+ const credential = EmailAuthProvider.credential(email,oldPassword);
+ const [showOldPassword, setShowOldPassword] = useState(false)
const [showSection, setShowSection] = useState(true)
const [showPassword, setShowPassword] = useState(false)
const [showPasswordConfirm, setShowPasswordConfirm] = useState(false)
+ const [passwordError, setPasswordError] = useState('')
+
+ const handlePasswordChange = () =>{
+ if(oldPassword === ""|| newPassword === "" || confirmPassword === ""){
+ alert("Please fill all fields");
+ return;
+ }
+ if (newPassword !== confirmPassword){
+ alert("Passwords do not match");
+ return;
+ }
+ if(oldPassword === newPassword){
+ alert("New password cannot be the same as old password");
+ return;
+ }
+ if(!newPassword.match(
+ /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
+ )){
+ alert("Password must contain at least 8 characters, one uppercase, one lowercase, one number and one special character");
+ return;
+ }
+ reauthenticateWithCredential(user, credential).then(()=>{
+ updatePassword(user,newPassword).then(()=>{
+ alert("Password updated successfully");
+ }).catch((error)=>{
+ alert("Error updating password: ",error);
+ })
+ }).catch((error)=>{
+ alert("Error reauthenticating user: ",error);
+ })
+ }
return (
// Changes to be made here
@@ -23,7 +61,7 @@ export default function Passwordreset() {
Change Your Password
-
+
@@ -33,13 +71,28 @@ export default function Passwordreset() {
{showSection && (
-
+
)}
+
+
+
+ {setOldPassword(e.target.value)})} type={showOldPassword ? "text" : "password"} required />
+
+
+
-
+ {setNewPassword(e.target.value)})} type={showPassword ? "text" : "password"} required />
|