Allow from address to be configurable
parent
ba2d2a6cea
commit
f932fb6e4c
@ -0,0 +1,20 @@
|
|||||||
|
const router = module.exports = require('express-promise-router')()
|
||||||
|
const parseJSON = require('body-parser').json()
|
||||||
|
const db = require('../db')
|
||||||
|
const ensureAdmin = require('./middleware/ensureAdmin')
|
||||||
|
const validate = require('./middleware/validators')
|
||||||
|
|
||||||
|
router.get('/', ensureAdmin, async (req, res) => {
|
||||||
|
const config = await db.config.getLatestConfig()
|
||||||
|
res.json(config)
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/address', ensureAdmin, parseJSON, validate.addressWithPhone, async (req, res) => {
|
||||||
|
const {name, street1, street2, city, state, zip, country, phone} = req.body;
|
||||||
|
|
||||||
|
// Create address, update order
|
||||||
|
const address = await db.address.create(name, street1, street2, city, state, zip, country, phone)
|
||||||
|
const config = await db.config.setShippingAddress(address.uuid, req.user.uuid)
|
||||||
|
|
||||||
|
res.json(config)
|
||||||
|
})
|
@ -0,0 +1,48 @@
|
|||||||
|
import router from 'next/router'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import ActionBar from '~/components/admin/actionBar'
|
||||||
|
import {DateTime} from 'luxon'
|
||||||
|
import Table from '~/components/table'
|
||||||
|
|
||||||
|
|
||||||
|
AdminConfig.getInitialProps = async ({ctx}) => {
|
||||||
|
const {data: config} = await ctx.axios.get('/api/config')
|
||||||
|
return {config}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminConfig({config}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ActionBar title="Config"/>
|
||||||
|
<Table
|
||||||
|
columns={[
|
||||||
|
{name: 'Parameter', extractor: config => config.name},
|
||||||
|
{name: 'Value', extractor: config => config.value},
|
||||||
|
{name: '', extractor: config =>
|
||||||
|
config.href && (
|
||||||
|
<Link href={config.href}><a>Edit</a></Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
rows={[
|
||||||
|
{id: 'tax', name: 'UT Tax Percent', value: parseFloat(config.default_tax_percent) + '%'},
|
||||||
|
{id: 'address', name: 'Shipping Source Address', value: (() => {
|
||||||
|
if(!config.shipping_from)
|
||||||
|
return 'Unset'
|
||||||
|
|
||||||
|
const {name, street1} = config.shipping_from
|
||||||
|
return `${name}, ${street1}`.slice(0, 20) + '...'
|
||||||
|
})(), href: '/admin/config/shipping'},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
{config.modified_by && (
|
||||||
|
<p>
|
||||||
|
Config last modified on
|
||||||
|
{' ' + DateTime.fromISO(config.date_updated).setZone('local').toFormat('LLL dd, yyyy') + ' '}
|
||||||
|
by {config.modified_by.email}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import router from 'next/router'
|
||||||
|
|
||||||
|
import ActionBar from '~/components/admin/actionBar'
|
||||||
|
import {FormController, Input, Button} from '~/components/form'
|
||||||
|
|
||||||
|
ShippingFrom.getInitialProps = async ({ctx: {axios}}) => {
|
||||||
|
const {data: {shipping_from: address}} = await axios.get(`/api/config`)
|
||||||
|
return {address}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ShippingFrom({address}) {
|
||||||
|
const afterSave = () => {
|
||||||
|
router.push(`/admin/config`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ActionBar title="Update Shipping Source Address"/>
|
||||||
|
<FormController url="/api/config/address" afterSubmit={afterSave}>
|
||||||
|
<Input initialValue={address?.name} name="name" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.street1} label="Street (line 1)" name="street1" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.street2} label="Street (line 2)" name="street2"/>
|
||||||
|
<Input initialValue={address?.city} label="City" name="city" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.state} label="State / Province" name="state" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.zip} label="Postal Code" name="zip" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.country} label="Country" name="country" validate={value=>value.length > 0}/>
|
||||||
|
<Input initialValue={address?.phone} label="Phone" name="phone" validate={value=>value.length > 0}/>
|
||||||
|
<Button type="submit">Save Address</Button>
|
||||||
|
</FormController>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue