Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
classwork-55
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нұрасыл Қайратұлы
classwork-55
Commits
69aa60aa
Commit
69aa60aa
authored
May 21, 2024
by
Nurasyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update async redux
parent
d4ec6f02
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
BurgerBuilder.tsx
src/containers/BurgerBuilder/BurgerBuilder.tsx
+6
-1
orders.slice.ts
src/store/orders.slice.ts
+28
-0
No files found.
src/containers/BurgerBuilder/BurgerBuilder.tsx
View file @
69aa60aa
import
React
,
{
useState
}
from
'react'
;
import
React
,
{
use
Effect
,
use
State
}
from
'react'
;
import
{
useNavigate
}
from
'react-router-dom'
;
import
{
useNavigate
}
from
'react-router-dom'
;
import
type
{
Ingredients
,
IngredientNames
}
from
'@/interfaces/Ingredients'
;
import
type
{
Ingredients
,
IngredientNames
}
from
'@/interfaces/Ingredients'
;
import
Burger
from
'@/components/Burger/Burger'
;
import
Burger
from
'@/components/Burger/Burger'
;
...
@@ -9,6 +9,7 @@ import { OrderSummary } from '@/components/Burger/OrderSummary';
...
@@ -9,6 +9,7 @@ import { OrderSummary } from '@/components/Burger/OrderSummary';
import
{
useAppSelector
}
from
'@/store'
;
import
{
useAppSelector
}
from
'@/store'
;
import
{
useAppDispatch
}
from
'@/store'
;
import
{
useAppDispatch
}
from
'@/store'
;
import
{
setIngredients
}
from
'@/store/ingredients.slice'
;
import
{
setIngredients
}
from
'@/store/ingredients.slice'
;
import
{
getOrder
}
from
'@/store/orders.slice'
;
const
BurgerBuilder
=
()
=>
{
const
BurgerBuilder
=
()
=>
{
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
...
@@ -52,6 +53,10 @@ const BurgerBuilder = () => {
...
@@ -52,6 +53,10 @@ const BurgerBuilder = () => {
navigate
({
pathname
:
"/checkout"
})
navigate
({
pathname
:
"/checkout"
})
};
};
useEffect
(()
=>
{
dispatch
(
getOrder
())
},
[])
return
(
return
(
<>
<>
<
Modal
show=
{
show
}
onClosed=
{
onClosedHandler
}
>
<
Modal
show=
{
show
}
onClosed=
{
onClosedHandler
}
>
...
...
src/store/orders.slice.ts
View file @
69aa60aa
...
@@ -22,6 +22,18 @@ export const postOrder = createAsyncThunk(
...
@@ -22,6 +22,18 @@ export const postOrder = createAsyncThunk(
}
}
)
)
export
const
getOrder
=
createAsyncThunk
(
"orders/getOrder"
,
async
()
=>
{
try
{
const
data
=
await
axiosBurger
.
get
(
"orders.json"
)
return
data
}
catch
(
error
:
any
)
{
throw
new
Error
(
error
)
}
}
)
export
const
ordersSlice
=
createSlice
({
export
const
ordersSlice
=
createSlice
({
name
:
"orders"
,
name
:
"orders"
,
initialState
,
initialState
,
...
@@ -50,5 +62,21 @@ export const ordersSlice = createSlice({
...
@@ -50,5 +62,21 @@ export const ordersSlice = createSlice({
state
.
contactData
=
contactData
state
.
contactData
=
contactData
state
.
price
=
price
state
.
price
=
price
})
})
.
addCase
(
getOrder
.
pending
,
(
state
)
=>
{
state
.
isLoading
=
true
console
.
log
(
"PENDING"
);
})
.
addCase
(
getOrder
.
rejected
,
(
state
,
action
)
=>
{
state
.
isLoading
=
false
state
.
error
=
action
.
error
as
Error
console
.
log
(
"REJECT"
);
})
.
addCase
(
getOrder
.
fulfilled
,
(
state
,
action
)
=>
{
console
.
log
(
action
.
payload
,
"FULFILLED"
);
state
.
isLoading
=
false
})
}
}
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment