From 8f5dc52dc56cf37669e560bbde67dea102030c13 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:44:16 +0200 Subject: [PATCH 1/6] Product now fetches and passes to ui/product. --- frontend/components/Product.vue | 117 +------------------ frontend/components/ui/product.vue | 177 +++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 113 deletions(-) create mode 100644 frontend/components/ui/product.vue diff --git a/frontend/components/Product.vue b/frontend/components/Product.vue index e2c3a25..82d75ba 100644 --- a/frontend/components/Product.vue +++ b/frontend/components/Product.vue @@ -1,64 +1,15 @@ diff --git a/frontend/components/ui/product.vue b/frontend/components/ui/product.vue new file mode 100644 index 0000000..ca339bf --- /dev/null +++ b/frontend/components/ui/product.vue @@ -0,0 +1,177 @@ + + + + + From c09a29134d66ea5458629732229efdce7b096653 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:44:54 +0200 Subject: [PATCH 2/6] Uses prop "to" to send to edit from admin page. --- frontend/components/Admin.vue | 4 +++- frontend/components/ui/ProductCard.vue | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/components/Admin.vue b/frontend/components/Admin.vue index 3eb7217..28bccc5 100644 --- a/frontend/components/Admin.vue +++ b/frontend/components/Admin.vue @@ -7,7 +7,9 @@
- +
diff --git a/frontend/components/ui/ProductCard.vue b/frontend/components/ui/ProductCard.vue index cb062a0..fb93ba2 100644 --- a/frontend/components/ui/ProductCard.vue +++ b/frontend/components/ui/ProductCard.vue @@ -40,7 +40,11 @@ export default { product: { type: Object, required: true - } + }, + to: { + type: String, + required: false + } }, data() { return { @@ -64,7 +68,7 @@ export default { store.dispatch('cartModule/addItemToCart', { ...this.product }); }, viewProduct() { - this.$router.push('/shop/' + this.product.urlSlug) + this.$router.push(this.to ? this.to : '/shop/' + this.product.urlSlug) } } } From e7b5ac1fc8bdb56be6d50ec4554ab9dc3276c81e Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:46:16 +0200 Subject: [PATCH 3/6] Check if localhost before making fetch request. --- frontend/components/stripe.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/components/stripe.vue b/frontend/components/stripe.vue index 5652720..a6178c4 100644 --- a/frontend/components/stripe.vue +++ b/frontend/components/stripe.vue @@ -58,7 +58,11 @@ export default { }) }, makeIntent() { - fetch('/api/stripe/create-payment-intent', { + let url = '/api/stripe/create-payment-intent'; + if (window.location.href.includes('localhost')) + url = 'http://localhost:30010'.concat(url) + + fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' From 7cc00dbc49639a0d04ca1cc433136befa55c9f14 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:46:44 +0200 Subject: [PATCH 4/6] New edit product page that live edits a ui/product. --- frontend/components/editProduct.vue | 122 ++++++++++++++++++++++++++++ frontend/routes.js | 10 +++ 2 files changed, 132 insertions(+) create mode 100644 frontend/components/editProduct.vue diff --git a/frontend/components/editProduct.vue b/frontend/components/editProduct.vue new file mode 100644 index 0000000..15e7e1b --- /dev/null +++ b/frontend/components/editProduct.vue @@ -0,0 +1,122 @@ + + + + + diff --git a/frontend/routes.js b/frontend/routes.js index fc97ea8..6f94196 100644 --- a/frontend/routes.js +++ b/frontend/routes.js @@ -39,6 +39,16 @@ let routes = [ path: '/admin', component: (resolve) => require(['./components/Admin.vue'], resolve) }, + { + name: 'Add', + path: '/add', + component: (resolve) => require(['./components/editProduct.vue'], resolve) + }, + { + name: 'Edit', + path: '/edit/:slug', + component: (resolve) => require(['./components/editProduct.vue'], resolve) + } // { // name: 'styleguide', // path: '/styleguide', From ef8012151c80fe03a5e917e35f6645533ead7fa1 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:47:16 +0200 Subject: [PATCH 5/6] Updated global with pos-abs and h4 rules. --- frontend/styles/global.scss | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/styles/global.scss b/frontend/styles/global.scss index 99a5a97..2b2981e 100644 --- a/frontend/styles/global.scss +++ b/frontend/styles/global.scss @@ -41,6 +41,9 @@ h3 { font-size: calc(0.785 * var(--text-lg)); } } +h4 { + font-size: var(--text-md); +} .flex { display: flex; @@ -77,6 +80,12 @@ h3 { } +.pos-abs { + position: absolute; + z-index: 10; +} + + .col-wrap { padding-left: 120px; padding-right: 120px; @@ -117,6 +126,7 @@ h3 { @include mobile { padding-top: var(--space-xl); + padding-bottom: var(--space-xl); } } From 44f42be26f626aa110a1bb2f2c5c1e0b788b55e8 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 21 Jul 2020 18:49:56 +0200 Subject: [PATCH 6/6] Api endpoints for fetching shema for product and variation. --- server/app.js | 2 ++ server/controllers/product.js | 8 +++++++- server/controllers/variation.js | 11 +++++++++-- server/src/products.js | 10 +++++++++- server/src/utils.js | 8 +++++++- server/src/variation.js | 14 ++++++++++++-- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/server/app.js b/server/app.js index 29421b9..e572e39 100644 --- a/server/app.js +++ b/server/app.js @@ -21,9 +21,11 @@ app.use(express.json()); // app.use(express.urlencoded()); router.get('/products', productsController.allProducts) +router.get('/product/schema', productsController.getProductSchema) router.get('/product/:slug', productsController.productBySlug) router.post('/product', productsController.addNewProduct) +router.get('/variation/schema', variationsController.getVariationSchema) router.post('/variation/:id', variationsController.addNewVariationToProduct); router.post('/applepay/validateSession', applePayController.validateSession) diff --git a/server/controllers/product.js b/server/controllers/product.js index b2d8ca7..4993f61 100644 --- a/server/controllers/product.js +++ b/server/controllers/product.js @@ -46,8 +46,14 @@ const addNewProduct = (req, res) => { .then(resp => res.send(resp)) } +const getProductSchema = (req, res) => { + return products.productSchema() + .then(schema => res.json(schema)) +} + module.exports = { allProducts, productBySlug, - addNewProduct + addNewProduct, + getProductSchema }; diff --git a/server/controllers/variation.js b/server/controllers/variation.js index 66013bc..aac68a7 100644 --- a/server/controllers/variation.js +++ b/server/controllers/variation.js @@ -1,4 +1,4 @@ -const { saveNewVariation } = require('src/variation.js') +const { saveNewVariation, variationSchema } = require('src/variation.js') const Products = require('src/products'); const products = new Products(); @@ -35,6 +35,13 @@ const addNewVariationToProduct = async (req, res) => { .catch(err => handleError(err, res)) } + +const getVariationSchema = (req, res) => { + return variationSchema() + .then(schema => res.json(schema)) +} + module.exports = { - addNewVariationToProduct + addNewVariationToProduct, + getVariationSchema }; diff --git a/server/src/products.js b/server/src/products.js index 7d34c77..652f105 100644 --- a/server/src/products.js +++ b/server/src/products.js @@ -1,5 +1,6 @@ const Product = require('schemas/Product'); -const { slugify } = require('src/utils'); +const Variation = require('schemas/Variation'); +const { slugify, nulledSchema } = require('src/utils'); class Products { constructor() { @@ -29,6 +30,13 @@ class Products { return Product.find().populate('variations'); } + productSchema() { + const product = { ...Product.schema.obj }; + const productSchema = nulledSchema(product); + + return Promise.resolve(productSchema); + } + getBySlug(slug) { return Product.findOne({ urlSlug: slug }).populate('variations'); } diff --git a/server/src/utils.js b/server/src/utils.js index c26da73..b550a9a 100644 --- a/server/src/utils.js +++ b/server/src/utils.js @@ -14,6 +14,12 @@ const slugify = (string) => { .replace(/-+$/, '') // Trim - from end of text } +const nulledSchema = schema => Object.keys(schema).reduce((accumulator, current) => { + accumulator[current] = ""; + return accumulator; +}, {}); + module.exports = { - slugify + slugify, + nulledSchema } diff --git a/server/src/variation.js b/server/src/variation.js index c8e095d..b2206dd 100644 --- a/server/src/variation.js +++ b/server/src/variation.js @@ -1,4 +1,5 @@ const Variation = require('schemas/Variation'); +const { nulledSchema } = require('src/utils'); const updateVariation = () => { return @@ -17,6 +18,15 @@ const saveNewVariation = async (variation) => { return newVariation; } -module.exports = { - saveNewVariation +const variationSchema = () => { + const variation = { ...Variation.schema.obj }; + const variationSchema = nulledSchema(variation); + + return Promise.resolve(variationSchema); +} + + +module.exports = { + saveNewVariation, + variationSchema }