1
1
import { createContext , useReducer , useContext , useEffect } from 'react' ;
2
2
import { ActionType } from './actions' ;
3
3
import reducer from './reducer' ;
4
- import { customFetch } from '../util/authFetch' ;
4
+ import { customFetch } from '../util/customFetch' ;
5
+ import { ItemDetails } from '../util/types' ;
5
6
6
7
const authFetch = customFetch ( 3000 ) ;
7
8
// const itemFetch = customFetch(3001);
8
- // const inventoryFetch = customFetch(3002);
9
+ const inventoryFetch = customFetch ( 3002 ) ;
9
10
// const orderFetch = customFetch(3003);
10
11
11
12
interface Item {
@@ -35,6 +36,9 @@ interface AppContextInterface extends StateInterface {
35
36
stopLoading : ( ) => void ;
36
37
loginUser : ( username : string , password : string , isLogin : boolean ) => void ;
37
38
logoutUser : ( ) => void ;
39
+ getItemsForSale : ( ) => void ;
40
+ getItemInventory : ( ) => ItemDetails ;
41
+ getMyStoreItems : ( ) => void ;
38
42
}
39
43
40
44
const AppContext = createContext < AppContextInterface > ( {
@@ -43,6 +47,9 @@ const AppContext = createContext<AppContextInterface>({
43
47
stopLoading : ( ) => null ,
44
48
loginUser : ( ) => null ,
45
49
logoutUser : ( ) => null ,
50
+ getItemsForSale : ( ) => null ,
51
+ getItemInventory : ( ) => null ,
52
+ getMyStoreItems : ( ) => null ,
46
53
} ) ;
47
54
48
55
type Props = {
@@ -83,7 +90,7 @@ const AppContextProvider = ({ children }: Props) => {
83
90
const logoutUser = async ( ) => {
84
91
startLoading ( ) ;
85
92
try {
86
- const response = await authFetch . post ( 'http://localhost:3000/api /auth/logout' ) ;
93
+ const response = await authFetch . post ( '/auth/logout' ) ;
87
94
console . log ( response ) ;
88
95
dispatch ( { type : ActionType . LOGOUT_USER } ) ;
89
96
} catch ( err ) {
@@ -106,6 +113,31 @@ const AppContextProvider = ({ children }: Props) => {
106
113
stopLoading ( ) ;
107
114
} ;
108
115
116
+ // TODO
117
+ const getItemsForSale = ( ) => {
118
+ console . log ( 'getItemsForSale' ) ;
119
+ } ;
120
+
121
+ // TODO
122
+ const getItemInventory = async ( itemId : string ) => {
123
+ console . log ( 'getItemInventory' ) ;
124
+ startLoading ( ) ;
125
+ try {
126
+ const response = await inventoryFetch ( `/inventory/getItemInventory/${ itemId } ` ) ;
127
+ stopLoading ( ) ;
128
+ return response . data ;
129
+ } catch ( err ) {
130
+ stopLoading ( ) ;
131
+ console . log ( err ) ;
132
+ return null ;
133
+ }
134
+ } ;
135
+
136
+ // TODO
137
+ const getMyStoreItems = ( ) => {
138
+ console . log ( 'getMyStoreItems' ) ;
139
+ } ;
140
+
109
141
return (
110
142
< AppContext . Provider
111
143
value = { {
@@ -114,6 +146,9 @@ const AppContextProvider = ({ children }: Props) => {
114
146
stopLoading,
115
147
loginUser,
116
148
logoutUser,
149
+ getItemsForSale,
150
+ getItemInventory,
151
+ getMyStoreItems,
117
152
} }
118
153
>
119
154
{ children } { /* <App /> */ }
0 commit comments