mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: bugs sprint
This commit is contained in:
@@ -48,7 +48,7 @@ function ExpenseForm({
|
||||
createExpenseMutate,
|
||||
expense,
|
||||
expenseId,
|
||||
submitPayload,
|
||||
submitPayloadRef,
|
||||
} = useExpenseFormContext();
|
||||
|
||||
const isNewMode = !expenseId;
|
||||
@@ -86,9 +86,12 @@ function ExpenseForm({
|
||||
return;
|
||||
}
|
||||
|
||||
// Get submit payload from ref for synchronous access
|
||||
const currentSubmitPayload = submitPayloadRef?.current || {};
|
||||
|
||||
const form = {
|
||||
...transformFormValuesToRequest(values),
|
||||
publish: submitPayload.publish,
|
||||
publish: currentSubmitPayload.publish,
|
||||
};
|
||||
// Handle request success.
|
||||
const handleSuccess = (response) => {
|
||||
@@ -103,10 +106,10 @@ function ExpenseForm({
|
||||
});
|
||||
setSubmitting(false);
|
||||
|
||||
if (submitPayload.redirect) {
|
||||
if (currentSubmitPayload.redirect) {
|
||||
history.push('/expenses');
|
||||
}
|
||||
if (submitPayload.resetForm) {
|
||||
if (currentSubmitPayload.resetForm) {
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,8 +59,13 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
||||
const { mutateAsync: createExpenseMutate } = useCreateExpense();
|
||||
const { mutateAsync: editExpenseMutate } = useEditExpense();
|
||||
|
||||
// Submit form payload.
|
||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||
// Submit form payload - using ref for synchronous access.
|
||||
const submitPayloadRef = React.useRef({});
|
||||
|
||||
// Setter to update the ref.
|
||||
const setSubmitPayload = React.useCallback((payload) => {
|
||||
submitPayloadRef.current = payload;
|
||||
}, []);
|
||||
|
||||
// Detarmines whether the form in new mode.
|
||||
const isNewMode = !expenseId;
|
||||
@@ -69,7 +74,7 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
||||
const provider = {
|
||||
isNewMode,
|
||||
expenseId,
|
||||
submitPayload,
|
||||
submitPayloadRef, // Expose ref for synchronous access
|
||||
|
||||
currencies,
|
||||
customers,
|
||||
|
||||
Reference in New Issue
Block a user