Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
Full-Stack
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
1
Merge Requests
1
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
Нұрасыл Қайратұлы
Full-Stack
Commits
dd591871
Commit
dd591871
authored
Jul 16, 2024
by
Nurasyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил компоненты для продуктов
parent
4fafab66
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
15 deletions
+110
-15
ProductItem.tsx
Frontend/src/containers/Products/ProductItem.tsx
+31
-0
Products.tsx
Frontend/src/containers/Products/Products.tsx
+30
-10
productsSlice.ts
Frontend/src/features/productsSlice.ts
+33
-2
axiosApiClient.ts
Frontend/src/helpers/axiosApiClient.ts
+3
-3
IProduct.ts
Frontend/src/interfaces/IProduct.ts
+6
-0
index.ts
Frontend/src/store/index.ts
+7
-0
No files found.
Frontend/src/containers/Products/ProductItem.tsx
0 → 100644
View file @
dd591871
import
{
Link
}
from
'react-router-dom'
;
import
{
Grid
,
Card
,
CardHeader
,
CardContent
,
CardActions
,
IconButton
,
Typography
}
from
'@mui/material'
;
import
{
ArrowForward
}
from
'@mui/icons-material'
;
import
{
IProduct
}
from
'@/interfaces/IProduct'
;
interface
Props
{
product
:
IProduct
;
}
export
function
ProductItem
({
product
}:
Props
)
{
const
{
title
,
price
,
id
,
description
}
=
product
;
return
(
<
Grid
item
xs=
{
12
}
sm=
{
12
}
md=
{
6
}
lg=
{
4
}
>
<
Card
sx=
{
{
minWidth
:
275
}
}
>
<
CardHeader
title=
{
title
}
/>
<
CardContent
>
<
Typography
variant=
"body2"
>
{
description
}
</
Typography
>
<
strong
style=
{
{
marginLeft
:
'10px'
}
}
>
Price:
{
price
}
KZT
</
strong
>
</
CardContent
>
<
CardActions
>
<
IconButton
component=
{
Link
}
to=
{
`/products/${id}`
}
>
<
ArrowForward
/>
</
IconButton
>
</
CardActions
>
</
Card
>
</
Grid
>
);
}
Frontend/src/containers/Products/Products.tsx
View file @
dd591871
import
{
Link
}
from
'react-router-dom'
;
import
{
Typography
,
Grid
,
Button
}
from
'@mui/material'
;
import
{
useAppDispatch
,
useAppSelector
}
from
'../../store'
;
import
{
shallowEqual
}
from
'react-redux'
;
import
{
useEffect
}
from
'react'
;
import
{
fetchProducts
}
from
'../../features/productsSlice'
;
import
{
ProductItem
}
from
'./ProductItem'
;
export
function
Products
()
{
const
dispatch
=
useAppDispatch
();
const
{
products
}
=
useAppSelector
((
state
)
=>
state
.
products
,
shallowEqual
);
useEffect
(()
=>
{
dispatch
(
fetchProducts
());
},
[
dispatch
]);
return
(
<
Grid
container
direction=
"column"
spacing=
{
2
}
>
<
Grid
item
container
direction=
"row"
justifyContent=
"space-between"
alignItems=
"center"
>
<
Grid
item
>
<
Typography
variant=
"h4"
>
Products
</
Typography
>
</
Grid
>
<>
<
Grid
container
direction=
"column"
spacing=
{
2
}
>
<
Grid
item
container
direction=
"row"
justifyContent=
"space-between"
alignItems=
"center"
>
<
Grid
item
>
<
Typography
variant=
"h4"
>
Products
</
Typography
>
</
Grid
>
<
Grid
item
>
<
Button
color=
"primary"
component=
{
Link
}
to=
{
'/products/new'
}
>
Add product
</
Button
>
<
Grid
item
>
<
Button
color=
"primary"
component=
{
Link
}
to=
{
'/products/new'
}
>
Add product
</
Button
>
</
Grid
>
</
Grid
>
</
Grid
>
</
Grid
>
<
Grid
item
container
direction=
"row"
spacing=
{
1
}
>
{
products
.
map
((
product
)
=>
(
<
ProductItem
key=
{
product
.
id
}
product=
{
product
}
/>
))
}
</
Grid
>
</>
);
}
Frontend/src/features/productsSlice.ts
View file @
dd591871
import
{
createSlice
}
from
'@reduxjs/toolkit'
;
import
{
axiosApiClient
}
from
"../helpers/axiosApiClient"
;
import
{
IProduct
}
from
"../interfaces/IProduct"
;
import
{
createAsyncThunk
,
createSlice
}
from
"@reduxjs/toolkit"
;
const
initialState
=
{};
interface
State
{
products
:
IProduct
[];
error
:
Error
|
null
;
loading
:
boolean
;
}
const
initialState
:
State
=
{
products
:
[],
error
:
null
,
loading
:
false
,
};
export
const
fetchProducts
=
createAsyncThunk
(
'fetch/products'
,
async
()
=>
{
return
await
axiosApiClient
.
get
<
IProduct
[]
>
(
'/products'
).
then
((
res
)
=>
res
.
data
);
});
const
productsSlice
=
createSlice
({
name
:
'products'
,
initialState
,
reducers
:
{},
extraReducers
:
(
builder
)
=>
{
builder
.
addCase
(
fetchProducts
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
products
=
action
.
payload
;
state
.
loading
=
false
;
})
.
addCase
(
fetchProducts
.
rejected
,
(
state
,
action
)
=>
{
state
.
error
=
action
.
error
as
Error
;
state
.
loading
=
false
;
})
.
addCase
(
fetchProducts
.
pending
,
(
state
)
=>
{
state
.
loading
=
true
;
});
},
});
export
default
productsSlice
.
reducer
;
Frontend/src/helpers/axiosApiClient.ts
View file @
dd591871
import
axios
from
"axios"
;
import
axios
from
'axios'
;
export
const
axiosApiClient
=
axios
.
create
({
baseURL
:
"http://localhost:8000"
});
\ No newline at end of file
baseURL
:
'http://localhost:8000'
,
});
Frontend/src/interfaces/IProduct.ts
0 → 100644
View file @
dd591871
export
interface
IProduct
{
id
:
string
;
title
:
string
;
description
:
string
;
price
:
number
;
}
Frontend/src/store/index.ts
View file @
dd591871
import
{
configureStore
}
from
'@reduxjs/toolkit'
;
import
productsReducer
from
'../features/productsSlice.ts'
;
import
{
TypedUseSelectorHook
,
useDispatch
,
useSelector
}
from
'react-redux'
;
const
store
=
configureStore
({
reducer
:
{
...
...
@@ -7,4 +8,10 @@ const store = configureStore({
},
});
type
RootState
=
ReturnType
<
typeof
store
.
getState
>
;
type
AppDispatch
=
typeof
store
.
dispatch
;
export
const
useAppDispatch
:
()
=>
AppDispatch
=
useDispatch
;
export
const
useAppSelector
:
TypedUseSelectorHook
<
RootState
>
=
useSelector
;
export
default
store
;
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