Skip to content

Commit

Permalink
Add store front page
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 25, 2024
1 parent d385e73 commit b9e1b91
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions thallium-frontend/src/pages/StorePage.tsx
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b9e1b91

Please sign in to comment.