AddonCard.js
3 weeks ago
CardsGrid.js
3 months ago
Categories.js
4 months ago
Filters.js
3 months ago
modules-api.js
1 year ago
CardsGrid.js
221 lines
| 1 | import { |
| 2 | Box, |
| 3 | Divider, |
| 4 | HStack, |
| 5 | Heading, |
| 6 | SimpleGrid, |
| 7 | Text, |
| 8 | } from '@chakra-ui/react'; |
| 9 | import AddonCard from './AddonCard'; |
| 10 | |
| 11 | const CardsGrid = ({ modules, selectedCategory, showToast, onModuleToggle }) => { |
| 12 | const getModulesByCategory = () => { |
| 13 | const modulesByCategory = new Map(); |
| 14 | |
| 15 | modules.forEach((module) => { |
| 16 | const category = module.category || 'Others'; |
| 17 | if (!modulesByCategory.has(category)) { |
| 18 | modulesByCategory.set(category, []); |
| 19 | } |
| 20 | modulesByCategory.get(category).push(module); |
| 21 | }); |
| 22 | |
| 23 | const categoryOrder = [ |
| 24 | 'Form Elements', |
| 25 | 'Payment Gateways', |
| 26 | 'Email Marketing', |
| 27 | 'CRM Integrations', |
| 28 | 'Marketing & Analytics', |
| 29 | 'Integrations', |
| 30 | 'E-Commerce', |
| 31 | 'Page Builders', |
| 32 | 'Security', |
| 33 | 'Cloud & Storage', |
| 34 | ]; |
| 35 | |
| 36 | const sortedCategories = []; |
| 37 | |
| 38 | categoryOrder.forEach((categoryName) => { |
| 39 | if (modulesByCategory.has(categoryName)) { |
| 40 | sortedCategories.push([ |
| 41 | categoryName, |
| 42 | modulesByCategory.get(categoryName), |
| 43 | ]); |
| 44 | } |
| 45 | }); |
| 46 | |
| 47 | modulesByCategory.forEach((categoryModules, category) => { |
| 48 | if (!categoryOrder.includes(category)) { |
| 49 | sortedCategories.push([category, categoryModules]); |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | return sortedCategories.map(([category, categoryModules]) => ({ |
| 54 | category, |
| 55 | displayName: category, |
| 56 | modules: categoryModules, |
| 57 | })); |
| 58 | }; |
| 59 | |
| 60 | if (selectedCategory === 'All') { |
| 61 | const categoriesData = getModulesByCategory(); |
| 62 | |
| 63 | return ( |
| 64 | <Box> |
| 65 | {categoriesData.map( |
| 66 | ({ category, displayName, modules: categoryModules }) => ( |
| 67 | <Box |
| 68 | key={category} |
| 69 | mb={{ base: '4', sm: '5', md: '6' }} |
| 70 | bg="white" |
| 71 | p={{ base: '4', sm: '5', md: '6', lg: '8' }} |
| 72 | borderRadius="13px" |
| 73 | borderWidth="1px" |
| 74 | borderStyle="solid" |
| 75 | borderColor="#e1e1e1" |
| 76 | > |
| 77 | <HStack |
| 78 | justify="space-between" |
| 79 | mb={{ base: '3', sm: '4' }} |
| 80 | flexWrap="wrap" |
| 81 | gap="2" |
| 82 | > |
| 83 | <Heading |
| 84 | size={{ base: 'sm', sm: 'md' }} |
| 85 | color="gray.800" |
| 86 | fontWeight="600" |
| 87 | fontSize={{ base: '16px', sm: '18px', md: '20px' }} |
| 88 | > |
| 89 | {displayName} |
| 90 | </Heading> |
| 91 | <Text |
| 92 | fontSize={{ base: '12px', sm: '13px', md: '14px' }} |
| 93 | color="gray.500" |
| 94 | fontWeight="500" |
| 95 | flexShrink={0} |
| 96 | > |
| 97 | {categoryModules.length}{' '} |
| 98 | {categoryModules.length === 1 ? 'Item' : 'Items'} |
| 99 | </Text> |
| 100 | </HStack> |
| 101 | <Divider |
| 102 | mb={{ base: '5', sm: '6', md: '7' }} |
| 103 | borderColor="#e1e1e1" |
| 104 | opacity="1" |
| 105 | pb="4px" |
| 106 | /> |
| 107 | |
| 108 | <SimpleGrid |
| 109 | gridTemplateColumns="repeat(auto-fill, minmax(320px, 1fr))" |
| 110 | // columns={{ base: 1, md: 2, lg: 3 }} |
| 111 | spacing={{ base: '4', sm: '5', md: '6' }} |
| 112 | > |
| 113 | {categoryModules.map((addon) => ( |
| 114 | <AddonCard |
| 115 | key={addon.slug} |
| 116 | addon={addon} |
| 117 | showToast={showToast} |
| 118 | onModuleToggle={onModuleToggle} |
| 119 | /> |
| 120 | ))} |
| 121 | </SimpleGrid> |
| 122 | </Box> |
| 123 | ), |
| 124 | )} |
| 125 | </Box> |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | const categoryName = |
| 130 | selectedCategory !== 'All' |
| 131 | ? selectedCategory |
| 132 | : modules.length > 0 |
| 133 | ? modules[0].category || 'Others' |
| 134 | : 'Others'; |
| 135 | |
| 136 | return ( |
| 137 | <Box> |
| 138 | <Box |
| 139 | mb={{ base: '4', sm: '5', md: '6' }} |
| 140 | bg="white" |
| 141 | p={{ base: '4', sm: '5', md: '6', lg: '8' }} |
| 142 | borderRadius="13px" |
| 143 | borderWidth="1px" |
| 144 | borderStyle="solid" |
| 145 | borderColor="#e1e1e1" |
| 146 | > |
| 147 | <HStack |
| 148 | justify="space-between" |
| 149 | mb={{ base: '3', sm: '4' }} |
| 150 | flexWrap="wrap" |
| 151 | gap="2" |
| 152 | > |
| 153 | <Heading |
| 154 | size={{ base: 'sm', sm: 'md' }} |
| 155 | color="gray.800" |
| 156 | fontWeight="600" |
| 157 | fontSize={{ base: '16px', sm: '18px', md: '20px' }} |
| 158 | > |
| 159 | {categoryName} |
| 160 | </Heading> |
| 161 | <Text |
| 162 | fontSize={{ base: '12px', sm: '13px', md: '14px' }} |
| 163 | color="gray.500" |
| 164 | fontWeight="500" |
| 165 | flexShrink={0} |
| 166 | > |
| 167 | {modules.length} {modules.length === 1 ? 'Item' : 'Items'} |
| 168 | </Text> |
| 169 | </HStack> |
| 170 | <Divider mb={{ base: '5', sm: '6', md: '7' }} borderColor="#e1e1e1" opacity="1" pb="4px" /> |
| 171 | |
| 172 | {modules.length > 0 ? ( |
| 173 | <SimpleGrid |
| 174 | // columns={{ base: 1, md: 2, lg: 3 }} |
| 175 | // spacing={{ base: '4', sm: '5', md: '6' }} |
| 176 | |
| 177 | gridTemplateColumns="repeat(auto-fill, minmax(320px, 1fr))" |
| 178 | spacing={{ base: '4', sm: '5', md: '6' }} |
| 179 | > |
| 180 | {modules.map((addon) => ( |
| 181 | <AddonCard |
| 182 | key={addon.slug} |
| 183 | addon={addon} |
| 184 | showToast={showToast} |
| 185 | onModuleToggle={onModuleToggle} |
| 186 | /> |
| 187 | ))} |
| 188 | </SimpleGrid> |
| 189 | ) : ( |
| 190 | <Box |
| 191 | display="flex" |
| 192 | justifyContent="center" |
| 193 | flexDirection="column" |
| 194 | padding={{ base: '30px 16px', sm: '40px 20px', md: '60px' }} |
| 195 | gap={{ base: '2', sm: '3' }} |
| 196 | alignItems="center" |
| 197 | textAlign="center" |
| 198 | > |
| 199 | <Text |
| 200 | fontSize={{ base: '14px', sm: '15px', md: '16px' }} |
| 201 | fontWeight="500" |
| 202 | color="gray.600" |
| 203 | > |
| 204 | No modules found |
| 205 | </Text> |
| 206 | <Text |
| 207 | fontSize={{ base: '13px', sm: '14px' }} |
| 208 | color="gray.500" |
| 209 | px={{ base: '2', sm: '4' }} |
| 210 | > |
| 211 | No addons are available in the {categoryName} category. |
| 212 | </Text> |
| 213 | </Box> |
| 214 | )} |
| 215 | </Box> |
| 216 | </Box> |
| 217 | ); |
| 218 | }; |
| 219 | |
| 220 | export default CardsGrid; |
| 221 |