Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions frontend/react-app/src/components/LockUnlockTask.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { lockTask, unlockTask } from '../api/adminApi';
import { Lock, LockOpen } from 'lucide-react';
import "../css/MyTasks.css";

function LockUnlockTask({ initialIsLocked, taskId }) {
function LockUnlockTask({ initialIsLocked, taskId, updateLinkById }) {
const [isLocked, setIsLocked] = useState(initialIsLocked);

const handleLockUnlock = async () => {
Expand All @@ -12,13 +12,15 @@ function LockUnlockTask({ initialIsLocked, taskId }) {
const unlock = await unlockTask(taskId);
if (unlock) {
setIsLocked(false);
window.location.reload();
updateLinkById(taskId, false)
//window.location.reload();
}
} else {
const lock = await lockTask(taskId);
if (lock) {
updateLinkById(taskId, true)
setIsLocked(true);
window.location.reload();
//window.location.reload();
}
}
} catch (error) {
Expand Down
13 changes: 11 additions & 2 deletions frontend/react-app/src/pages/MyTasks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ function MyTasks(){
const [tasksToDo, setTasksToDo ] = useState([]);
const [loading, setLoading] = useState(true);

const updateLinkById = (id, isLocked)=>{
setTasksToDo(tasksToDo.map((task)=>{
if(task.taskId === id){
task.isLocked = isLocked;
}
return task
}))
}

async function fetchData(){
try{
const results = await getAssignedTasks(userId);
Expand All @@ -75,7 +84,7 @@ useEffect(()=>{
console.log("Tasks To Do:", tasksToDo);


},[]);
},[tasksToDo]);



Expand Down Expand Up @@ -122,7 +131,7 @@ const headerAndAccessors = [
Cell: (original) => {
const isLocked = original.value;
return isAdmin ? (
<LockUnlockTask initialIsLocked={isLocked} taskId={original.row.original.id} />
<LockUnlockTask initialIsLocked={isLocked} taskId={original.row.original.id} updateLinkById={updateLinkById} />
) : (
isLocked ? '🔒' : '🔓'
);
Expand Down
13 changes: 10 additions & 3 deletions frontend/react-app/src/pages/TeamTasks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,20 @@ function TeamTasks(){
setallUsersLoading(false)
}
}

const updateLinkById = (id, isLocked)=>{
setTasksToDo(tasksToDo.map((task)=>{
if(task.taskId === id){
task.isLocked = isLocked;
}
return task
}))
}
useEffect(()=>{
fetchData();
console.log("Tasks To Do:", tasksToDo);


},[]);
},[tasksToDo]);

const isAdmin = cookies.userInfo.role ==='admin';
const headerAndAccessors = [
Expand All @@ -147,7 +154,7 @@ function TeamTasks(){
Cell: (original) => {
const isLocked = original.value;
return isAdmin ? (
<LockUnlockTask initialIsLocked={isLocked} taskId={original.row.original.id} />
<LockUnlockTask initialIsLocked={isLocked} taskId={original.row.original.id} updateLinkById={updateLinkById} />
) : (
isLocked ? '🔒' : '🔓'
);
Expand Down