/* eslint-disable no-underscore-dangle */ import React, { useState, useEffect } from 'react'; import { Heading, Grid, GridItem, Box, } from '@chakra-ui/react'; import { BiSearchAlt2 } from 'react-icons/bi'; import store from '../../redux/store'; import Card from './components/Card'; import { Home as i18n } from '../../global/i18n'; import Loading from '../../global/components/Loading'; import InlineLabelInput from '../../global/components/FormControl/InlineLabelInput'; export default () => { const [hasLoaded, setLoaded] = useState(false); const [products, setProducts] = useState([]); useEffect(() => { if (hasLoaded) return () => {}; const _ = async (setProductsPt, setLoadedPt) => { const resp = await fetch('/api/v1/products'); const data = await resp.json(); if (resp.ok) { setProductsPt(data); setLoadedPt(true); } else { store.dispatch({ type: 'SET_ALERT', data: { header: i18n.downloadFailedAlert.header, content: JSON.stringify(data.error) } }); } }; _(setProducts, setLoaded); return () => {}; }, [hasLoaded, setLoaded, setProducts]); if (!hasLoaded) { return (); } return (
OpenCommerce Store {}} propKeyPressEvt={() => {}} propSubmitEvt={() => {}} type="text" labelBgColor="green.400" labelFgColor="white" labelIcon={()} labelText="Search.." error={null} />
{products.map((x) => ( ))}
); };