From f4f10d5eb690a33dd1c112358457a2b987297f26 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 5 Apr 2018 13:54:22 -0400 Subject: work --- backend/package.json | 3 +- backend/src/index.js | 1 - backend/src/resolvers/Mutation.js | 14 +++++++-- frontend/components/CartCount.js | 12 +++---- frontend/components/Header.js | 16 ++++++++-- frontend/components/Items.js | 17 ++-------- frontend/components/Nav.js | 18 +++++++---- frontend/components/PleaseSignIn.js | 21 +++++++++++++ frontend/components/Search.js | 62 +++++++++++++++++++++++++++---------- frontend/components/Signup.js | 9 ++++-- frontend/components/UpdateItem.js | 3 +- frontend/components/styles/Form.js | 13 ++++---- frontend/lib/withData.js | 1 - frontend/package-lock.json | 14 +++++++++ frontend/package.json | 3 +- frontend/pages/add.js | 6 ++-- frontend/pages/admin/update.js | 5 ++- frontend/pages/signup.js | 4 +-- 18 files changed, 152 insertions(+), 70 deletions(-) create mode 100644 frontend/components/PleaseSignIn.js diff --git a/backend/package.json b/backend/package.json index 4a1a0ae..1fdbc3a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -14,6 +14,7 @@ "jsonwebtoken": "8.1.1", "nodemailer": "^4.4.2", "prisma-binding": "1.5.7", + "react-debounce-input": "^3.2.0", "stripe": "^5.4.0" }, "devDependencies": { @@ -36,4 +37,4 @@ "env" ] } -} \ No newline at end of file +} diff --git a/backend/src/index.js b/backend/src/index.js index 4f98c52..8cf48fc 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -24,7 +24,6 @@ server.express.use(async (req, res, next) => { ` ); req.user = user; - console.log(req.user); next(); }); diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index 9127b04..daaa7de 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -46,13 +46,16 @@ const mutations = { // Creation of Post Mutations async createItem(parent, args, ctx, info) { - const userId = getUserId(ctx); + if (!ctx.request.userId) { + throw new Error('You must be logged in to create an item'); + } + const item = await ctx.db.mutation.createItem( { data: { user: { connect: { - id: userId, + id: ctx.request.userId, }, }, ...args, @@ -80,7 +83,14 @@ const mutations = { }, async updateItem(parent, args, ctx, info) { + const user = ctx.request.user; + const item = await ctx.db.query.item({ where: { id: args.id } }, `{ user { id } }`); + if (item.user.id !== user.id || !user.permissions.includes('ADMIN')) { + throw new Error('You are not allowed to update that item!'); + } + const updates = { ...args }; + // remove the ID because you can't update that delete updates.id; return ctx.db.mutation.updateItem({ where: { id: args.id }, diff --git a/frontend/components/CartCount.js b/frontend/components/CartCount.js index 5af472a..1cc4e47 100644 --- a/frontend/components/CartCount.js +++ b/frontend/components/CartCount.js @@ -5,7 +5,9 @@ const Dot = styled.div` background: ${props => props.theme.red}; color: white; border-radius: 50%; - padding: 5px; + padding: 0.5rem; + line-height: 2rem; + min-width: 3rem; margin-left: 1rem; font-weight: 100; font-feature-settings: 'tnum'; @@ -42,13 +44,7 @@ const AnimationStyles = styled.span` const CartCount = ({ count }) => ( - + {count} diff --git a/frontend/components/Header.js b/frontend/components/Header.js index 053a18b..4e631a0 100644 --- a/frontend/components/Header.js +++ b/frontend/components/Header.js @@ -20,6 +20,10 @@ const StyledHeader = styled.header` grid-template-columns: auto 1fr; justify-content: space-between; align-items: stretch; + @media (max-width: 1300px) { + grid-template-columns: 1fr; + justify-content: center; + } } .sub-bar { display: grid; @@ -31,14 +35,20 @@ const StyledHeader = styled.header` const Logo = styled.h1` font-size: 4rem; margin-left: 2rem; - transform: skew(-5deg); + position: relative; + z-index: 2; + transform: skew(-7deg); a { - padding: 1rem 1.5rem; + padding: 0.5rem 1rem; background: ${props => props.theme.red}; color: white; letter-spacing: -2px; text-transform: uppercase; } + @media (max-width: 1300px) { + margin: 0; + text-align: center; + } `; const Header = props => ( @@ -46,7 +56,7 @@ const Header = props => (
- Sick Fits! + Sick Fits!