Skip to content

Commit 582839d

Browse files
committed
added check if userState is defined directly to component
1 parent c7fbe88 commit 582839d

1 file changed

Lines changed: 2 additions & 18 deletions

File tree

client/src/components/Record.jsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect } from "react";
22
import { useParams, useNavigate } from "react-router-dom";
33
import { toast } from 'react-toastify';
4-
import { useDispatch, useSelector } from 'react-redux';
4+
import { useSelector } from 'react-redux';
55
import { motion } from 'framer-motion';
66
import { BaseUrl } from './BaseUrl';
77

@@ -24,25 +24,9 @@ const item = {
2424
};
2525

2626
export default function Record() {
27-
const [loggedIn, setLoggedIn] = useState(false);
2827
const userState = useSelector((state) => state.userState);
2928
const companyId = userState.user ? userState.user.companyId : null;
3029

31-
// Check if user is logged in
32-
useEffect(() => {
33-
const checkLoginStatus = async () => {
34-
console.error("Entire userState:", userState); // Log the entire state
35-
if (userState.user) {
36-
console.error("userState.user exists:", userState.user);
37-
setLoggedIn(true);
38-
} else {
39-
console.error("userState.user is null or undefined");
40-
setLoggedIn(false);
41-
}
42-
};
43-
checkLoginStatus();
44-
}, [userState]);
45-
4630
// State to hold the form data
4731
const [form, setForm] = useState({
4832
employeeName: "",
@@ -201,7 +185,7 @@ export default function Record() {
201185
<div className="mt-2">
202186
<div className="flex rounded-md shadow-sm ring-1 ring-inset ring-slate-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-400 sm:max-w-md">
203187
<input
204-
readOnly={loggedIn}
188+
readOnly={!!userState.user}
205189
type="number"
206190
name="companyId"
207191
id="companyId"

0 commit comments

Comments
 (0)