Skip to content

Commit

Permalink
Update store
Browse files Browse the repository at this point in the history
  • Loading branch information
KenzoBenzo committed May 31, 2020
1 parent 7cb6d76 commit 35eac4f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.cache
.env
public
public/
yarn.lock
47 changes: 18 additions & 29 deletions functions/order-created.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
require("dotenv").config();
import sendgrid from "@sendgrid/mail";

const sgMail = require("@sendgrid/mail");
require("dotenv").config();

sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sendgrid.setApiKey(process.env.SENDGRID_API_KEY);

exports.handler = async ({ event, context, callback }) => {
exports.handler = async (event, context) => {
let body = JSON.parse(event.body);
console.log(body);

const msg = {
to: email,
from: process.env.SENDGRID_OWNER_EMAIL,
templateId: process.env.SENDGRID_ORDER_CREATED_ID,
dynamic_template_data: {
orderID: id,
name: name
}
};

try {
await sgMail.send(msg).then(() => {
console.log(
`Contact form sent from: ${process.env.SENDGRID_OWNER_EMAIL}, to: ${body.email}, with name: ${body.name}`
);
callback();
await sendgrid.send({
to: body.email,
from: process.env.SENDGRID_OWNER_EMAIL,
templateId: process.env.SENDGRID_ORDER_CREATED_ID,
dynamic_template_data: {
orderID: body.id,
name: body.name,
},
});

return {
statusCode: 200,
body: "Message sent"
};
} catch (error) {
return {
statusCode: error.code,
body: JSON.stringify(error)
};
return res.status(error.statusCode || 500).json({ error: error.message });
}

return {
statusCode: 200,
body: JSON.stringify({ error: "" }),
};
};
26 changes: 2 additions & 24 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const randomCartId = () =>
.substring(7);

const client = new GraphQLClient({
url: "/.netlify/functions/graphql"
url: "/.netlify/functions/graphql",
});

export const wrapPageElement = ({ element, props }) => {
Expand All @@ -25,29 +25,7 @@ export const wrapRootElement = ({ element }) => {
<ThemeProvider theme={customTheme}>
<StripeProvider>
<ClientContext.Provider value={client}>
<CartProvider
id={randomCartId()}
// onItemAdd={handleItemAdded}
// onItemUpdate={() =>
// useToast({
// position: "top-right",
// title: "Success!",
// description: "Item updated!",
// status: "success",
// duration: 5000,
// isClosable: true
// })
// }
// onItemRemove={() =>
// useToast({
// position: "top-right",
// title: "Success!",
// description: "Removed from cart.",
// status: "success",
// duration: 5000,
// isClosable: true
// })}
>
<CartProvider id={randomCartId()}>
<CSSReset />
{element}
</CartProvider>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prodserve": "gatsby build && gatsby serve"
},
"dependencies": {
"@chakra-ui/core": "0.6.1",
"@chakra-ui/core": "0.8.0",
"@emotion/core": "10.0.28",
"@emotion/styled": "10.0.27",
"@sendgrid/mail": "^6.5.4",
Expand Down
41 changes: 9 additions & 32 deletions src/gatsby/node/createResolvers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const md5 = require("md5");
const { createRemoteFileNode } = require("gatsby-source-filesystem");

const createResolvers = ({
actions: { createNode },
cache,
createNodeId,
createResolvers,
store,
reporter
reporter,
}) => {
const resolvers = {
GraphCMS_Product: {
Expand All @@ -16,50 +13,30 @@ const createResolvers = ({
resolve: ({ printfulProductId }, args, context, info) => {
return context.nodeModel.getNodeById({
id: printfulProductId,
type: `PrintfulProduct`
});
}
}
},
GraphCMS_Review: {
gravatar: {
type: `File`,
resolve: ({ email }, args, context, info) => {
const url = `https://gravatar.com/avatar/${md5(
email.trim().toLowerCase(),
{ encoding: "binary" }
)}`;

return createRemoteFileNode({
url,
store,
cache,
createNode,
createNodeId,
reporter
type: `PrintfulProduct`,
});
}
}
},
},
},
PrintfulVariant: {
formattedPrice: {
type: `String!`,
resolve: ({ retail_price }, args, context, info) => {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD"
currency: "USD",
}).format(retail_price / 100);
}
},
},
splitName: {
type: `String!`,
resolve: ({ name }, args, context, info) => {
const [, splitVariantName] = name.split(" - ");

return splitVariantName ? splitVariantName : name;
}
}
}
},
},
},
};

createResolvers(resolvers);
Expand Down
11 changes: 5 additions & 6 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import SEO from "../components/SEO";

function IndexPage({
data: {
cms: { products }
}
cms: { products },
},
}) {
return (
<>
<SEO
pageTitle='Home'
pageDescription='BeFreakingKind is an apparel company born out of the want to encourage people at the bare minimum, to be good people.'
pageTitle="Home"
pageDescription="BeFreakingKind is an apparel company born out of the want to encourage people at the bare minimum, to be good people."
/>
<Hero text='Just be fucking kind.' />
<Hero text={`Just be freaking kind.`} />
<ProductGrid products={products} />
</>
);
Expand All @@ -38,7 +38,6 @@ export const pageQuery = graphql`
}
variants {
formattedPrice
retail_price
}
}
}
Expand Down

0 comments on commit 35eac4f

Please sign in to comment.