1125 lines
11 KiB
TypeScript
1125 lines
11 KiB
TypeScript
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js'
|
|
import Head from 'next/head'
|
|
import React, { ReactElement, useEffect, useState } from 'react'
|
|
import DatePicker from "react-datepicker";
|
|
import "react-datepicker/dist/react-datepicker.css";
|
|
import dayjs from "dayjs";
|
|
|
|
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 { SelectField } from "../../components/SelectField";
|
|
import { SelectFieldMany } from "../../components/SelectFieldMany";
|
|
import { SwitchField } from '../../components/SwitchField'
|
|
import {RichTextField} from "../../components/RichTextField";
|
|
|
|
import { update, fetch } from '../../stores/recurring_rules/recurring_rulesSlice'
|
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks'
|
|
import { useRouter } from 'next/router'
|
|
import {saveFile} from "../../helpers/fileSaver";
|
|
import dataFormatter from '../../helpers/dataFormatter';
|
|
import ImageField from "../../components/ImageField";
|
|
|
|
|
|
|
|
const EditRecurring_rulesPage = () => {
|
|
const router = useRouter()
|
|
const dispatch = useAppDispatch()
|
|
const initVals = {
|
|
|
|
|
|
'name': '',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
category: null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
budget: null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
owner: null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_active: false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
note: '',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
const [initialValues, setInitialValues] = useState(initVals)
|
|
|
|
const { recurring_rules } = useAppSelector((state) => state.recurring_rules)
|
|
|
|
|
|
const { id } = router.query
|
|
|
|
useEffect(() => {
|
|
dispatch(fetch({ id: id }))
|
|
}, [id])
|
|
|
|
useEffect(() => {
|
|
if (typeof recurring_rules === 'object') {
|
|
setInitialValues(recurring_rules)
|
|
}
|
|
}, [recurring_rules])
|
|
|
|
useEffect(() => {
|
|
if (typeof recurring_rules === 'object') {
|
|
const newInitialVal = {...initVals};
|
|
Object.keys(initVals).forEach(el => newInitialVal[el] = (recurring_rules)[el])
|
|
setInitialValues(newInitialVal);
|
|
}
|
|
}, [recurring_rules])
|
|
|
|
const handleSubmit = async (data) => {
|
|
await dispatch(update({ id: id, data }))
|
|
await router.push('/recurring_rules/recurring_rules-list')
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>{getPageTitle('Edit recurring_rules')}</title>
|
|
</Head>
|
|
<SectionMain>
|
|
<SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit recurring_rules'} main>
|
|
{''}
|
|
</SectionTitleLineWithButton>
|
|
<CardBox>
|
|
<Formik
|
|
enableReinitialize
|
|
initialValues={initialValues}
|
|
onSubmit={(values) => handleSubmit(values)}
|
|
>
|
|
<Form>
|
|
|
|
|
|
|
|
<FormField
|
|
label="Rulename"
|
|
>
|
|
<Field
|
|
name="name"
|
|
placeholder="Rulename"
|
|
/>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label="Flowtype" labelFor="flow_type">
|
|
<Field name="flow_type" id="flow_type" component="select">
|
|
|
|
<option value="expense">expense</option>
|
|
|
|
<option value="income">income</option>
|
|
|
|
</Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
label="Amount"
|
|
>
|
|
<Field
|
|
type="number"
|
|
name="amount"
|
|
placeholder="Amount"
|
|
/>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label="Frequency" labelFor="frequency">
|
|
<Field name="frequency" id="frequency" component="select">
|
|
|
|
<option value="daily">daily</option>
|
|
|
|
<option value="weekly">weekly</option>
|
|
|
|
<option value="monthly">monthly</option>
|
|
|
|
<option value="yearly">yearly</option>
|
|
|
|
</Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
label="Intervalcount"
|
|
>
|
|
<Field
|
|
type="number"
|
|
name="interval_count"
|
|
placeholder="Intervalcount"
|
|
/>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
label="Startat"
|
|
>
|
|
<DatePicker
|
|
dateFormat="yyyy-MM-dd hh:mm"
|
|
showTimeSelect
|
|
selected={initialValues.start_at ?
|
|
new Date(
|
|
dayjs(initialValues.start_at).format('YYYY-MM-DD hh:mm'),
|
|
) : null
|
|
}
|
|
onChange={(date) => setInitialValues({...initialValues, 'start_at': date})}
|
|
/>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
label="Endat"
|
|
>
|
|
<DatePicker
|
|
dateFormat="yyyy-MM-dd hh:mm"
|
|
showTimeSelect
|
|
selected={initialValues.end_at ?
|
|
new Date(
|
|
dayjs(initialValues.end_at).format('YYYY-MM-DD hh:mm'),
|
|
) : null
|
|
}
|
|
onChange={(date) => setInitialValues({...initialValues, 'end_at': date})}
|
|
/>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label="Priority" labelFor="priority">
|
|
<Field name="priority" id="priority" component="select">
|
|
|
|
<option value="low">low</option>
|
|
|
|
<option value="medium">medium</option>
|
|
|
|
<option value="high">high</option>
|
|
|
|
<option value="critical">critical</option>
|
|
|
|
</Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label="Paymentmethod" labelFor="payment_method">
|
|
<Field name="payment_method" id="payment_method" component="select">
|
|
|
|
<option value="cash">cash</option>
|
|
|
|
<option value="card">card</option>
|
|
|
|
<option value="transfer">transfer</option>
|
|
|
|
<option value="mobile_money">mobile_money</option>
|
|
|
|
<option value="other">other</option>
|
|
|
|
</Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label='Category' labelFor='category'>
|
|
<Field
|
|
name='category'
|
|
id='category'
|
|
component={SelectField}
|
|
options={initialValues.category}
|
|
itemRef={'categories'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showField={'name'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
></Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label='Budget' labelFor='budget'>
|
|
<Field
|
|
name='budget'
|
|
id='budget'
|
|
component={SelectField}
|
|
options={initialValues.budget}
|
|
itemRef={'budgets'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showField={'name'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
></Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label='Owner' labelFor='owner'>
|
|
<Field
|
|
name='owner'
|
|
id='owner'
|
|
component={SelectField}
|
|
options={initialValues.owner}
|
|
itemRef={'users'}
|
|
|
|
|
|
showField={'firstName'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
></Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label='Isactive' labelFor='is_active'>
|
|
<Field
|
|
name='is_active'
|
|
id='is_active'
|
|
component={SwitchField}
|
|
></Field>
|
|
</FormField>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<FormField label="Note" hasTextareaHeight>
|
|
<Field name="note" as="textarea" placeholder="Note" />
|
|
</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('/recurring_rules/recurring_rules-list')}/>
|
|
</BaseButtons>
|
|
</Form>
|
|
</Formik>
|
|
</CardBox>
|
|
</SectionMain>
|
|
</>
|
|
)
|
|
}
|
|
|
|
EditRecurring_rulesPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<LayoutAuthenticated
|
|
|
|
permission={'UPDATE_RECURRING_RULES'}
|
|
|
|
>
|
|
{page}
|
|
</LayoutAuthenticated>
|
|
)
|
|
}
|
|
|
|
export default EditRecurring_rulesPage
|