fix: autofill the quick created customer/vendor

This commit is contained in:
Ahmed Bouhuolia
2024-08-13 23:55:53 +02:00
parent ec2b7e332e
commit d2193fdac0
14 changed files with 212 additions and 35 deletions

View File

@@ -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'}

View File

@@ -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'}