1
1
import { useQuery } from "@tanstack/react-query" ;
2
2
import { useState } from "react" ;
3
+ import toast from "react-hot-toast" ;
4
+ import Swal from "sweetalert2" ;
3
5
import useAxiosCommon from "../../Hooks/useAxiosCommon" ;
6
+ import useAxiosSecqur from "../../Hooks/useAxiosSecqur" ;
4
7
import LogingSpiner from "../../Sheare/LogingSpiner" ;
5
8
import AddUpcoming from "./AddUpcoming" ;
6
9
7
10
const Upcommingmeal = ( ) => {
8
11
let [ isOpen , setIsOpen ] = useState ( false ) ;
9
12
const axioscommon = useAxiosCommon ( ) ;
10
- const { data : upcommingmeals = [ ] , isLoading } = useQuery ( {
13
+ const axiosSec = useAxiosSecqur ( ) ;
14
+ const {
15
+ data : upcommingmeals = [ ] ,
16
+ isLoading,
17
+ refetch,
18
+ } = useQuery ( {
11
19
queryKey : [ "upcommingmeals" ] ,
12
20
queryFn : async ( ) => {
13
21
const { data } = await axioscommon . get ( "/upcommingmeals" ) ;
@@ -16,7 +24,36 @@ const Upcommingmeal = () => {
16
24
} ) ;
17
25
18
26
const handelPublic = ( upcom ) => {
19
- console . log ( upcom ) ;
27
+ const items = {
28
+ title : upcom ?. title ,
29
+ catagory : upcom ?. catagory ,
30
+ price : parseFloat ( upcom ?. price ) ,
31
+ rating : parseFloat ( upcom ?. rating ) ,
32
+ likes : parseFloat ( upcom ?. likes ) ,
33
+ ingredients : upcom ?. ingredients ,
34
+ description : upcom ?. description ,
35
+ admin_name : upcom ?. admin_name ,
36
+ email : upcom ?. email ,
37
+ } ;
38
+
39
+ Swal . fire ( {
40
+ title : "Are you sure?" ,
41
+ text : "you punlish thid item" ,
42
+ icon : "warning" ,
43
+ showCancelButton : true ,
44
+ confirmButtonColor : "#3085d6" ,
45
+ cancelButtonColor : "#d33" ,
46
+ confirmButtonText : "Yes, delete it!" ,
47
+ } ) . then ( async ( result ) => {
48
+ if ( result . isConfirmed ) {
49
+ const res = await axiosSec . delete ( `/upcommingmeals/${ upcom ?. _id } ` ) ;
50
+ const posts = await axiosSec . post ( "/addmeals" , items ) ;
51
+ if ( posts . data . insertedId ) {
52
+ toast . success ( "publish successfully !" ) ;
53
+ }
54
+ }
55
+ refetch ( ) ;
56
+ } ) ;
20
57
} ;
21
58
22
59
if ( isLoading ) return < LogingSpiner > </ LogingSpiner > ;
0 commit comments