-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteProvider.tsx
48 lines (45 loc) · 1.24 KB
/
DeleteProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Logout wrapper
*/
import { useThemeStore } from "components/themes/PureBaldrTheme/themeStore";
import { fetchApi, getCookie } from "helpers/P7RestControler";
import { useRouter } from "next/router";
interface Props {
id: any;
reFetch: any;
}
const DeleteProvider: React.FC<Props> = ({ children, id, reFetch }) => {
const setAttr = useThemeStore((state: any) => state.setAttr);
return (
<div
onClick={() => {
fetchApi(
`${process.env.NEXT_PUBLIC_API_URL}/api/notifications/${id}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${getCookie("jwt")}`,
},
},
(res: any) => {
if (res.error) {
console.log("error", res);
} else {
reFetch[1]({
loading: false,
data: reFetch[0].data.filter(function (obj: any) {
return obj.id !== id;
}),
});
setAttr({path:'theme.message.text',value:'Element was deleted.'})
setAttr({path:'theme.message.status',value:'success'})
}
}
);
}}
>
{children}
</div>
);
};
export default DeleteProvider