-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2860 from LiteFarmOrg/LF-3592/Create_custom_reven…
…ue_type_form_container_and_frontend_route LF-3592: Create custom revenue type form container and frontend route
- Loading branch information
Showing
18 changed files
with
381 additions
and
62 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/api/db/migration/20230913181516_add_columns_to_sale.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const up = async function (knex) { | ||
await knex.schema.alterTable('sale', (table) => { | ||
table.float('value'); | ||
table.string('note'); | ||
}); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const down = async function (knex) { | ||
await knex.schema.alterTable('sale', (table) => { | ||
table.dropColumn('value'); | ||
table.dropColumn('note'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
packages/webapp/src/components/Forms/GeneralRevenue/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
import React from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Form from '../../Form'; | ||
import Button from '../../Form/Button'; | ||
import Input, { getInputErrors } from '../../Form/Input'; | ||
import InputAutoSize from '../../Form/InputAutoSize'; | ||
import PageTitle from '../../PageTitle/v2'; | ||
import { getLocalDateInYYYYDDMM } from '../../../util/date'; | ||
import { hookFormMaxCharsValidation } from '../../Form/hookformValidationUtils'; | ||
|
||
const SALE_DATE = 'sale_date'; | ||
const SALE_CUSTOMER = 'customer_name'; | ||
const VALUE = `value`; | ||
const NOTE = `note`; | ||
|
||
const GeneralRevenue = ({ | ||
onSubmit, | ||
title, | ||
dateLabel, | ||
customerLabel, | ||
currency, | ||
sale, | ||
useHookFormPersist, | ||
persistedFormData, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
getValues, | ||
} = useForm({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
[SALE_DATE]: | ||
(sale?.[SALE_DATE] && getLocalDateInYYYYDDMM(sale.SALE_DATE)) || | ||
persistedFormData?.[SALE_DATE] || | ||
getLocalDateInYYYYDDMM(), | ||
[SALE_CUSTOMER]: sale?.[SALE_CUSTOMER] || persistedFormData?.[SALE_CUSTOMER] || '', | ||
[VALUE]: sale?.[VALUE] || null, | ||
[NOTE]: sale?.[NOTE] || '', | ||
}, | ||
}); | ||
|
||
useHookFormPersist(getValues); | ||
|
||
return ( | ||
<Form | ||
onSubmit={handleSubmit(onSubmit)} | ||
buttonGroup={ | ||
<Button disabled={!isValid} fullLength type={'submit'}> | ||
{t('common:SAVE')} | ||
</Button> | ||
} | ||
> | ||
<PageTitle title={title} onGoBack={() => history.back()} style={{ marginBottom: '24px' }} /> | ||
<Input | ||
label={customerLabel} | ||
hookFormRegister={register(SALE_CUSTOMER, { required: true })} | ||
style={{ marginBottom: '40px' }} | ||
errors={getInputErrors(errors, SALE_CUSTOMER)} | ||
type={'text'} | ||
/> | ||
<Input | ||
label={dateLabel} | ||
hookFormRegister={register(SALE_DATE, { required: true })} | ||
style={{ marginBottom: '40px' }} | ||
type={'date'} | ||
errors={getInputErrors(errors, SALE_DATE)} | ||
/> | ||
<Input | ||
label={t('SALE.DETAIL.VALUE')} | ||
type="number" | ||
hookFormRegister={register(VALUE, { required: true, valueAsNumber: true })} | ||
currency={currency} | ||
style={{ marginBottom: '40px' }} | ||
errors={getInputErrors(errors, VALUE)} | ||
/> | ||
<InputAutoSize | ||
style={{ marginBottom: '40px' }} | ||
label={t('LOG_COMMON.NOTES')} | ||
optional={true} | ||
hookFormRegister={register(NOTE, { maxLength: hookFormMaxCharsValidation(10000) })} | ||
name={NOTE} | ||
errors={getInputErrors(errors, NOTE)} | ||
/> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default GeneralRevenue; |
Oops, something went wrong.