Skip to content

Commit cad008c

Browse files
committed
added post functionality to client
1 parent 0ea0720 commit cad008c

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

client/src/App.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,24 @@ export default function App() {
2424
},[])
2525

2626
function onAddTask(task){
27-
setData(apiData => [...apiData, task])
27+
28+
fetch(import.meta.env.VITE_SERVER_URL, {
29+
method: 'POST',
30+
headers: {
31+
'Content-Type': 'application/json',
32+
},
33+
body: JSON.stringify(task),
34+
})
35+
.then(res=>{
36+
if(!res.ok){
37+
throw new Error(res.statusText + ": " + res.status);
38+
}
39+
return res.json()
40+
})
41+
.then((data) => {
42+
setData(apiData => [...apiData, data])
43+
})
44+
.catch(error => console.log(error))
2845
}
2946

3047
if (loading) return <p>Loading...</p>;

client/src/components/Table.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import DeleteButton from './DeleteButton';
66

77
export default function Table({data}) {
88

9-
const [tasks, setTasks] = useState(data);
9+
const [_tasks, setTasks] = useState(data);
1010
const [selectedTask, setSelectedTask] = useState(null);
11-
11+
1212
const columns = useMemo(() => [
1313
{ header: '#', cell: info => info.row.index + 1},
1414
{ header: 'Estatus', accessorFn: row => row.status.percentage},
@@ -18,7 +18,7 @@ export default function Table({data}) {
1818
])
1919

2020
const table = useReactTable({
21-
data: tasks,
21+
data,
2222
columns,
2323
getCoreRowModel: getCoreRowModel(),
2424
})

client/src/components/modals/EditTaskForm.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function EditTaskForm({task, onSave, onClose}) {
2121
setLabel(e.target.value);
2222
}
2323

24-
function handleSubmit(e){
24+
function handleSubmit(e) {
2525
e.preventDefault();
2626
if([label, description, asignee].some(field => !field)) {
2727
console.log("Please enter all values")

client/src/components/modals/NewTaskForm.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ export default function NewTaskForm({setShowModal, onAddTask}) {
2424

2525
function handleSubmit(e){
2626
e.preventDefault();
27+
2728
console.log(percentage + " " + label + " " + description + " " + asignee)
2829
if([label, description, asignee].some(field => !field)) {
2930
console.log("Please enter all values")
3031
return;
3132
}
33+
3234
const task ={
3335
description: description,
3436
status: {
@@ -37,7 +39,7 @@ export default function NewTaskForm({setShowModal, onAddTask}) {
3739
},
3840
asignee: asignee
3941
};
40-
42+
4143
setShowModal(false);
4244
onAddTask(task);
4345
}

0 commit comments

Comments
 (0)