diff --git a/components/form/checkbox.js b/components/form/checkbox.js index 9395b75..b3b718c 100644 --- a/components/form/checkbox.js +++ b/components/form/checkbox.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, {useEffect} from 'react' import styles from './styles.module.css' @@ -7,6 +7,11 @@ export default function Checkbox({label, error, hint, name, value, onChange, onB onChange({target: {value: !value}}) } + useEffect(()=>{ + if(value === "") + onChange({target: {value: false}}) + }, []) + return (
diff --git a/components/form/decimalInput.js b/components/form/decimalInput.js index 12e4b4b..16fffb4 100644 --- a/components/form/decimalInput.js +++ b/components/form/decimalInput.js @@ -86,7 +86,7 @@ export default function Input({label, prefix, numDecimals, error, hint, name, va {remainingText}
- {hint && {error || (isValid ? '' : hint)}} + {(hint || error) && {error || (isValid ? '' : hint)}} ) } diff --git a/components/form/input.js b/components/form/input.js index 325ebd8..f436034 100644 --- a/components/form/input.js +++ b/components/form/input.js @@ -2,14 +2,14 @@ import React from 'react' import styles from './styles.module.css' -export default function Input({_label, error, hint, type, name, value, onChange, onBlur, isValid}){ +export default function Input({label: _label, error, hint, type, name, value, onChange, onBlur, isValid}){ const label = _label || name.replace(name[0], name[0].toUpperCase()) return (
- {hint && {error || (isValid ? '' : hint)}} + {(hint || error) && {error || (isValid ? '' : hint)}}
) } diff --git a/pages/admin/items/index.js b/pages/admin/items/index.js index 6f6a9f8..341bd8f 100644 --- a/pages/admin/items/index.js +++ b/pages/admin/items/index.js @@ -31,6 +31,7 @@ export default function Items({items: _items}){ return ( <>

Items

+ Create New Item item.name}, diff --git a/pages/admin/items/new.js b/pages/admin/items/new.js new file mode 100644 index 0000000..d7f0f0f --- /dev/null +++ b/pages/admin/items/new.js @@ -0,0 +1,32 @@ +import React from 'react' +import router from 'next/router' +import {FormController, Input, DecimalInput, Button, Checkbox} from '~/components/form' + +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 ( + <> +

Create New Item

+ + + + + Math.floor(float * 100)} /> + +

Note: You can add images to an item after creating it

+ +
+ + ) +}