Skip to content

Commit

Permalink
Add delete number
Browse files Browse the repository at this point in the history
  • Loading branch information
aleda145 committed Aug 3, 2022
1 parent 05d2cf0 commit 35104d2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/src/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ export default function Dashboard({ client, setIsLoggedIn }) {
},
}
);
const removeMutation = useMutation(
(numId) => {
console.log(numId.numId);
console.log(typeof numId.numId);
return client.Records.delete("user_nums", numId.numId);
},
{
onSuccess: () => {
queryClient.invalidateQueries("favNumbers");
console.log("succes");
},
onError: (error) => {
console.log(error);
error.customError = error.response.data.message;
},
}
);
async function logOutClicked() {
await client.AuthStore.clear();
setIsLoggedIn(false);
Expand All @@ -39,13 +56,16 @@ export default function Dashboard({ client, setIsLoggedIn }) {

if (error) return "An error has occurred: " + error.message;
let favorite_numbers = [];
let favorite_ids = [];
for (const item of data.items) {
favorite_numbers.push(item.num + " ");
favorite_ids.push(item.id);
}

return (
<div>
<div>My {client.AuthStore.model.email} favorite numbers</div>
<div>{favorite_ids}</div>
<div>{favorite_numbers}</div>

<button
Expand All @@ -62,6 +82,20 @@ export default function Dashboard({ client, setIsLoggedIn }) {
>
Lägg till nummer
</button>
<button
onClick={() => {
removeMutation.mutate(
{ numId: favorite_ids[0] },
{
onSuccess: () => {
console.log("button remove scucces");
},
}
);
}}
>
Delete number
</button>

<button onClick={logOutClicked}>Log out</button>
</div>
Expand Down

0 comments on commit 35104d2

Please sign in to comment.