Skip to content

Commit 01ebee6

Browse files
committed
feat: add categories page
1 parent d26b68c commit 01ebee6

File tree

15 files changed

+324
-101
lines changed

15 files changed

+324
-101
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"toastify",
2727
"Tooman",
2828
"usehooks",
29+
"webp",
2930
"Woocommerce",
3031
"Yekan",
3132
"چنده"

next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const nextConfig = {
1818
},
1919
{
2020
protocol: 'https',
21-
hostname: 'api.nextwoo.ir',
21+
hostname: 'nextwoo.ir',
2222
},
2323
{
2424
protocol: 'https',
1.67 KB
Loading

src/app/[locale]/(main)/(container)/cart/hooks/useCheckoutItems.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ const useCheckoutItems = ({ content }: { content: CartContentFragment }) => {
107107
/>
108108
),
109109
},
110-
{
110+
];
111+
112+
if (totalProfit > 0) {
113+
items.push({
111114
key: (
112115
<Typography color="error" variant="body2" sx={{ fontWeight: 600 }}>
113116
{t('pages.cart.box.yourProfit')}
@@ -122,8 +125,8 @@ const useCheckoutItems = ({ content }: { content: CartContentFragment }) => {
122125
}}
123126
/>
124127
),
125-
},
126-
];
128+
});
129+
}
127130

128131
return items;
129132
};

src/app/[locale]/(main)/(homepage)/components/MainCategories.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Image from '@/components/common/Image';
44
import { useAppContext } from '@/hooks/useAppContext';
55
import { ChevronLeft } from '@mui/icons-material';
6-
import { Box, Grid, Link, Stack } from '@mui/material';
6+
import { Box, Grid, Link, Stack, Typography } from '@mui/material';
77
import { grey } from '@mui/material/colors';
88
import { FC } from 'react';
99

@@ -24,12 +24,12 @@ const MainCategories: FC<MainCategoriesProps> = ({ items }) => {
2424
params.set('categoryId', item.id.toString());
2525

2626
return (
27-
<Grid key={item.id} item xs={6} md={3}>
27+
<Grid key={item.id} item xs={4} md={4} lg={2}>
2828
<Link href={`/search?${params.toString()}`}>
2929
<Stack spacing={1} alignItems="end">
3030
<Box
3131
width="100%"
32-
height={isMobile ? 150 : 210}
32+
height={isMobile ? 100 : 210}
3333
sx={{
3434
bgcolor: grey[100],
3535
borderRadius: 2,
@@ -50,14 +50,16 @@ const MainCategories: FC<MainCategoriesProps> = ({ items }) => {
5050
</Box>
5151

5252
<Stack direction="row" spacing={1}>
53-
{item.title}
54-
<ChevronLeft
55-
fontSize="small"
56-
sx={{
57-
transform: (theme) =>
58-
theme.direction === 'ltr' ? 'rotate(180deg)' : null,
59-
}}
60-
/>
53+
<Typography variant="body2">{item.title}</Typography>
54+
{!isMobile && (
55+
<ChevronLeft
56+
fontSize="small"
57+
sx={{
58+
transform: (theme) =>
59+
theme.direction === 'ltr' ? 'rotate(180deg)' : null,
60+
}}
61+
/>
62+
)}
6163
</Stack>
6264
</Stack>
6365
</Link>

src/app/[locale]/(main)/(homepage)/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import SlidersSkeleton from './components/SlidersSkeleton';
2424
const getCategories = async () => {
2525
const { data } = await getClient().query<GetMainCategoriesQuery>({
2626
query: GET_MAIN_CATEGORIES,
27+
variables: {
28+
first: 6,
29+
},
2730
});
2831

2932
const items =
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Stack, Typography } from '@mui/material';
2+
import { FC } from 'react';
3+
4+
export interface MenuCategoryItemProps {
5+
name: string | null;
6+
selected: boolean;
7+
onClick: VoidFunction;
8+
}
9+
const MenuCategoryItem: FC<MenuCategoryItemProps> = ({
10+
name,
11+
selected,
12+
onClick,
13+
}) => {
14+
return (
15+
<Stack
16+
onClick={onClick}
17+
alignItems="center"
18+
justifyContent="center"
19+
sx={{
20+
height: 65,
21+
backgroundColor: (theme) =>
22+
selected ? theme.palette.background.default : theme.palette.grey[200],
23+
}}
24+
>
25+
<Typography variant="body2">{name}</Typography>
26+
</Stack>
27+
);
28+
};
29+
30+
export default MenuCategoryItem;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Link } from '@/navigation';
2+
import { ChevronRight } from '@mui/icons-material';
3+
import { Stack, Typography } from '@mui/material';
4+
import { FC } from 'react';
5+
import SubCategoryItem from './SubCategoryItem';
6+
7+
export interface SubCategoriesProps {
8+
parentId: string | null;
9+
name: string;
10+
items: any[];
11+
}
12+
13+
const SubCategories: FC<SubCategoriesProps> = ({ name, parentId, items }) => {
14+
if (!parentId) {
15+
return null;
16+
}
17+
18+
return (
19+
<Stack px={1.5} flexGrow={1}>
20+
<Stack component={Link} href="#" height={65} justifyContent="center">
21+
<Typography
22+
variant="body2"
23+
color="primary"
24+
sx={{
25+
display: 'flex',
26+
alignItems: 'center',
27+
}}
28+
>
29+
مشاهده همه کالاهای {name}{' '}
30+
<ChevronRight
31+
fontSize="small"
32+
sx={{
33+
transform: (theme) =>
34+
theme.direction === 'rtl' ? 'rotate(180deg)' : null,
35+
}}
36+
/>
37+
</Typography>
38+
</Stack>
39+
<Stack direction="row" px={1.5} flexWrap="wrap" gap={1}>
40+
{items.map((item) => {
41+
return (
42+
<SubCategoryItem
43+
src={item.image.sourceUrl}
44+
name={item.name}
45+
id={item.name}
46+
/>
47+
);
48+
})}
49+
50+
<SubCategoryItem
51+
src={'/assets/images/all-product.webp'}
52+
name={'همه کالاها'}
53+
id={parentId}
54+
/>
55+
</Stack>
56+
</Stack>
57+
);
58+
};
59+
60+
export default SubCategories;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Image from '@/components/common/Image';
2+
import { Link } from '@/navigation';
3+
import { Stack, Typography } from '@mui/material';
4+
import { FC } from 'react';
5+
6+
export interface SubCategoryItemProps {
7+
id: string;
8+
name: string;
9+
src: string;
10+
}
11+
const SubCategoryItem: FC<SubCategoryItemProps> = ({ id, src, name }) => {
12+
return (
13+
<Stack
14+
spacing={1}
15+
width="30%"
16+
alignItems="center"
17+
component={Link}
18+
href="#"
19+
sx={{
20+
height: 'fit-content',
21+
maxHeight: 'auto',
22+
}}
23+
>
24+
<Stack
25+
alignItems="center"
26+
justifyContent="center"
27+
sx={{
28+
bgcolor: (theme) => theme.palette.grey[200],
29+
borderRadius: 1.5,
30+
height: 'fit-content',
31+
}}
32+
>
33+
<Image width={82} height={82} src={src} alt={name} />
34+
</Stack>
35+
<Typography
36+
color="text.primary"
37+
variant="body2"
38+
sx={{
39+
// whiteSpace: 'nowrap',
40+
textOverflow: 'ellipsis',
41+
overflow: 'hidden',
42+
display: '-webkit-box',
43+
'-webkit-line-clamp': '2',
44+
'-webkit-box-orient': 'vertical',
45+
}}
46+
>
47+
{name}
48+
</Typography>
49+
</Stack>
50+
);
51+
};
52+
53+
export default SubCategoryItem;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Skeleton, Stack } from '@mui/material';
2+
import React from 'react';
3+
4+
const Loading = () => {
5+
return (
6+
<Stack direction="row" alignItems="flex-start">
7+
<Stack overflow="auto">
8+
{new Array(4).fill(1).map((_item, index) => {
9+
return (
10+
<Skeleton
11+
key={index.toString()}
12+
variant="rectangular"
13+
width={115}
14+
height={65}
15+
sx={{
16+
borderRadius: 0,
17+
borderBottom: '1px solid ',
18+
borderColor: (theme) => theme.palette.divider,
19+
}}
20+
/>
21+
);
22+
})}
23+
</Stack>
24+
<Stack
25+
px={1.5}
26+
gap={1}
27+
flexWrap="wrap"
28+
justifyContent="center"
29+
direction="row"
30+
flexGrow={1}
31+
>
32+
{new Array(6).fill(1).map((_item, index) => {
33+
return (
34+
<Stack spacing={0.5} width="30%" key={index.toString()}>
35+
<Skeleton variant="rectangular" height={100} />
36+
<Skeleton variant="text" width="100%" />
37+
</Stack>
38+
);
39+
})}
40+
</Stack>
41+
</Stack>
42+
);
43+
};
44+
45+
export default Loading;

0 commit comments

Comments
 (0)