diff options
author | 2024-08-25 04:04:59 +0100 | |
---|---|---|
committer | 2024-08-25 04:04:59 +0100 | |
commit | b9e1b913fe7683b795605ca80eafa2f089651c82 (patch) | |
tree | 142c8c529affde199ea4f47e56d217a7fb34c57f | |
parent | Add an item displayed in the store (diff) |
Add store front page
-rw-r--r-- | thallium-frontend/src/pages/StorePage.tsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/thallium-frontend/src/pages/StorePage.tsx b/thallium-frontend/src/pages/StorePage.tsx new file mode 100644 index 0000000..6899bd8 --- /dev/null +++ b/thallium-frontend/src/pages/StorePage.tsx @@ -0,0 +1,41 @@ +import { useSelector } from "react-redux"; +import { RootState } from "../store"; +import { useEffect, useState } from "react"; + +import { Template, getTemplates } from "../api/templates"; +import StoreItem from "../components/StoreItem"; +import styled from "styled-components"; + +const StoreGrid = styled.div` + display: grid; + grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); + gap: 2rem; + margin-left: 1rem; + margin-right: 1rem; +`; + +const StorePage = () => { + const voucherToken = useSelector((state: RootState) => state.authorization.voucherToken); + const [storeItems, setStoreItems] = useState<Template[] | null>(null); + + useEffect(() => { + getTemplates(true).then(setStoreItems).catch((err: unknown) => { + setStoreItems([]); + console.error(err); + }); + }, [voucherToken]); + + return ( + <> + <h1>Giveaway Store</h1> + <StoreGrid> + {storeItems?.map((item) => ( + <StoreItem key={item.template_id} template={item} /> + ))} + </StoreGrid> + + </> + ); +}; + +export default StorePage; |