mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: autofill the quick created customer/vendor
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { createNewItemFromQuery, createNewItemRenderer } from './utils';
|
||||
import { FSelect } from '../Forms';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
import { useCreateAutofillListener } from '@/hooks/state/autofill';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
/**
|
||||
@@ -17,6 +19,7 @@ function CustomerSelectRoot({
|
||||
// #ownProps
|
||||
items,
|
||||
allowCreate,
|
||||
name,
|
||||
...props
|
||||
}) {
|
||||
// Maybe inject create new item props to suggest component.
|
||||
@@ -24,14 +27,21 @@ function CustomerSelectRoot({
|
||||
const maybeCreateNewItemFromQuery = allowCreate
|
||||
? createNewItemFromQuery
|
||||
: null;
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Creates autofill listener once the quick customer drawer submit the form.
|
||||
const autofillRef = useCreateAutofillListener((payload: any) => {
|
||||
setFieldValue(name, payload.customerId);
|
||||
});
|
||||
// Handles the create item click.
|
||||
const handleCreateItemClick = () => {
|
||||
openDrawer(DRAWERS.QUICK_CREATE_CUSTOMER);
|
||||
const handleCreateItemClick = (item) => {
|
||||
const displayName = item.name;
|
||||
openDrawer(DRAWERS.QUICK_CREATE_CUSTOMER, { autofillRef, displayName });
|
||||
};
|
||||
|
||||
return (
|
||||
<FSelect
|
||||
name={name}
|
||||
items={items}
|
||||
textAccessor={'display_name'}
|
||||
labelAccessor={'formatted_balance'}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
import { useFormikContext } from 'formik';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
import { createNewItemFromQuery, createNewItemRenderer } from './utils';
|
||||
import { FSelect } from '../Forms';
|
||||
import { useCreateAutofillListener } from '@/hooks/state/autofill';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
/**
|
||||
@@ -15,6 +17,7 @@ function VendorsSelectRoot({
|
||||
openDrawer,
|
||||
|
||||
// #ownProps
|
||||
name,
|
||||
items,
|
||||
allowCreate,
|
||||
|
||||
@@ -25,14 +28,24 @@ function VendorsSelectRoot({
|
||||
const maybeCreateNewItemFromQuery = allowCreate
|
||||
? createNewItemFromQuery
|
||||
: null;
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Creates a new autofill listener once the quick vendor drawer submits the form.
|
||||
const autofillRef = useCreateAutofillListener((payload: any) => {
|
||||
setFieldValue(name, payload.vendorId);
|
||||
});
|
||||
|
||||
// Handles the create item click.
|
||||
const handleCreateItemClick = () => {
|
||||
openDrawer(DRAWERS.QUICK_WRITE_VENDOR);
|
||||
const handleCreateItemClick = (item) => {
|
||||
openDrawer(DRAWERS.QUICK_WRITE_VENDOR, {
|
||||
autofillRef,
|
||||
displayName: item.name,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<FSelect
|
||||
name={name}
|
||||
items={items}
|
||||
textAccessor={'display_name'}
|
||||
labelAccessor={'formatted_balance'}
|
||||
|
||||
Reference in New Issue
Block a user