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/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/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/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' 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) } } } 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 @@ + + + + + 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', 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); } } 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 }