-
-
-
+
);
diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx
index 627ccd7b0..96ac9462e 100644
--- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx
+++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx
@@ -12,13 +12,13 @@ import {
} from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { toSafeInteger } from 'lodash';
-import { FeatureCan, FormattedMessage as T } from '@/components';
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
+import * as R from 'ramda';
+import { FInputGroup, FeatureCan, FormattedMessage as T } from '@/components';
import { useAutofocus } from '@/hooks';
import { CLASSES } from '@/constants/classes';
import {
- compose,
safeSumBy,
momentFormatter,
tansformDateValue,
@@ -48,10 +48,8 @@ import {
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withSettings from '@/containers/Settings/withSettings';
-import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
import {
- useObservePaymentNoSettings,
amountPaymentEntries,
fullAmountPaymentEntries,
customersFieldShouldUpdate,
@@ -59,21 +57,91 @@ import {
} from './utils';
import { Features } from '@/constants';
+/**
+ * Payment receive number field.
+ */
+const PaymentReceivePaymentNoField = R.compose(
+ withSettings(({ paymentReceiveSettings }) => ({
+ paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
+ })),
+ withDialogActions,
+)(
+ ({
+ // #withDialogActions
+ openDialog,
+
+ // #withSettings
+ paymentReceiveAutoIncrement,
+ }) => {
+ const { values, setFieldValue } = useFormikContext();
+
+ // Handle click open payment receive number dialog.
+ const handleClickOpenDialog = () => {
+ openDialog('payment-receive-number-form');
+ };
+ // Handle payment number field blur.
+ const handlePaymentNoBlur = (event) => {
+ const newValue = event.target.value;
+
+ // Show the confirmation dialog if the value has changed and auto-increment
+ // mode is enabled.
+ if (
+ values.payment_receive_no !== newValue &&
+ paymentReceiveAutoIncrement
+ ) {
+ openDialog('payment-receive-number-form', {
+ initialFormValues: {
+ onceManualNumber: newValue,
+ incrementMode: 'manual-transaction',
+ },
+ });
+ }
+ // Setting the payment number to the form will be manually in case
+ // auto-increment is disable.
+ if (!paymentReceiveAutoIncrement) {
+ setFieldValue('payment_receive_no', newValue);
+ setFieldValue('payment_receive_no_manually', newValue);
+ }
+ };
+ return (
+
}
+ inline={true}
+ labelInfo={
}
+ >
+
+ {}}
+ />
+ ,
+ }}
+ tooltip={true}
+ tooltipProps={{
+ content: (
+
+ ),
+ position: Position.BOTTOM_LEFT,
+ }}
+ />
+
+
+ );
+ },
+);
+
/**
* Payment receive header fields.
*/
-function PaymentReceiveHeaderFields({
- // #withCurrentOrganization
- organization: { base_currency },
-
- // #withDialogActions
- openDialog,
-
- // #withSettings
- paymentReceiveAutoIncrement,
- paymentReceiveNumberPrefix,
- paymentReceiveNextNumber,
-}) {
+export default function PaymentReceiveHeaderFields() {
// Payment receive form context.
const { customers, accounts, projects, isNewMode } =
usePaymentReceiveFormContext();
@@ -104,30 +172,6 @@ function PaymentReceiveHeaderFields({
const newEntries = amountPaymentEntries(toSafeInteger(value), entries);
setFieldValue('entries', newEntries);
};
- // Handle click open payment receive number dialog.
- const handleClickOpenDialog = () => {
- openDialog('payment-receive-number-form');
- };
-
- // Handle payment number field blur.
- const handlePaymentNoBlur = (form, field) => (event) => {
- const newValue = event.target.value;
-
- if (field.value !== newValue && paymentReceiveAutoIncrement) {
- openDialog('payment-receive-number-form', {
- initialFormValues: {
- manualTransactionNo: newValue,
- incrementMode: 'manual-transaction',
- },
- });
- }
- };
-
- // Syncs payment receive number from settings to the form.
- useObservePaymentNoSettings(
- paymentReceiveNumberPrefix,
- paymentReceiveNextNumber,
- );
return (
@@ -246,43 +290,7 @@ function PaymentReceiveHeaderFields({
{/* ------------ Payment receive no. ------------ */}
-
- {({ form, field, meta: { error, touched } }) => (
- }
- inline={true}
- labelInfo={}
- className={('form-group--payment_receive_no', CLASSES.FILL)}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
-
- ,
- }}
- tooltip={true}
- tooltipProps={{
- content: (
-
- ),
- position: Position.BOTTOM_LEFT,
- }}
- />
-
-
- )}
-
+
{/* ------------ Deposit account ------------ */}
({
- paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
- paymentReceiveNumberPrefix: paymentReceiveSettings?.numberPrefix,
- paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
- })),
- withDialogActions,
- withCurrentOrganization(),
-)(PaymentReceiveHeaderFields);
-
const CustomerButtonLink = styled(CustomerDrawerLink)`
font-size: 11px;
margin-top: 6px;
diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/components.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/components.tsx
index 30e16af7b..160072afc 100644
--- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/components.tsx
+++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/components.tsx
@@ -1,14 +1,17 @@
// @ts-nocheck
-import React from 'react';
+import React, { useEffect, useLayoutEffect } from 'react';
import moment from 'moment';
import intl from 'react-intl-universal';
import { Button } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
+import * as R from 'ramda';
import { Money, ExchangeRateInputGroup, MoneyFieldCell } from '@/components';
import { useCurrentOrganization } from '@/hooks/state';
import { useEstimateIsForeignCustomer } from './utils';
+import { transactionNumber } from '@/utils';
+import withSettings from '@/containers/Settings/withSettings';
/**
* Invoice date cell.
@@ -109,6 +112,41 @@ export function PaymentReceiveExchangeRateInputField({ ...props }) {
* payment receive project select.
* @returns {JSX.Element}
*/
- export function PaymentReceiveProjectSelectButton({ label }) {
+export function PaymentReceiveProjectSelectButton({ label }) {
return ;
}
+
+/**
+ * Syncs the auto-increment settings to payment receive form.
+ * @returns {React.ReactNode}
+ */
+export const PaymentReceiveSyncIncrementSettingsToForm = R.compose(
+ withSettings(({ paymentReceiveSettings }) => ({
+ paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
+ paymentReceiveNumberPrefix: paymentReceiveSettings?.numberPrefix,
+ paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
+ })),
+)(
+ ({
+ paymentReceiveNextNumber,
+ paymentReceiveNumberPrefix,
+ paymentReceiveAutoIncrement,
+ }) => {
+ const { setFieldValue } = useFormikContext();
+
+ useLayoutEffect(() => {
+ if (!paymentReceiveAutoIncrement) return;
+
+ setFieldValue(
+ 'payment_receive_no',
+ transactionNumber(paymentReceiveNumberPrefix, paymentReceiveNextNumber),
+ );
+ }, [
+ setFieldValue,
+ paymentReceiveNumberPrefix,
+ paymentReceiveNextNumber,
+ paymentReceiveAutoIncrement,
+ ]);
+ return null;
+ },
+);
diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx
index f4490490a..ec33a1b64 100644
--- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx
+++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx
@@ -17,7 +17,6 @@ import {
} from '@/utils';
import { useCurrentOrganization } from '@/hooks/state';
-
// Default payment receive entry.
export const defaultPaymentReceiveEntry = {
index: '',
@@ -37,8 +36,10 @@ export const defaultPaymentReceive = {
payment_date: moment(new Date()).format('YYYY-MM-DD'),
reference_no: '',
payment_receive_no: '',
+ // Holds the payment number that entered manually only.
+ payment_receive_no_manually: '',
statement: '',
- full_amount: '',
+ full_amount: '',
currency_code: '',
branch_id: '',
exchange_rate: 1,
@@ -123,18 +124,6 @@ export const fullAmountPaymentEntries = (entries) => {
}));
};
-/**
- * Syncs payment receive number settings with form.
- */
-export const useObservePaymentNoSettings = (prefix, nextNumber) => {
- const { setFieldValue } = useFormikContext();
-
- React.useEffect(() => {
- const invoiceNo = transactionNumber(prefix, nextNumber);
- setFieldValue('payment_receive_no', invoiceNo);
- }, [setFieldValue, prefix, nextNumber]);
-};
-
/**
* Detarmines the customers fast-field should update.
*/
@@ -168,6 +157,8 @@ export const transformFormToRequest = (form) => {
return {
...omit(form, ['payment_receive_no_manually', 'payment_receive_no']),
+ // The `payment_receive_no_manually` will be presented just if the auto-increment
+ // is disable, always both attributes hold the same value in manual mode.
...(form.payment_receive_no_manually && {
payment_receive_no: form.payment_receive_no,
}),
@@ -264,3 +255,13 @@ export const useEstimateIsForeignCustomer = () => {
);
return isForeignCustomer;
};
+
+export const resetFormState = ({ initialValues, values, resetForm }) => {
+ resetForm({
+ values: {
+ // Reset the all values except the brand id.
+ ...initialValues,
+ brand_id: values.brand_id,
+ },
+ });
+};
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx
index fba767919..75a8b9665 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx
@@ -33,7 +33,9 @@ import {
defaultReceipt,
handleErrors,
transformFormValuesToRequest,
+ resetFormState,
} from './utils';
+import { ReceiptSyncIncrementSettingsToForm } from './components';
/**
* Receipt form.
@@ -121,7 +123,7 @@ function ReceiptForm({
history.push('/receipts');
}
if (submitPayload.resetForm) {
- resetForm();
+ resetFormState();
}
};
@@ -165,7 +167,11 @@ function ReceiptForm({
+ {/*---------- Dialogs ---------*/}
+
+ {/*---------- Effects ---------*/}
+
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormDialogs.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormDialogs.tsx
index d378f878d..4fe2cb947 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormDialogs.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormDialogs.tsx
@@ -10,9 +10,15 @@ export default function ReceiptFormDialogs() {
const { setFieldValue } = useFormikContext();
// Update the form once the receipt number form submit confirm.
- const handleReceiptNumberFormConfirm = ({ incrementNumber, manually }) => {
- setFieldValue('receipt_number', incrementNumber || '');
- setFieldValue('receipt_number_manually', manually);
+ const handleReceiptNumberFormConfirm = (settings) => {
+ // Set the receipt transaction no. that cames from dialog to the form.
+ // the `receipt_no_manually` will be empty except the increment mode is not auto.
+ setFieldValue('receipt_number', settings.transactionNumber);
+ setFieldValue('receipt_number_manually', '');
+
+ if (settings.incrementMode !== 'auto') {
+ setFieldValue('receipt_number_manually', settings.transactionNumber);
+ }
};
return (
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeader.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeader.tsx
index 8c5174c62..833c5b45b 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeader.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeader.tsx
@@ -17,6 +17,21 @@ function ReceiptFormHeader({
// #ownProps
onReceiptNumberChanged,
}) {
+ return (
+
+
+
+
+ );
+}
+
+/**
+ * The big total amount of receipt form.
+ * @returns {React.ReactNode}
+ */
+function ReceiptFormHeaderBigTotal() {
const {
values: { currency_code, entries },
} = useFormikContext();
@@ -25,16 +40,11 @@ function ReceiptFormHeader({
const totalDueAmount = useMemo(() => getEntriesTotal(entries), [entries]);
return (
-
+
);
}
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeaderFields.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeaderFields.tsx
index cd0179247..ff62e984a 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeaderFields.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptFormHeaderFields.tsx
@@ -10,9 +10,12 @@ import {
ControlGroup,
} from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
-import { FastField, ErrorMessage } from 'formik';
-import { CLASSES } from '@/constants/classes';
+import { FastField, ErrorMessage, useFormikContext } from 'formik';
+import * as R from 'ramda';
+import { CLASSES } from '@/constants/classes';
+import { ACCOUNT_TYPE } from '@/constants/accountTypes';
+import { Features } from '@/constants';
import {
FFormGroup,
AccountsSelect,
@@ -23,64 +26,112 @@ import {
CustomerDrawerLink,
FormattedMessage as T,
FeatureCan,
+ FInputGroup,
} from '@/components';
-import withSettings from '@/containers/Settings/withSettings';
-import withDialogActions from '@/containers/Dialog/withDialogActions';
-import { ACCOUNT_TYPE } from '@/constants/accountTypes';
import { ProjectsSelect } from '@/containers/Projects/components';
import {
momentFormatter,
- compose,
tansformDateValue,
handleDateChange,
inputIntent,
} from '@/utils';
import { useReceiptFormContext } from './ReceiptFormProvider';
-import {
- accountsFieldShouldUpdate,
- customersFieldShouldUpdate,
- useObserveReceiptNoSettings,
-} from './utils';
+import { accountsFieldShouldUpdate, customersFieldShouldUpdate } from './utils';
import {
ReceiptExchangeRateInputField,
ReceiptProjectSelectButton,
} from './components';
-import { Features } from '@/constants';
+
+import withSettings from '@/containers/Settings/withSettings';
+import withDialogActions from '@/containers/Dialog/withDialogActions';
+
+/**
+ * Receipt number field of receipt form.
+ */
+const ReceiptFormReceiptNumberField = R.compose(
+ withDialogActions,
+ withSettings(({ receiptSettings }) => ({
+ receiptAutoIncrement: receiptSettings?.autoIncrement,
+ })),
+)(
+ ({
+ // #withDialogActions
+ openDialog,
+
+ // #withSettings
+ receiptAutoIncrement,
+ }) => {
+ const { values, setFieldValue } = useFormikContext();
+
+ const handleReceiptNumberChange = () => {
+ openDialog('receipt-number-form', {});
+ };
+
+ const handleReceiptNoBlur = (event) => {
+ const newValue = event.target.value;
+
+ // Show the confirmation dialog if the value has changed and auto-increment
+ // mode is enabled.
+ if (values.receipt_number !== newValue && receiptAutoIncrement) {
+ openDialog('receipt-number-form', {
+ initialFormValues: {
+ onceManualNumber: newValue,
+ incrementMode: 'manual-transaction',
+ },
+ });
+ }
+ // Setting the receipt number to the form will be manually in case
+ // auto-increment is disable.
+ if (!receiptAutoIncrement) {
+ setFieldValue('receipt_number', newValue);
+ setFieldValue('receipt_number_manually', newValue);
+ }
+ };
+
+ return (
+
}
+ inline={true}
+ labelInfo={
}
+ >
+
+ {}}
+ />
+ ,
+ }}
+ tooltip={true}
+ tooltipProps={{
+ content: (
+
+ ),
+ position: Position.BOTTOM_LEFT,
+ }}
+ inputProps={{
+ leftIcon: ,
+ }}
+ />
+
+
+ );
+ },
+);
/**
* Receipt form header fields.
*/
-function ReceiptFormHeader({
- //#withDialogActions
- openDialog,
-
- // #withSettings
- receiptAutoIncrement,
- receiptNextNumber,
- receiptNumberPrefix,
-}) {
+export default function ReceiptFormHeader() {
const { accounts, customers, projects } = useReceiptFormContext();
- const handleReceiptNumberChange = useCallback(() => {
- openDialog('receipt-number-form', {});
- }, [openDialog]);
-
- const handleReceiptNoBlur = (form, field) => (event) => {
- const newValue = event.target.value;
-
- if (field.value !== newValue && receiptAutoIncrement) {
- openDialog('receipt-number-form', {
- initialFormValues: {
- manualTransactionNo: newValue,
- incrementMode: 'manual-transaction',
- },
- });
- }
- };
-
- // Synsc receipt number settings with the form.
- useObserveReceiptNoSettings(receiptNumberPrefix, receiptNextNumber);
-
return (
{/* ----------- Customer name ----------- */}
@@ -176,45 +227,7 @@ function ReceiptFormHeader({
{/* ----------- Receipt number ----------- */}
-
- {({ form, field, meta: { error, touched } }) => (
- }
- inline={true}
- className={('form-group--receipt_number', CLASSES.FILL)}
- labelInfo={}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
-
- ,
- }}
- tooltip={true}
- tooltipProps={{
- content: (
-
- ),
- position: Position.BOTTOM_LEFT,
- }}
- inputProps={{
- leftIcon: ,
- }}
- />
-
-
- )}
-
+
{/* ----------- Reference ----------- */}
@@ -251,15 +264,6 @@ function ReceiptFormHeader({
);
}
-export default compose(
- withDialogActions,
- withSettings(({ receiptSettings }) => ({
- receiptAutoIncrement: receiptSettings?.autoIncrement,
- receiptNextNumber: receiptSettings?.nextNumber,
- receiptNumberPrefix: receiptSettings?.numberPrefix,
- })),
-)(ReceiptFormHeader);
-
const CustomerButtonLink = styled(CustomerDrawerLink)`
font-size: 11px;
margin-top: 6px;
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/components.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/components.tsx
index 417daea29..937a4f937 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/components.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/components.tsx
@@ -3,9 +3,14 @@ import React from 'react';
import intl from 'react-intl-universal';
import { Button } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
+import * as R from 'ramda';
+
import { ExchangeRateInputGroup } from '@/components';
import { useCurrentOrganization } from '@/hooks/state';
import { useReceiptIsForeignCustomer } from './utils';
+import { useUpdateEffect } from '@/hooks';
+import withSettings from '@/containers/Settings/withSettings';
+import { transactionNumber } from '@/utils';
/**
* Receipt exchange rate input field.
@@ -37,3 +42,34 @@ export function ReceiptExchangeRateInputField({ ...props }) {
export function ReceiptProjectSelectButton({ label }) {
return ;
}
+
+/**
+ * Syncs receipt auto-increment settings to form.
+ * @return {React.ReactNode}
+ */
+export const ReceiptSyncIncrementSettingsToForm = R.compose(
+ withSettings(({ receiptSettings }) => ({
+ receiptAutoIncrement: receiptSettings?.autoIncrement,
+ receiptNextNumber: receiptSettings?.nextNumber,
+ receiptNumberPrefix: receiptSettings?.numberPrefix,
+ })),
+)(({ receiptAutoIncrement, receiptNextNumber, receiptNumberPrefix }) => {
+ const { setFieldValue } = useFormikContext();
+
+ useUpdateEffect(() => {
+ // Do not update if the receipt auto-increment mode is disabled.
+ if (!receiptAutoIncrement) return;
+
+ setFieldValue(
+ 'receipt_number',
+ transactionNumber(receiptNumberPrefix, receiptNextNumber),
+ );
+ }, [
+ setFieldValue,
+ receiptNumberPrefix,
+ receiptAutoIncrement,
+ receiptNextNumber,
+ ]);
+
+ return null;
+});
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx
index ba339a457..4dcaec4b2 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx
@@ -36,6 +36,8 @@ export const defaultReceipt = {
customer_id: '',
deposit_account_id: '',
receipt_number: '',
+ // Holds the receipt number that entered manually only.
+ receipt_number_manually: '',
receipt_date: moment(new Date()).format('YYYY-MM-DD'),
reference_no: '',
receipt_message: '',
@@ -77,15 +79,6 @@ export const transformToEditForm = (receipt) => {
};
};
-export const useObserveReceiptNoSettings = (prefix, nextNumber) => {
- const { setFieldValue } = useFormikContext();
-
- React.useEffect(() => {
- const receiptNo = transactionNumber(prefix, nextNumber);
- setFieldValue('receipt_number', receiptNo);
- }, [setFieldValue, prefix, nextNumber]);
-};
-
/**
* Detarmines entries fast field should update.
*/
@@ -248,3 +241,14 @@ export const useReceiptIsForeignCustomer = () => {
);
return isForeignCustomer;
};
+
+export const resetFormState = ({ initialValues, values, resetForm }) => {
+ resetForm({
+ values: {
+ // Reset the all values except the warehouse and brand id.
+ ...initialValues,
+ warehouse_id: values.warehouse_id,
+ brand_id: values.brand_id,
+ },
+ });
+};
diff --git a/packages/webapp/src/hooks/query/manualJournals.tsx b/packages/webapp/src/hooks/query/manualJournals.tsx
index b5f7d418b..7af2c84a5 100644
--- a/packages/webapp/src/hooks/query/manualJournals.tsx
+++ b/packages/webapp/src/hooks/query/manualJournals.tsx
@@ -21,6 +21,9 @@ const commonInvalidateQueries = (client) => {
client.invalidateQueries(t.ACCOUNTS);
client.invalidateQueries(t.ACCOUNT);
+ // Invalidate settings.
+ client.invalidateQueries([t.SETTING, t.SETTING_MANUAL_JOURNALS]);
+
// Invalidate financial reports.
client.invalidateQueries(t.FINANCIAL_REPORT);
diff --git a/packages/webapp/src/hooks/query/settings.tsx b/packages/webapp/src/hooks/query/settings.tsx
index 2a2029214..ae1308ffe 100644
--- a/packages/webapp/src/hooks/query/settings.tsx
+++ b/packages/webapp/src/hooks/query/settings.tsx
@@ -4,6 +4,7 @@ import { useRequestQuery } from '../useQueryRequest';
import useApiRequest from '../useRequest';
import { useSetSettings } from '@/hooks/state';
import t from './types';
+import { useEffect } from 'react';
/**
* Saves the settings.
@@ -23,18 +24,23 @@ export function useSaveSettings(props) {
function useSettingsQuery(key, query, props) {
const setSettings = useSetSettings();
- return useRequestQuery(
+ const settingsQuery = useRequestQuery(
key,
{ method: 'get', url: 'settings', params: query },
{
select: (res) => res.data.settings,
defaultData: [],
- onSuccess: (settings) => {
- setSettings(settings);
- },
...props,
},
);
+ useEffect(() => {
+ // Sync to Redux state if the reqeust success and is not fetching.
+ if (!settingsQuery.isFetching && settingsQuery.isSuccess) {
+ setSettings(settingsQuery.data);
+ }
+ }, [settingsQuery.isFetching, settingsQuery.isSuccess, settingsQuery.data]);
+
+ return settingsQuery;
}
/**
diff --git a/packages/webapp/src/lang/en/index.json b/packages/webapp/src/lang/en/index.json
index 6b93f700e..d9b5f02a8 100644
--- a/packages/webapp/src/lang/en/index.json
+++ b/packages/webapp/src/lang/en/index.json
@@ -1376,7 +1376,7 @@
"receipt.auto_increment.manually": "Your receipt numbers are set on manual mode. Are you sure chaning this settings?",
"payment_receive.auto_increment.auto": "Your payment numbers are set on auto-increment mode. Are you sure changing this setting?",
"payment_receive.auto_increment.manually": "Your payment numbers are set on manual mode. Are you sure chaning this settings?",
- "auto_increment.field.manually": "I will enter them manually each time",
+ "auto_increment.field.manually": "I will enter them manually each time.",
"auto_increment.field.manual_this_transaction": "Manual entering for this transaction.",
"auto_increment.field.auto": "Auto-incrementing number.",
"date_formats": {