Skip to content

Commit 9d8b1c3

Browse files
added styling
1 parent 45c43c6 commit 9d8b1c3

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

src/components/product/SingleProduct.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { useAppDispatch, useAppSelector } from '../../store/store';
88
import { fetchSingleProduct } from '../../store/features/product/singleProductSlice';
99
import { PuffLoader } from 'react-spinners';
1010
import { IProductInitialResponse } from '../../utils/types/store';
11+
import { Meta } from '../Meta';
12+
import { Link } from 'react-router-dom';
1113

1214
const ProductComponent = ({ productId }: { productId: string }) => {
1315
const dispatch = useAppDispatch();
@@ -19,13 +21,15 @@ const ProductComponent = ({ productId }: { productId: string }) => {
1921

2022
return (
2123
<>
24+
<Meta title={`Product details - ${productId}`} />
2225
{isLoading ? (
2326
<div className="loader">
2427
<PuffLoader color="#ff6d18" size={300} loading={isLoading} />
2528
</div>
2629
) : isError ? (
2730
<div className="error-message">
2831
<p>{message || "Something went wrong. Please try again later."}</p>
32+
<Link to="/" className="btn-link">View all products</Link>
2933
</div>
3034
) : (
3135
product ?
@@ -40,7 +44,10 @@ const ProductComponent = ({ productId }: { productId: string }) => {
4044

4145
</div>
4246
:
43-
<div>No Product</div>
47+
<div className='error-message'>
48+
<p>Product was not found</p>
49+
<Link to="/" className="btn-link">View all products</Link>
50+
</div>
4451
)
4552
}
4653
</>

src/store/features/product/singleProductSlice.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ const singleProductSlice = createSlice({
3232
state.isError = null;
3333
state.isSuccess = false;
3434
})
35-
.addCase(fetchSingleProduct.fulfilled, (state, action: PayloadAction<IProductResponse>) => {
35+
.addCase(fetchSingleProduct.fulfilled, (state, action: PayloadAction<any>) => {
3636
state.isLoading = false;
3737
state.isSuccess = true;
38-
state.product = action.payload.data?.product || null;
38+
state.product = action.payload.product || null;
3939
})
4040
.addCase(fetchSingleProduct.rejected, (state, action: PayloadAction<any>) => {
4141
state.isLoading = false;

src/styles/ProductComponent.scss

+57-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
.product-component {
44
padding: 2rem;
5-
*{
5+
6+
* {
67
font-size: 16px;
78
}
89

@@ -328,28 +329,76 @@
328329

329330
}
330331

332+
.loader {
333+
display: flex;
334+
justify-content: center;
335+
align-items: center;
336+
height: 60vh;
337+
width: 100%;
338+
}
339+
340+
.error-message {
341+
display: flex;
342+
flex-direction: column;
343+
gap: 10px;
344+
justify-content: center;
345+
align-items: center;
346+
width: 100%;
347+
height: 60vh;
348+
349+
p {
350+
font-size: 20px;
351+
color: $red-color;
352+
}
353+
354+
.btn-link {
355+
border: none;
356+
background-color: $primary-color;
357+
padding: 1rem 4rem;
358+
text-decoration: none;
359+
color: $white-color;
360+
font-family: $text-family;
361+
font-weight: 700;
362+
font-size: 1.2rem;
363+
border-radius: 2rem;
364+
cursor: pointer;
365+
}
366+
367+
.btn-link:hover {
368+
background-color: $white-color;
369+
color: $primary-color;
370+
border: 1px solid $border-color;
371+
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
372+
transition: all 0.3s ease-in-out;
373+
}
374+
}
375+
331376
@media (max-width: 600px) {
332377
.product-component {
333-
*{
378+
* {
334379
font-size: 12px;
335380
}
381+
336382
.product-container {
337383
flex-direction: column;
338384
padding-bottom: 20px;
339-
.images-container{
385+
386+
.images-container {
340387
max-height: 300px;
341388
min-height: 300px;
342389
overflow: hidden;
343-
.main-image-container{
344-
.main-image{
390+
391+
.main-image-container {
392+
.main-image {
345393
height: 100%;
346394
}
347395
}
348396
}
349397
}
350-
.card-container{
351-
.card-header{
352-
.card-header-title{
398+
399+
.card-container {
400+
.card-header {
401+
.card-header-title {
353402
font-size: 5px;
354403
}
355404
}

0 commit comments

Comments
 (0)