243 lines
6.9 KiB
TypeScript
243 lines
6.9 KiB
TypeScript
import {
|
|
mdiAccount,
|
|
mdiChartTimelineVariant,
|
|
mdiMail,
|
|
mdiUpload,
|
|
} from '@mdi/js';
|
|
import Head from 'next/head';
|
|
import React, { ReactElement } from 'react';
|
|
import CardBox from '../../components/CardBox';
|
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
import SectionMain from '../../components/SectionMain';
|
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
import { getPageTitle } from '../../config';
|
|
|
|
import { Field, Form, Formik } from 'formik';
|
|
import FormField from '../../components/FormField';
|
|
import BaseDivider from '../../components/BaseDivider';
|
|
import BaseButtons from '../../components/BaseButtons';
|
|
import BaseButton from '../../components/BaseButton';
|
|
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
import FormFilePicker from '../../components/FormFilePicker';
|
|
import FormImagePicker from '../../components/FormImagePicker';
|
|
import { SwitchField } from '../../components/SwitchField';
|
|
|
|
import { SelectField } from '../../components/SelectField';
|
|
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
import { RichTextField } from '../../components/RichTextField';
|
|
|
|
import { create } from '../../stores/bottles/bottlesSlice';
|
|
import { useAppDispatch } from '../../stores/hooks';
|
|
import { useRouter } from 'next/router';
|
|
import moment from 'moment';
|
|
|
|
const initialValues = {
|
|
name: '',
|
|
|
|
brand: '',
|
|
|
|
proof: '',
|
|
|
|
type: 'Bourbon',
|
|
|
|
notes: '',
|
|
|
|
tasting_notes: '',
|
|
|
|
msrp_range: '',
|
|
|
|
secondary_value_range: '',
|
|
|
|
opened_bottle_indicator: false,
|
|
|
|
quantity: '',
|
|
|
|
barcode: '',
|
|
|
|
picture: [],
|
|
|
|
age: '',
|
|
|
|
distillery: '',
|
|
|
|
user: '',
|
|
};
|
|
|
|
const BottlesNew = () => {
|
|
const router = useRouter();
|
|
const dispatch = useAppDispatch();
|
|
|
|
const handleSubmit = async (data) => {
|
|
await dispatch(create(data));
|
|
await router.push('/bottles/bottles-list');
|
|
};
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>{getPageTitle('New Item')}</title>
|
|
</Head>
|
|
<SectionMain>
|
|
<SectionTitleLineWithButton
|
|
icon={mdiChartTimelineVariant}
|
|
title='New Item'
|
|
main
|
|
>
|
|
{''}
|
|
</SectionTitleLineWithButton>
|
|
<CardBox>
|
|
<Formik
|
|
initialValues={initialValues}
|
|
onSubmit={(values) => handleSubmit(values)}
|
|
>
|
|
<Form>
|
|
<FormField label='Name'>
|
|
<Field name='name' placeholder='Name' />
|
|
</FormField>
|
|
|
|
<FormField label='Brand' labelFor='brand'>
|
|
<Field
|
|
name='brand'
|
|
id='brand'
|
|
component={SelectField}
|
|
options={[]}
|
|
itemRef={'brands'}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='Proof'>
|
|
<Field type='number' name='proof' placeholder='Proof' />
|
|
</FormField>
|
|
|
|
<FormField label='Type' labelFor='type'>
|
|
<Field name='type' id='type' component='select'>
|
|
<option value='Bourbon'>Bourbon</option>
|
|
|
|
<option value='Scotch'>Scotch</option>
|
|
|
|
<option value='Rye'>Rye</option>
|
|
|
|
<option value='Irish'>Irish</option>
|
|
|
|
<option value='Other'>Other</option>
|
|
</Field>
|
|
</FormField>
|
|
|
|
<FormField label='Notes' hasTextareaHeight>
|
|
<Field
|
|
name='notes'
|
|
id='notes'
|
|
component={RichTextField}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='TastingNotes' hasTextareaHeight>
|
|
<Field
|
|
name='tasting_notes'
|
|
id='tasting_notes'
|
|
component={RichTextField}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='MSRPRange'>
|
|
<Field name='msrp_range' placeholder='MSRPRange' />
|
|
</FormField>
|
|
|
|
<FormField label='SecondaryValueRange'>
|
|
<Field
|
|
name='secondary_value_range'
|
|
placeholder='SecondaryValueRange'
|
|
/>
|
|
</FormField>
|
|
|
|
<FormField
|
|
label='OpenedBottleIndicator'
|
|
labelFor='opened_bottle_indicator'
|
|
>
|
|
<Field
|
|
name='opened_bottle_indicator'
|
|
id='opened_bottle_indicator'
|
|
component={SwitchField}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='Quantity'>
|
|
<Field type='number' name='quantity' placeholder='Quantity' />
|
|
</FormField>
|
|
|
|
<FormField label='Barcode'>
|
|
<Field name='barcode' placeholder='Barcode' />
|
|
</FormField>
|
|
|
|
<FormField>
|
|
<Field
|
|
label='Picture'
|
|
color='info'
|
|
icon={mdiUpload}
|
|
path={'bottles/picture'}
|
|
name='picture'
|
|
id='picture'
|
|
accept='image/*'
|
|
capture
|
|
schema={{
|
|
size: undefined,
|
|
formats: undefined,
|
|
}}
|
|
component={FormImagePicker}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='Age'>
|
|
<Field type='number' name='age' placeholder='Age' />
|
|
</FormField>
|
|
|
|
<FormField label='Distillery' labelFor='distillery'>
|
|
<Field
|
|
name='distillery'
|
|
id='distillery'
|
|
component={SelectField}
|
|
options={[]}
|
|
itemRef={'distilleries'}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<FormField label='User' labelFor='user'>
|
|
<Field
|
|
name='user'
|
|
id='user'
|
|
component={SelectField}
|
|
options={[]}
|
|
itemRef={'users'}
|
|
></Field>
|
|
</FormField>
|
|
|
|
<BaseDivider />
|
|
<BaseButtons>
|
|
<BaseButton type='submit' color='info' label='Submit' />
|
|
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
<BaseButton
|
|
type='reset'
|
|
color='danger'
|
|
outline
|
|
label='Cancel'
|
|
onClick={() => router.push('/bottles/bottles-list')}
|
|
/>
|
|
</BaseButtons>
|
|
</Form>
|
|
</Formik>
|
|
</CardBox>
|
|
</SectionMain>
|
|
</>
|
|
);
|
|
};
|
|
|
|
BottlesNew.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<LayoutAuthenticated permission={'CREATE_BOTTLES'}>
|
|
{page}
|
|
</LayoutAuthenticated>
|
|
);
|
|
};
|
|
|
|
export default BottlesNew;
|