You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.9 KiB
JavaScript

5 years ago
import React from 'react'
import router from 'next/router'
5 years ago
import ActionBar from '~/components/admin/actionBar'
import {FormController, Input, TextArea, DecimalInput, Button, Checkbox} from '~/components/form'
5 years ago
export default function NewItem() {
const stringLengthAtLeastOne = str => str.length > 0
const slugRestrictions = str => {
if(str.length < 3) return false;
if(str.length > 20) return false;
if(!str.match(/^[-a-z0-9_]*$/i)) return false;
return true;
}
const afterCreate = (item) => {
router.push(`/admin/items/${item.urlslug}`)
}
return (
<>
5 years ago
<ActionBar title="Create New Item"/>
5 years ago
<FormController url="/api/items" afterSubmit={afterCreate}>
<h3>General Fields</h3>
5 years ago
<Input name="name" validate={stringLengthAtLeastOne} />
<TextArea name="description" validate={stringLengthAtLeastOne} />
5 years ago
<Input label="URL Slug" name="urlslug" validate={slugRestrictions} />
<DecimalInput label="Price" name="price_cents" prefix="$" numDecimals={2} transform={float => Math.floor(float * 100)} />
<Checkbox label="Published" name="published" hint="Publish this item" />
<h3>Customs Info</h3>
<Input name="hs_tariff_number" label="Tariff Number" validate={stringLengthAtLeastOne} hint="Please see https://hts.usitc.gov/current. Sock is 611595"/>
<Input name="customs_description" label="Customs Description" validate={stringLengthAtLeastOne} hint={"Short description like \"t-shirt\""}/>
<Input name="origin_country" label="Country of Origin" validate={s => s.length === 2} hint="2 letter ISO country code"/>
<DecimalInput label="Weight (ounces)" name="weight" hint="Please enter (in ounces) the weight of this item" prefix="" numDecimals={2} validate={val => val > 0} />
5 years ago
<p><strong>Note:</strong> You can add images to an item after creating it</p>
<Button type="submit">Create</Button>
</FormController>
</>
)
}